fixes from review

This commit is contained in:
Victor Shyba 2019-01-17 21:24:24 -03:00 committed by Lex Berezhny
parent 68b56b7858
commit 0e9888be3b
2 changed files with 9 additions and 10 deletions

View file

@ -39,7 +39,7 @@ class ClaimDict(OrderedDict):
@property @property
def serialized(self): def serialized(self):
"""Serialized Claim protobuf""" """Serialized Claim protobuf"""
if self.detached_signature and self.detached_signature.payload: if self.detached_signature:
return self.detached_signature.serialized return self.detached_signature.serialized
return self.protobuf.SerializeToString() return self.protobuf.SerializeToString()
@ -52,10 +52,9 @@ class ClaimDict(OrderedDict):
@property @property
def has_signature(self): def has_signature(self):
claim = self.protobuf return self.protobuf.HasField("publisherSignature") or (
if claim.HasField("publisherSignature"): self.detached_signature and self.detached_signature.raw_signature
return True )
return self.detached_signature and self.detached_signature.certificate_id
@property @property
def is_certificate(self): def is_certificate(self):
@ -94,11 +93,10 @@ class ClaimDict(OrderedDict):
@property @property
def certificate_id(self): def certificate_id(self):
if self.protobuf.HasField("publisherSignature"):
return binascii.hexlify(self.protobuf.publisherSignature.certificateId)
if self.detached_signature and self.detached_signature.certificate_id: if self.detached_signature and self.detached_signature.certificate_id:
return binascii.hexlify(self.detached_signature.certificate_id) return binascii.hexlify(self.detached_signature.certificate_id)
if not self.has_signature:
return None
return binascii.hexlify(self.protobuf.publisherSignature.certificateId)
@property @property
def signature(self): def signature(self):

View file

@ -1,5 +1,7 @@
from collections import namedtuple from collections import namedtuple
from typing import Union
LEGACY = namedtuple('Legacy', 'payload') LEGACY = namedtuple('Legacy', 'payload')
NAMED_SECP256K1 = namedtuple('NamedSECP256k1', 'raw_signature certificate_id payload') NAMED_SECP256K1 = namedtuple('NamedSECP256k1', 'raw_signature certificate_id payload')
FLAGS = { FLAGS = {
@ -9,8 +11,7 @@ FLAGS = {
class Signature: class Signature:
def __init__(self, data: namedtuple): def __init__(self, data: Union[LEGACY, NAMED_SECP256K1]):
assert isinstance(data, (LEGACY, NAMED_SECP256K1))
self.data = data self.data = data
@property @property