Parses a wrapped key string into a tuple: (key id, version, key) given input in the form: :v :
(wrapped_key: str)
| 55 | |
| 56 | |
| 57 | def parse_wrapped_key(wrapped_key: str) -> tuple[str, int, bytes]: |
| 58 | """Parses a wrapped key string into a tuple: (key id, version, key) given |
| 59 | input in the form: <key id>:v<version>:<bas64 encoded key>""" |
| 60 | ptn = re.compile("(.+?):v([0-9]+?):(.+)") |
| 61 | if m := ptn.fullmatch(wrapped_key): |
| 62 | id, version, b64key = m.groups() |
| 63 | version = int(version) |
| 64 | key = base64.b64decode(b64key) |
| 65 | return (id, version, key) |
| 66 | else: |
| 67 | raise ValueError("Cannot parse wrapped key", wrapped_key) |
| 68 | |
| 69 | |
| 70 | MASTER_KEY_VERSION = "master_key_version" |
no outgoing calls