mirror of
https://github.com/romanz/amodem.git
synced 2026-02-06 16:48:06 +08:00
gpg: fixup str/bytes issues
This commit is contained in:
@@ -325,7 +325,7 @@ def verify(pubkey, signature, original_data):
|
||||
|
||||
# remove GPG armor
|
||||
lines = stream.readlines()[3:-1]
|
||||
data = base64.b64decode(''.join(lines))
|
||||
data = base64.b64decode(b''.join(lines))
|
||||
payload, checksum = data[:-3], data[-3:]
|
||||
assert util.crc24(payload) == checksum
|
||||
stream = io.BytesIO(payload)
|
||||
|
||||
@@ -103,11 +103,12 @@ class Factory(object):
|
||||
def create_primary(self):
|
||||
"""Export new primary GPG public key, ready for "gpg2 --import"."""
|
||||
pubkey_packet = proto.packet(tag=6, blob=self.pubkey.data())
|
||||
user_id_packet = proto.packet(tag=13, blob=self.user_id)
|
||||
user_id_packet = proto.packet(tag=13,
|
||||
blob=self.user_id.encode('ascii'))
|
||||
|
||||
data_to_sign = (self.pubkey.data_to_hash() +
|
||||
user_id_packet[:1] +
|
||||
util.prefix_len('>L', self.user_id))
|
||||
util.prefix_len('>L', self.user_id.encode('ascii')))
|
||||
log.info('signing public key "%s"', self.user_id)
|
||||
hashed_subpackets = [
|
||||
proto.subpacket_time(self.pubkey.created), # signature time
|
||||
|
||||
@@ -150,8 +150,8 @@ def _split_lines(body, size):
|
||||
def armor(blob, type_str):
|
||||
"""See https://tools.ietf.org/html/rfc4880#section-6 for details."""
|
||||
head = '-----BEGIN PGP {}-----\nVersion: GnuPG v2\n\n'.format(type_str)
|
||||
body = base64.b64encode(blob)
|
||||
checksum = base64.b64encode(util.crc24(blob))
|
||||
body = base64.b64encode(blob).decode('ascii')
|
||||
checksum = base64.b64encode(util.crc24(blob)).decode('ascii')
|
||||
tail = '-----END PGP {}-----\n'.format(type_str)
|
||||
return head + _split_lines(body, 64) + '=' + checksum + '\n' + tail
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ def run_sign(args):
|
||||
data = sys.stdin.read()
|
||||
sig = f.sign_message(data)
|
||||
|
||||
sig = proto.armor(sig, 'SIGNATURE')
|
||||
sig = proto.armor(sig, 'SIGNATURE').encode('ascii')
|
||||
decode.verify(pubkey=pubkey, signature=sig, original_data=data)
|
||||
|
||||
filename = '-' # write to stdout
|
||||
|
||||
Reference in New Issue
Block a user