[Cryptech-Commits] [sw/pkcs11] 01/05: Fix leading zero handling in Py11's BigInteger encoder.

git at cryptech.is git at cryptech.is
Thu May 19 03:17:46 UTC 2016


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch rpc
in repository sw/pkcs11.

commit b45a4ffd33f123a77f480725ea5dd9c7a3bfc143
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Mon May 16 08:56:55 2016 -0400

    Fix leading zero handling in Py11's BigInteger encoder.
---
 py11/attributes.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/py11/attributes.py b/py11/attributes.py
index 32cf940..56473ad 100644
--- a/py11/attributes.py
+++ b/py11/attributes.py
@@ -42,7 +42,7 @@ class Attribute_CK_ULONG(Attribute):
   def decode(self, x): return unpack("L", x)[0]
 
 class Attribute_biginteger(Attribute):
-  def encode(self, x): return ("%*x" % (((x.bit_length() + 7) / 8) * 2, x)).decode("hex")
+  def encode(self, x): return "\x00" if x == 0 else ("%0*x" % (((x.bit_length() + 7) / 8) * 2, x)).decode("hex")
   def decode(self, x): return long(x.encode("hex"), 16)
 
 



More information about the Commits mailing list