From 440e3e13b6ffa552eba6e0a3d2aeabd59692b132 Mon Sep 17 00:00:00 2001 From: jMyles Date: Sat, 10 Feb 2018 19:05:36 -0800 Subject: [PATCH] Signature r+s concatenation serialization. --- nkms/crypto/signature.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/nkms/crypto/signature.py b/nkms/crypto/signature.py index 6f9ebec9b..5817d8904 100644 --- a/nkms/crypto/signature.py +++ b/nkms/crypto/signature.py @@ -43,8 +43,14 @@ class Signature(object): return encode_dss_signature(self.r, self.s) def __bytes__(self): - """ - Implements the __bytes__ call for Signature to transform into a - transportable mode. - """ - return self.sig_as_bytes + # A couple quick assertions to be sure this is OK. Remove these at some point. + assert self.r.to_bytes(33, "big")[0] == 0, "Is 32 bytes enough?" + assert self.s.to_bytes(33, "big")[0] == 0, "Is 32 bytes enough?" + return self.r.to_bytes(32, "big") + self.s.to_bytes(32, "big") + + def __len__(self): + return len(bytes(self)) + + def __add__(self, other): + return bytes(self) + other + __radd__ = __add__