| 22 | |
| 23 | # Sample implementations of the encryption-related interfaces. |
| 24 | class KeyWrapper: |
| 25 | def __init__(self, kid): |
| 26 | self.kek = urandom(32) |
| 27 | self.backend = default_backend() |
| 28 | self.kid = 'local:' + kid |
| 29 | |
| 30 | def wrap_key(self, key, algorithm='A256KW'): |
| 31 | if algorithm == 'A256KW': |
| 32 | return aes_key_wrap(self.kek, key, self.backend) |
| 33 | else: |
| 34 | raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) |
| 35 | |
| 36 | def unwrap_key(self, key, algorithm): |
| 37 | if algorithm == 'A256KW': |
| 38 | return aes_key_unwrap(self.kek, key, self.backend) |
| 39 | else: |
| 40 | raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) |
| 41 | |
| 42 | def get_key_wrap_algorithm(self): |
| 43 | return 'A256KW' |
| 44 | |
| 45 | def get_kid(self): |
| 46 | return self.kid |
| 47 | |
| 48 | |
| 49 | class KeyResolver: |
no outgoing calls
no test coverage detected