Skip to content

Commit 8723871

Browse files
committed
add comments regarding signature formats
1 parent 29b4db4 commit 8723871

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/cryptojwt/jws.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,14 @@ def __init__(self, algorithm='SHA256'):
176176
raise UnSupported('algorithm: {}'.format(algorithm))
177177

178178
def sign(self, msg, key):
179+
# cryptography returns ASN.1-encoded signature data; decode as JWS uses raw signatures (r||s)
179180
asn1sig = key.sign(msg, ec.ECDSA(self.hash_algorithm()))
180181
(r, s) = decode_dss_signature(asn1sig)
181182
return int_to_bytes(r) + int_to_bytes(s)
182183

183184
def verify(self, msg, sig, key):
184185
try:
186+
# cryptography uses ASN.1-encoded signature data; split JWS signature (r||s) and encode before verification
185187
(r, s) = self._split_raw_signature(sig)
186188
asn1sig = encode_dss_signature(r, s)
187189
key.verify(asn1sig, msg, ec.ECDSA(self.hash_algorithm()))
@@ -192,6 +194,7 @@ def verify(self, msg, sig, key):
192194

193195
@staticmethod
194196
def _split_raw_signature(sig):
197+
"""Split raw signature into components"""
195198
c_length = len(sig) // 2
196199
r = int_from_bytes(sig[:c_length], byteorder='big')
197200
s = int_from_bytes(sig[c_length:], byteorder='big')

0 commit comments

Comments
 (0)