|
1 | | -from typing import Union |
2 | | - |
3 | 1 | from cryptography.hazmat.primitives import serialization |
4 | 2 | from cryptography.hazmat.primitives.asymmetric import ed448, ed25519, x448, x25519 |
5 | 3 |
|
|
14 | 12 | import_public_key_from_pem_file, |
15 | 13 | ) |
16 | 14 |
|
17 | | -OKPPublicKey = Union[ |
18 | | - ed25519.Ed25519PublicKey, ed448.Ed448PublicKey, x25519.X25519PublicKey, x448.X448PublicKey |
19 | | -] |
20 | | -OKPPrivateKey = Union[ |
21 | | - ed25519.Ed25519PrivateKey, ed448.Ed448PrivateKey, x25519.X25519PrivateKey, x448.X448PrivateKey |
22 | | -] |
| 15 | +OKPPublicKey = ( |
| 16 | + ed25519.Ed25519PublicKey | ed448.Ed448PublicKey | x25519.X25519PublicKey | x448.X448PublicKey |
| 17 | +) |
| 18 | + |
| 19 | +OKPPrivateKey = ( |
| 20 | + ed25519.Ed25519PrivateKey |
| 21 | + | ed448.Ed448PrivateKey |
| 22 | + | x25519.X25519PrivateKey |
| 23 | + | x448.X448PrivateKey |
| 24 | +) |
23 | 25 |
|
24 | 26 | OKP_CRV2PUBLIC = { |
25 | 27 | "Ed25519": ed25519.Ed25519PublicKey, |
@@ -155,7 +157,8 @@ def deserialize(self): |
155 | 157 | def _serialize_public(self, key): |
156 | 158 | self.x = b64e( |
157 | 159 | key.public_bytes( |
158 | | - encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw |
| 160 | + encoding=serialization.Encoding.Raw, |
| 161 | + format=serialization.PublicFormat.Raw, |
159 | 162 | ) |
160 | 163 | ).decode("ascii") |
161 | 164 |
|
@@ -304,9 +307,11 @@ def cmp_keys(a, b, key_type): |
304 | 307 | return False |
305 | 308 | else: |
306 | 309 | if a.public_bytes( |
307 | | - encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw |
| 310 | + encoding=serialization.Encoding.Raw, |
| 311 | + format=serialization.PublicFormat.Raw, |
308 | 312 | ) != b.public_bytes( |
309 | | - encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw |
| 313 | + encoding=serialization.Encoding.Raw, |
| 314 | + format=serialization.PublicFormat.Raw, |
310 | 315 | ): |
311 | 316 | return False |
312 | 317 | return True |
|
0 commit comments