gpg: move PublicKey to proto

This commit is contained in:
Roman Zeyde
2016-05-21 17:10:17 +03:00
parent ce61c8b2ae
commit 0e72e3b7ff
2 changed files with 40 additions and 39 deletions

View File

@@ -74,44 +74,6 @@ class AgentSigner(object):
self.sock.close()
class PublicKey(object):
"""GPG representation for public key packets."""
def __init__(self, curve_name, created, verifying_key):
"""Contruct using a ECDSA VerifyingKey object."""
self.curve_info = proto.SUPPORTED_CURVES[curve_name]
self.created = int(created) # time since Epoch
self.verifying_key = verifying_key
self.algo_id = self.curve_info['algo_id']
def data(self):
"""Data for packet creation."""
header = struct.pack('>BLB',
4, # version
self.created, # creation
self.algo_id) # public key algorithm ID
oid = util.prefix_len('>B', self.curve_info['oid'])
blob = self.curve_info['serialize'](self.verifying_key)
return header + oid + blob
def data_to_hash(self):
"""Data for digest computation."""
return b'\x99' + util.prefix_len('>H', self.data())
def _fingerprint(self):
return hashlib.sha1(self.data_to_hash()).digest()
def key_id(self):
"""Short (8 byte) GPG key ID."""
return self._fingerprint()[-8:]
def __repr__(self):
"""Short (8 hexadecimal digits) GPG key ID."""
return '<{}>'.format(util.hexlify(self.key_id()))
__str__ = __repr__
def _time_format(t):
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))
@@ -125,7 +87,7 @@ class Signer(object):
assert curve_name in formats.SUPPORTED_CURVES
self.conn = HardwareSigner(user_id, curve_name=curve_name)
self.pubkey = PublicKey(
self.pubkey = proto.PublicKey(
curve_name=curve_name, created=created,
verifying_key=self.conn.pubkey())