@@ -77,22 +77,6 @@ def load_private_key(key_data, passphrase=None):
7777 logger .warning (f"Could not load key: unknown key file format." )
7878 return key
7979
80- def get_private_key_type (key ):
81- """
82- Determine the type of the key. ED25519 and ED448 are not supported by SignXML so these are rejected.
83- """
84- if isinstance (key , rsa .RSAPrivateKey ):
85- return "rsa"
86- elif isinstance (key , dsa .DSAPrivateKey ):
87- return "dsa"
88- elif isinstance (key , ec .EllipticCurvePrivateKey ):
89- return "ec"
90- elif isinstance (key , ed25519 .Ed25519PrivateKey ):
91- logger .warning ("ED25519 keys are not supported" )
92- elif isinstance (key , ed448 .Ed448PrivateKey ):
93- logger .warning ("ED448 keys are not supported" )
94- logger .warning ("Unknown key type." )
95-
9680
9781def get_signature_algorithm_from_private_key (key_data , passphrase = None , default_algorithm = "rsa-sha256" ):
9882 """
@@ -101,15 +85,19 @@ def get_signature_algorithm_from_private_key(key_data, passphrase=None, default_
10185 By default the lookup will return rsa-sha256, which is the default signature algorithm for XMLSigner objects.
10286 """
10387 key = load_private_key (key_data , passphrase )
104- key_type = get_private_key_type (key )
105- if key_type == "rsa" :
88+ if isinstance (key , rsa .RSAPrivateKey ):
10689 return "rsa-sha256"
107- elif key_type == " dsa" :
90+ elif isinstance ( key , dsa . DSAPrivateKey ) :
10891 return "dsa-sha256"
109- elif key_type == "ec" :
92+ elif isinstance ( key , ec . EllipticCurvePrivateKey ) :
11093 return "ecdsa-sha3-256"
94+ elif isinstance (key , ed25519 .Ed25519PrivateKey ):
95+ logger .warning ("ED25519 keys are not supported" )
96+ elif isinstance (key , ed448 .Ed448PrivateKey ):
97+ logger .warning ("ED448 keys are not supported" )
11198 return default_algorithm
11299
100+
113101def create_message (message_type , cert = None , key = None , passphrase = None , disable_signature = False , ** message_payload ):
114102 """
115103 Create and optionally sign an OpenADR message. Returns an XML string.
0 commit comments