| 17 | |
| 18 | |
| 19 | class KeyWrapper: |
| 20 | def __init__(self, kid='local:key1'): |
| 21 | # Must have constant key value for recorded tests, otherwise we could use a random generator. |
| 22 | self.kek = b'\xbe\xa4\x11K\x9eJ\x07\xdafF\x83\xad+\xadvA C\xe8\xbc\x90\xa4\x11}G\xc3\x0f\xd4\xb4\x19m\x11' |
| 23 | self.backend = default_backend() |
| 24 | self.kid = kid |
| 25 | |
| 26 | def wrap_key(self, key, algorithm='A256KW'): |
| 27 | if algorithm == 'A256KW': |
| 28 | return aes_key_wrap(self.kek, key, self.backend) |
| 29 | else: |
| 30 | raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) |
| 31 | |
| 32 | def unwrap_key(self, key, algorithm): |
| 33 | if algorithm == 'A256KW': |
| 34 | return aes_key_unwrap(self.kek, key, self.backend) |
| 35 | else: |
| 36 | raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) |
| 37 | |
| 38 | def get_key_wrap_algorithm(self): |
| 39 | return 'A256KW' |
| 40 | |
| 41 | def get_kid(self): |
| 42 | return self.kid |
| 43 | |
| 44 | |
| 45 | class KeyResolver: |
no outgoing calls