Make Package.signature return str key_id

We use the attribute in many places, but it's a "bytes" object in
pgpdump that messes up the remaining logic. Let's just wrap it from the
very beginning.
This commit is contained in:
Felix Yan 2019-02-09 01:49:15 +08:00 committed by Jelle van der Waa
parent 4a2c87b0f6
commit a5d05569df
2 changed files with 11 additions and 2 deletions

View File

@ -7,7 +7,7 @@
from django.contrib.sites.models import Site
from .fields import PositiveBigIntegerField
from .utils import set_created_field, DependStandin
from .utils import set_created_field, DependStandin, SignatureWrapper
from devel.models import DeveloperKey
from packages.alpm import AlpmAPI
@ -142,7 +142,7 @@ def signature(self):
return None
data = BinaryData(self.signature_bytes)
packets = list(data.packets())
return packets[0]
return SignatureWrapper(packets[0])
@property
def signer(self):

View File

@ -6,6 +6,7 @@
import hashlib
import markdown
from markdown.extensions import Extension
from pgpdump.packet import SignaturePacket
from django.core.cache import cache
from django.db import connections, router
@ -165,4 +166,12 @@ def __init__(self, depends):
self.deptype = first.deptype
self.pkg = first.pkg.base_package() or PackageStandin(first.pkg)
class SignatureWrapper(SignaturePacket):
'Decode key_id from raw SignaturePacket'
def __init__(self, packet):
for field in ("sig_version", "creation_time", "expiration_time"):
setattr(self, field, getattr(packet, field))
self.key_id = str(packet.key_id) if packet.key_id else None
# vim: set ts=4 sw=4 et: