Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
style: new black release formats all hex numbers in uppercase
Browse files Browse the repository at this point in the history
introduced in the new 18.9 version of black
  • Loading branch information
tsusanka committed Oct 3, 2018
1 parent ace3574 commit 8aa29ae
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/apps/cardano/cbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

_CBOR_UINT8_FOLLOWS = const(0x18)
_CBOR_UINT16_FOLLOWS = const(0x19)
_CBOR_UINT32_FOLLOWS = const(0x1a)
_CBOR_UINT64_FOLLOWS = const(0x1b)
_CBOR_VAR_FOLLOWS = const(0x1f)
_CBOR_UINT32_FOLLOWS = const(0x1A)
_CBOR_UINT64_FOLLOWS = const(0x1B)
_CBOR_VAR_FOLLOWS = const(0x1F)

_CBOR_BREAK = const(0x1f)
_CBOR_BREAK = const(0x1F)
_CBOR_RAW_TAG = const(0x18)


Expand Down
2 changes: 1 addition & 1 deletion src/apps/ethereum/get_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def get_address(ctx, msg):

if msg.show_display:
if len(address_n) > 1: # path has slip44 network identifier
network = networks.by_slip44(address_n[1] & 0x7fffffff)
network = networks.by_slip44(address_n[1] & 0x7FFFFFFF)
else:
network = None
hex_addr = _ethereum_address_hex(address, network)
Expand Down
20 changes: 10 additions & 10 deletions src/apps/fido_u2f/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from apps.common import HARDENED, storage

_HID_RPT_SIZE = const(64)
_CID_BROADCAST = const(0xffffffff) # broadcast channel id
_CID_BROADCAST = const(0xFFFFFFFF) # broadcast channel id

# types of frame
_TYPE_MASK = const(0x80) # frame type mask
Expand All @@ -23,7 +23,7 @@
_CMD_LOCK = const(0x84) # send lock channel command
_CMD_INIT = const(0x86) # channel initialization
_CMD_WINK = const(0x88) # send device identification wink
_CMD_ERROR = const(0xbf) # error response
_CMD_ERROR = const(0xBF) # error response

# types for the msg cmd
_MSG_REGISTER = const(0x01) # registration command
Expand All @@ -38,18 +38,18 @@
_ERR_INVALID_SEQ = const(0x04) # invalid message sequencing
_ERR_MSG_TIMEOUT = const(0x05) # message has timed out
_ERR_CHANNEL_BUSY = const(0x06) # channel busy
_ERR_LOCK_REQUIRED = const(0x0a) # command requires channel lock
_ERR_INVALID_CID = const(0x0b) # command not allowed on this cid
_ERR_OTHER = const(0x7f) # other unspecified error
_ERR_LOCK_REQUIRED = const(0x0A) # command requires channel lock
_ERR_INVALID_CID = const(0x0B) # command not allowed on this cid
_ERR_OTHER = const(0x7F) # other unspecified error

# command status responses
_SW_NO_ERROR = const(0x9000)
_SW_WRONG_LENGTH = const(0x6700)
_SW_DATA_INVALID = const(0x6984)
_SW_CONDITIONS_NOT_SATISFIED = const(0x6985)
_SW_WRONG_DATA = const(0x6a80)
_SW_INS_NOT_SUPPORTED = const(0x6d00)
_SW_CLA_NOT_SUPPORTED = const(0x6e00)
_SW_WRONG_DATA = const(0x6A80)
_SW_INS_NOT_SUPPORTED = const(0x6D00)
_SW_CLA_NOT_SUPPORTED = const(0x6E00)

# init response
_CAPFLAG_WINK = const(0x01) # device supports _CMD_WINK
Expand Down Expand Up @@ -491,7 +491,7 @@ def cmd_init(req: Cmd) -> Cmd:
return cmd_error(req.cid, _ERR_INVALID_CID)
elif req.cid == _CID_BROADCAST:
# uint32_t except 0 and 0xffffffff
resp_cid = random.uniform(0xfffffffe) + 1
resp_cid = random.uniform(0xFFFFFFFE) + 1
else:
resp_cid = req.cid

Expand Down Expand Up @@ -552,7 +552,7 @@ def msg_register_sign(challenge: bytes, app_id: bytes) -> bytes:
from apps.common import seed

# derivation path is m/U2F'/r'/r'/r'/r'/r'/r'/r'/r'
keypath = [HARDENED | random.uniform(0xf0000000) for _ in range(0, 8)]
keypath = [HARDENED | random.uniform(0xF0000000) for _ in range(0, 8)]
nodepath = [_U2F_KEY_PATH] + keypath

# prepare signing key from random path, compute decompressed public key
Expand Down
2 changes: 1 addition & 1 deletion src/apps/nem/namespace/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def serialize_provision_namespace(
if namespace.parent:
write_bytes_with_len(tx, namespace.parent.encode())
else:
write_uint32_le(tx, 0xffffffff)
write_uint32_le(tx, 0xFFFFFFFF)

return tx
10 changes: 5 additions & 5 deletions src/apps/ripple/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def write(w: bytearray, field: dict, value):


def write_type(w: bytearray, field: dict):
if field["key"] <= 0xf:
if field["key"] <= 0xF:
w.append((field["type"] << 4) | field["key"])
else:
# this concerns two-bytes fields such as lastLedgerSequence
Expand All @@ -88,7 +88,7 @@ def serialize_amount(value: int) -> bytearray:
raise ValueError("Value is too large")

b = bytearray(value.to_bytes(8, "big"))
b[0] &= 0x7f # clear first bit to indicate XRP
b[0] &= 0x7F # clear first bit to indicate XRP
b[0] |= 0x40 # set second bit to indicate positive number
return b

Expand All @@ -111,12 +111,12 @@ def write_varint(w: bytearray, val: int):
elif val <= 12480:
val -= 193
w.append(193 + rshift(val, 8))
w.append(val & 0xff)
w.append(val & 0xFF)
elif val <= 918744:
val -= 12481
w.append(241 + rshift(val, 16))
w.append(rshift(val, 8) & 0xff)
w.append(val & 0xff)
w.append(rshift(val, 8) & 0xFF)
w.append(val & 0xFF)
else:
raise ValueError("Value is too large")

Expand Down
2 changes: 1 addition & 1 deletion src/apps/stellar/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ def _crc16_checksum(data: bytes) -> bytes:
if c15 ^ bit:
crc ^= polynomial

return ustruct.pack("<H", crc & 0xffff)
return ustruct.pack("<H", crc & 0xFFFF)
2 changes: 1 addition & 1 deletion src/apps/wallet/sign_tx/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def sanitize_tx_input(tx: TransactionType) -> TxInputType:
if txi.script_type is None:
txi.script_type = InputScriptType.SPENDADDRESS
if txi.sequence is None:
txi.sequence = 0xffffffff
txi.sequence = 0xFFFFFFFF
return txi


Expand Down
2 changes: 1 addition & 1 deletion src/apps/wallet/sign_tx/tx_weight_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def ser_length_size(length: int):

@staticmethod
def op_push_size(length: int):
if length < 0x4c:
if length < 0x4C:
return 1
if length < 0x100:
return 2
Expand Down
10 changes: 5 additions & 5 deletions src/trezor/crypto/base32.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def encode(s: bytes) -> str:
encoded += bytes(
[
_b32tab[c1 >> 11], # bits 1 - 5
_b32tab[(c1 >> 6) & 0x1f], # bits 6 - 10
_b32tab[(c1 >> 1) & 0x1f], # bits 11 - 15
_b32tab[(c1 >> 6) & 0x1F], # bits 6 - 10
_b32tab[(c1 >> 1) & 0x1F], # bits 11 - 15
_b32tab[c2 >> 12], # bits 16 - 20 (1 - 5)
_b32tab[(c2 >> 7) & 0x1f], # bits 21 - 25 (6 - 10)
_b32tab[(c2 >> 2) & 0x1f], # bits 26 - 30 (11 - 15)
_b32tab[(c2 >> 7) & 0x1F], # bits 21 - 25 (6 - 10)
_b32tab[(c2 >> 2) & 0x1F], # bits 26 - 30 (11 - 15)
_b32tab[c3 >> 5], # bits 31 - 35 (1 - 5)
_b32tab[c3 & 0x1f], # bits 36 - 40 (1 - 5)
_b32tab[c3 & 0x1F], # bits 36 - 40 (1 - 5)
]
)
# Adjust for any leftover partial quanta
Expand Down
4 changes: 2 additions & 2 deletions src/trezor/crypto/bech32.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

def bech32_polymod(values):
"""Internal function that computes the Bech32 checksum."""
generator = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3]
generator = [0x3B6A57B2, 0x26508E6D, 0x1EA119FA, 0x3D4233DD, 0x2A1462B3]
chk = 1
for value in values:
top = chk >> 25
chk = (chk & 0x1ffffff) << 5 ^ value
chk = (chk & 0x1FFFFFF) << 5 ^ value
for i in range(5):
chk ^= generator[i] if ((top >> i) & 1) else 0
return chk
Expand Down
8 changes: 4 additions & 4 deletions src/trezor/crypto/cashaddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@


def cashaddr_polymod(values):
generator = [0x98f2bc8e61, 0x79b76d99e2, 0xf33e5fb3c4, 0xae2eabe2a8, 0x1e4f43e470]
generator = [0x98F2BC8E61, 0x79B76D99E2, 0xF33E5FB3C4, 0xAE2EABE2A8, 0x1E4F43E470]
chk = 1
for value in values:
top = chk >> 35
chk = ((chk & 0x07ffffffff) << 5) ^ value
chk = ((chk & 0x07FFFFFFFF) << 5) ^ value
for i in range(5):
chk ^= generator[i] if (top & (1 << i)) else 0
return chk ^ 1


def prefix_expand(prefix):
return [ord(x) & 0x1f for x in prefix] + [0]
return [ord(x) & 0x1F for x in prefix] + [0]


def calculate_checksum(prefix, payload):
poly = cashaddr_polymod(prefix_expand(prefix) + payload + [0, 0, 0, 0, 0, 0, 0, 0])
out = list()
for i in range(8):
out.append((poly >> 5 * (7 - i)) & 0x1f)
out.append((poly >> 5 * (7 - i)) & 0x1F)
return out


Expand Down
6 changes: 3 additions & 3 deletions src/trezor/crypto/rlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def encode(data, include_length=True) -> bytes:


def field_length(length: int, first_byte: bytearray) -> int:
if length == 1 and first_byte[0] <= 0x7f:
if length == 1 and first_byte[0] <= 0x7F:
return 1
elif length <= 55:
return 1 + length
elif length <= 0xff:
elif length <= 0xFF:
return 2 + length
elif length <= 0xffff:
elif length <= 0xFFFF:
return 3 + length
return 4 + length

0 comments on commit 8aa29ae

Please sign in to comment.