1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

trezor/utils: refactor 'serialize_identity()'

This commit is contained in:
Roman Zeyde 2018-03-09 17:13:18 +02:00 committed by Pavol Rusnak
parent cfb50f751e
commit de217f75df
2 changed files with 16 additions and 16 deletions

View File

@ -2,7 +2,7 @@ from trezor import ui
from trezor.crypto.hashlib import sha256 from trezor.crypto.hashlib import sha256
from trezor.messages.SignedIdentity import SignedIdentity from trezor.messages.SignedIdentity import SignedIdentity
from ustruct import pack, unpack from ustruct import pack, unpack
from trezor.utils import chunks from trezor.utils import chunks, serialize_identity
from apps.common.confirm import require_confirm from apps.common.confirm import require_confirm
from trezor.ui.text import Text from trezor.ui.text import Text
@ -51,21 +51,6 @@ async def require_confirm_sign_identity(ctx, identity, challenge_visual):
await require_confirm(ctx, content) await require_confirm(ctx, content)
def serialize_identity(identity):
s = ''
if identity.proto:
s += identity.proto + '://'
if identity.user:
s += identity.user + '@'
if identity.host:
s += identity.host
if identity.port:
s += ':' + identity.port
if identity.path:
s += identity.path
return s
def get_identity_path(identity: str, index: int): def get_identity_path(identity: str, index: int):
identity_hash = sha256(pack('<I', index) + identity).digest() identity_hash = sha256(pack('<I', index) + identity).digest()

View File

@ -64,6 +64,21 @@ def format_ordinal(number):
return str(number) + {1: 'st', 2: 'nd', 3: 'rd'}.get(4 if 10 <= number % 100 < 20 else number % 10, 'th') return str(number) + {1: 'st', 2: 'nd', 3: 'rd'}.get(4 if 10 <= number % 100 < 20 else number % 10, 'th')
def serialize_identity(identity):
s = ''
if identity.proto:
s += identity.proto + '://'
if identity.user:
s += identity.user + '@'
if identity.host:
s += identity.host
if identity.port:
s += ':' + identity.port
if identity.path:
s += identity.path
return s
class HashWriter: class HashWriter:
def __init__(self, hashfunc): def __init__(self, hashfunc):