10
10
11
11
12
12
class EDDSASigner (Signer ):
13
+ def __init__ (self , algorithm = None ):
14
+ self .algorithm = algorithm
15
+
13
16
def sign (self , msg , key ):
14
17
"""
15
18
Create a signature over a message as defined in RFC7515 using an
@@ -20,6 +23,17 @@ def sign(self, msg, key):
20
23
:return:
21
24
"""
22
25
26
+ if self .algorithm :
27
+ if self .algorithm == "Ed25519" and not isinstance (key , ed25519 .Ed25519PrivateKey ):
28
+ raise TypeError ("The private key must be an instance of Ed25519PrivateKey" )
29
+ if self .algorithm == "Ed448" and not isinstance (key , ed448 .Ed448PrivateKey ):
30
+ raise TypeError ("The private key must be an instance of Ed448PrivateKey" )
31
+
32
+ if not isinstance (key , (ed25519 .Ed25519PrivateKey , ed448 .Ed448PrivateKey )):
33
+ raise TypeError (
34
+ "The private key must be an instance of Ed25519PrivateKey or Ed448PrivateKey"
35
+ )
36
+
23
37
if not isinstance (key , (ed25519 .Ed25519PrivateKey , ed448 .Ed448PrivateKey )):
24
38
raise TypeError (
25
39
"The private key must be an instance of Ed25519PrivateKey or Ed448PrivateKey"
@@ -37,6 +51,13 @@ def verify(self, msg, sig, key):
37
51
:raises: BadSignature if the signature can't be verified.
38
52
:return: True
39
53
"""
54
+
55
+ if self .algorithm :
56
+ if self .algorithm == "Ed25519" and not isinstance (key , ed25519 .Ed25519PublicKey ):
57
+ raise TypeError ("The public key must be an instance of Ed25519PublicKey" )
58
+ if self .algorithm == "Ed448" and not isinstance (key , ed448 .Ed448PublicKey ):
59
+ raise TypeError ("The public key must be an instance of Ed448PublicKey" )
60
+
40
61
if not isinstance (key , (ed25519 .Ed25519PublicKey , ed448 .Ed448PublicKey )):
41
62
raise TypeError (
42
63
"The public key must be an instance of Ed25519PublicKey or Ed448PublicKey"
0 commit comments