Skip to content

Commit ff72a55

Browse files
committed
Fixed Flake8 compliancy.
1 parent 0f09e10 commit ff72a55

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

openleadr/messaging.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ def load_private_key(key_data, passphrase=None):
7575
try:
7676
key = serialization.load_der_private_key(key_data, passphrase_bytes)
7777
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.")
7979
return key
8080

8181

8282
def get_signature_algorithm_from_private_key(key_data, passphrase=None, default_algorithm="rsa-sha256"):
8383
"""
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.
8686
8787
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.
8989
"""
9090
key = load_private_key(key_data, passphrase)
9191
if isinstance(key, rsa.RSAPrivateKey):
@@ -111,8 +111,10 @@ def create_message(message_type, cert=None, key=None, passphrase=None, disable_s
111111
envelope = TEMPLATES.get_template('oadrPayload.xml')
112112
if cert and key and not disable_signature:
113113
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+
)
116118
SIGNER.namespaces['oadr'] = "http://openadr.org/oadr-2.0b/2012/07"
117119
SIGNER.sign_alg = SignatureMethod.from_fragment(get_signature_algorithm_from_private_key(key, passphrase))
118120
signature_tree = SIGNER.sign(tree,
@@ -126,7 +128,8 @@ def create_message(message_type, cert=None, key=None, passphrase=None, disable_s
126128
signature = None
127129
msg = envelope.render(template=f'{message_type}',
128130
signature=signature,
129-
signed_object=signed_object)
131+
signed_object=signed_object
132+
)
130133
logger.debug(f"Created message: {msg}")
131134
return msg
132135

test/test_signature_algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def test_key_type_sign_alg_match(key_type, expected_alg):
2929

3030
detected_alg = get_signature_algorithm_from_private_key(key_bytes)
3131

32-
assert detected_alg == expected_alg
32+
assert detected_alg == expected_alg

0 commit comments

Comments
 (0)