fix Py3k issues

This commit is contained in:
Roman Zeyde
2015-07-21 14:38:40 +03:00
parent b6d0efef9f
commit e7585170ae
2 changed files with 14 additions and 12 deletions

View File

@@ -9,8 +9,8 @@ import logging
log = logging.getLogger(__name__)
DER_OCTET_STRING = b'\x04'
ECDSA_KEY_TYPE = 'ecdsa-sha2-nistp256'
ECDSA_CURVE_NAME = 'nistp256'
ECDSA_KEY_TYPE = b'ecdsa-sha2-nistp256'
ECDSA_CURVE_NAME = b'nistp256'
curve = ecdsa.NIST256p
hashfunc = hashlib.sha256
@@ -57,21 +57,23 @@ def decompress_pubkey(pub):
B = curve.curve.b()
x = util.bytes2num(pub[1:33])
beta = pow(int(x*x*x+A*x+B), int((P+1)//4), int(P))
y = (P-beta) if ((beta + ord(pub[0])) % 2) else beta
p0 = util.bytes2num(pub[:1])
y = (P-beta) if ((beta + p0) % 2) else beta
point = ecdsa.ellipticcurve.Point(curve.curve, x, y)
vk = ecdsa.VerifyingKey.from_public_point(point, curve=curve,
hashfunc=hashfunc)
parts = [ECDSA_KEY_TYPE, ECDSA_CURVE_NAME,
DER_OCTET_STRING + vk.to_string()]
return ''.join([util.frame(p) for p in parts])
return b''.join([util.frame(p) for p in parts])
def export_public_key(pubkey, label):
blob = decompress_pubkey(pubkey)
log.debug('fingerprint: %s', fingerprint(blob))
b64 = base64.b64encode(blob)
return '{} {} {}\n'.format(ECDSA_KEY_TYPE, b64, label)
b64 = base64.b64encode(blob).decode('ascii')
return '{} {} {}\n'.format(ECDSA_KEY_TYPE.decode('ascii'), b64, label)
def import_public_key(line):