Merge "Use hex strings instead of messing with bits"
This commit is contained in:
commit
5bec7f9ae8
@ -228,8 +228,8 @@ class X509Certificate(signature.SignatureMixin):
|
||||
self._cert['tbsCertificate']['signature'] = algo_id
|
||||
|
||||
def _embed_signature(self, algo_id, signature):
|
||||
self._cert['signatureValue'] = "'%s'B" % (
|
||||
utils.bytes_to_bin(signature),)
|
||||
self._cert['signatureValue'] = "'%s'H" % (
|
||||
str(binascii.hexlify(signature).decode('ascii')),)
|
||||
self._cert['signatureAlgorithm'] = algo_id
|
||||
|
||||
def _get_signature(self):
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import binascii
|
||||
import io
|
||||
|
||||
from pyasn1.codec.der import decoder
|
||||
@ -204,4 +205,5 @@ class X509Csr(signature.SignatureMixin):
|
||||
|
||||
def _embed_signature(self, algo_id, signature):
|
||||
self._csr['signatureAlgorithm'] = algo_id
|
||||
self._csr['signature'] = "'%s'B" % (utils.bytes_to_bin(signature),)
|
||||
self._csr['signature'] = "'%s'H" % (
|
||||
str(binascii.hexlify(signature).decode('ascii')),)
|
||||
|
@ -136,20 +136,6 @@ def _pad_byte(bits):
|
||||
return ((8-r) % 8)*'0' + bits
|
||||
|
||||
|
||||
def bytes_to_bin(bytes):
|
||||
"""Convert byte string to bit string."""
|
||||
return "".join([_pad_byte(_int_to_bin(_ord(byte))) for byte in bytes])
|
||||
|
||||
|
||||
def _int_to_bin(n):
|
||||
if n == 0 or n == 1:
|
||||
return str(n)
|
||||
elif n % 2 == 0:
|
||||
return _int_to_bin(n // 2) + "0"
|
||||
else:
|
||||
return _int_to_bin(n // 2) + "1"
|
||||
|
||||
|
||||
def get_hash_class(md):
|
||||
return getattr(hashes, md.upper(), None)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user