@@ -75,17 +75,17 @@ def load_private_key(key_data, passphrase=None):
75
75
try :
76
76
key = serialization .load_der_private_key (key_data , passphrase_bytes )
77
77
except ValueError :
78
- logger .warning (f "Could not load key: unknown key file format." )
78
+ logger .warning ("Could not load key: unknown key file format." )
79
79
return key
80
80
81
81
82
82
def get_signature_algorithm_from_private_key (key_data , passphrase = None , default_algorithm = "rsa-sha256" ):
83
83
"""
84
- Derive a signature algorithm based on the private key type. Returns a string that can be used to lookup
85
- a signature algorithm by fragment. Algorithms are chosen based on NIST recommendations.
84
+ Derive a signature algorithm based on the private key type. Returns a string that can be used to lookup
85
+ a signature algorithm by fragment. Algorithms are chosen based on NIST recommendations.
86
86
87
87
SignXML supports only RSA-, DSA- and EC-based signature methods. As XMLSigner uses RSA_SHA256 as default
88
- signature algorithm, a fragment that results in this algorithm is returned for unsupported keys.
88
+ signature algorithm, a fragment that results in this algorithm is returned for unsupported keys.
89
89
"""
90
90
key = load_private_key (key_data , passphrase )
91
91
if isinstance (key , rsa .RSAPrivateKey ):
@@ -111,8 +111,10 @@ def create_message(message_type, cert=None, key=None, passphrase=None, disable_s
111
111
envelope = TEMPLATES .get_template ('oadrPayload.xml' )
112
112
if cert and key and not disable_signature :
113
113
tree = etree .fromstring (signed_object )
114
- SIGNER = XMLSigner (method = methods .detached ,
115
- c14n_algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" )
114
+ SIGNER = XMLSigner (
115
+ method = methods .detached ,
116
+ c14n_algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
117
+ )
116
118
SIGNER .namespaces ['oadr' ] = "http://openadr.org/oadr-2.0b/2012/07"
117
119
SIGNER .sign_alg = SignatureMethod .from_fragment (get_signature_algorithm_from_private_key (key , passphrase ))
118
120
signature_tree = SIGNER .sign (tree ,
@@ -126,7 +128,8 @@ def create_message(message_type, cert=None, key=None, passphrase=None, disable_s
126
128
signature = None
127
129
msg = envelope .render (template = f'{ message_type } ' ,
128
130
signature = signature ,
129
- signed_object = signed_object )
131
+ signed_object = signed_object
132
+ )
130
133
logger .debug (f"Created message: { msg } " )
131
134
return msg
132
135
0 commit comments