mirror of https://github.com/nucypher/nucypher.git
Bytes de/serialization for Signature has changed a bit now that we're using cryptography.io.
For a question about this method of serialization r and s, see: https://stackoverflow.com/questions/48726642/whats-the-proper-way-to-get-a-fixed-length-bytes-representation-of-an-ecdsa-sig/48727351#48727351pull/157/head
parent
ddd0d69ac8
commit
9ce9a8a49b
|
@ -25,7 +25,22 @@ class Signature(object):
|
|||
|
||||
:return: True if valid, False if invalid
|
||||
"""
|
||||
return API.ecdsa_verify(message, self.sig_as_bytes, pubkey)
|
||||
return API.ecdsa_verify(message, self._der_encoded_bytes(), pubkey)
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, signature_as_bytes, der_encoded=False):
|
||||
if der_encoded:
|
||||
r, s = decode_dss_signature(signature_as_bytes)
|
||||
else:
|
||||
if not len(signature_as_bytes) == 64:
|
||||
raise ValueError("Looking for exactly 64 bytes if you call from_bytes with der_encoded=False.")
|
||||
else:
|
||||
r = int.from_bytes(signature_as_bytes[:32], "big")
|
||||
s = int.from_bytes(signature_as_bytes[32:], "big")
|
||||
return cls(r, s)
|
||||
|
||||
def _der_encoded_bytes(self):
|
||||
return encode_dss_signature(self.r, self.s)
|
||||
|
||||
def __bytes__(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue