1010
1111
1212class EDDSASigner (Signer ):
13+ def __init__ (self , algorithm = None ):
14+ self .algorithm = algorithm
15+
1316 def sign (self , msg , key ):
1417 """
1518 Create a signature over a message as defined in RFC7515 using an
@@ -20,6 +23,17 @@ def sign(self, msg, key):
2023 :return:
2124 """
2225
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+
2337 if not isinstance (key , (ed25519 .Ed25519PrivateKey , ed448 .Ed448PrivateKey )):
2438 raise TypeError (
2539 "The private key must be an instance of Ed25519PrivateKey or Ed448PrivateKey"
@@ -37,6 +51,13 @@ def verify(self, msg, sig, key):
3751 :raises: BadSignature if the signature can't be verified.
3852 :return: True
3953 """
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+
4061 if not isinstance (key , (ed25519 .Ed25519PublicKey , ed448 .Ed448PublicKey )):
4162 raise TypeError (
4263 "The public key must be an instance of Ed25519PublicKey or Ed448PublicKey"
0 commit comments