|
5 | 5 | """
|
6 | 6 | import abc
|
7 | 7 | import logging
|
8 |
| -from typing import Dict, Type, Union |
| 8 | +from typing import Dict, Type |
9 | 9 |
|
10 | 10 | import cryptography.exceptions
|
11 | 11 | from cryptography.hazmat.backends import default_backend
|
12 | 12 | from cryptography.hazmat.primitives import hashes
|
13 | 13 | from cryptography.hazmat.primitives import hmac
|
14 |
| -from cryptography.hazmat.primitives.asymmetric import ec, x25519, x448 |
15 |
| -from cryptography.hazmat.primitives.asymmetric import ed25519 |
16 |
| -from cryptography.hazmat.primitives.asymmetric import ed448 |
| 14 | +from cryptography.hazmat.primitives.asymmetric import ec |
17 | 15 | from cryptography.hazmat.primitives.asymmetric import padding
|
18 | 16 | from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature
|
19 | 17 | from cryptography.hazmat.primitives.asymmetric.utils import encode_dss_signature
|
@@ -233,20 +231,15 @@ def __init__(self, name, hash_):
|
233 | 231 | super().__init__(name)
|
234 | 232 | self.hash = hash_()
|
235 | 233 |
|
236 |
| - def sign(self, key: Union[ |
237 |
| - ed25519.Ed25519PrivateKey, |
238 |
| - ed448.Ed448PrivateKey, |
239 |
| - x25519.X25519PrivateKey, |
240 |
| - x448.X448PrivateKey, |
241 |
| - ], msg: bytes): |
| 234 | + @classmethod |
| 235 | + def register(cls, signature_cls): |
| 236 | + # might need to overwrite this, so I can get the argument in |
| 237 | + return super().register(signature_cls) |
| 238 | + |
| 239 | + def sign(self, key, msg: bytes): |
242 | 240 | return key.sign(msg)
|
243 | 241 |
|
244 |
| - def verify(self, key: Union[ |
245 |
| - ed25519.Ed25519PublicKey, |
246 |
| - ed448.Ed448PublicKey, |
247 |
| - x25519.X25519PrivateKey, |
248 |
| - x448.X448PrivateKey, |
249 |
| - ], msg: bytes, sig: bytes): |
| 242 | + def verify(self, key, msg: bytes, sig: bytes): |
250 | 243 | try:
|
251 | 244 | key.verify(signature=sig, data=msg)
|
252 | 245 | except cryptography.exceptions.InvalidSignature as error:
|
@@ -287,8 +280,8 @@ def verify(self, key: Union[
|
287 | 280 | #: Ed25519 uses SHA512
|
288 | 281 | ES25519 = JWASignature.register(_JWAOKP('ES25519', hashes.SHA512))
|
289 | 282 | #: Ed448 uses SHA3/SHAKE256
|
290 |
| -ES448 = JWASignature.register(_JWAOKP('ES448', hashes.SHAKE256)) |
291 |
| -#: X25519 uses |
292 |
| -X22519 = JWASignature.register(_JWAOKP('X22519', hashes.SHAKE256)) |
293 |
| -#: X448 uses |
294 |
| -X448 = JWASignature.register(_JWAOKP('X448', hashes.SHAKE256)) |
| 283 | +# ES448 = JWASignature.register(_JWAOKP('ES448', hashes.SHAKE256)) |
| 284 | +# #: X25519 uses SHA3/SHAKE256 |
| 285 | +# X22519 = JWASignature.register(_JWAOKP('X22519', hashes.SHAKE256)) |
| 286 | +# #: X448 uses SHA3/SHAKE256 |
| 287 | +# X448 = JWASignature.register(_JWAOKP('X448', hashes.SHAKE256)) |
0 commit comments