mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-17 01:52:02 +00:00
core: throw exception classes instead of instances where possible
This commit is contained in:
parent
312224b7a3
commit
e3e2811f7a
@ -92,7 +92,7 @@ def _cbor_encode(value):
|
|||||||
else:
|
else:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
log.debug(__name__, "not implemented (encode): %s", type(value))
|
log.debug(__name__, "not implemented (encode): %s", type(value))
|
||||||
raise NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
def _read_length(cbor, aux):
|
def _read_length(cbor, aux):
|
||||||
@ -193,11 +193,11 @@ def _cbor_decode(cbor):
|
|||||||
elif fb_aux == _CBOR_BREAK:
|
elif fb_aux == _CBOR_BREAK:
|
||||||
return (cbor[0], cbor[1:])
|
return (cbor[0], cbor[1:])
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError
|
||||||
else:
|
else:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
log.debug(__name__, "not implemented (decode): %s", cbor[0])
|
log.debug(__name__, "not implemented (decode): %s", cbor[0])
|
||||||
raise NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class Tagged:
|
class Tagged:
|
||||||
@ -233,5 +233,5 @@ def encode(value):
|
|||||||
def decode(cbor: bytes):
|
def decode(cbor: bytes):
|
||||||
res, check = _cbor_decode(cbor)
|
res, check = _cbor_decode(cbor)
|
||||||
if not (check == b""):
|
if not (check == b""):
|
||||||
raise ValueError()
|
raise ValueError
|
||||||
return res
|
return res
|
||||||
|
@ -29,5 +29,5 @@ async def request_pin(
|
|||||||
else:
|
else:
|
||||||
result = await dialog
|
result = await dialog
|
||||||
if result is CANCELLED:
|
if result is CANCELLED:
|
||||||
raise PinCancelled()
|
raise PinCancelled
|
||||||
return result
|
return result
|
||||||
|
@ -298,7 +298,7 @@ class KeyVBase:
|
|||||||
return memcpy(buff, offset, self[self.idxize(idx)], 0, 32)
|
return memcpy(buff, offset, self[self.idxize(idx)], 0, 32)
|
||||||
|
|
||||||
def read(self, idx, buff, offset=0):
|
def read(self, idx, buff, offset=0):
|
||||||
raise ValueError()
|
raise ValueError
|
||||||
|
|
||||||
def slice(self, res, start, stop):
|
def slice(self, res, start, stop):
|
||||||
for i in range(start, stop):
|
for i in range(start, stop):
|
||||||
@ -583,7 +583,7 @@ class KeyVPowers(KeyVBase):
|
|||||||
elif item == prev + 1:
|
elif item == prev + 1:
|
||||||
return sc_mul(self.cur, self.cur, self.x)
|
return sc_mul(self.cur, self.cur, self.x)
|
||||||
else:
|
else:
|
||||||
IndexError("Only linear scan allowed")
|
raise IndexError("Only linear scan allowed")
|
||||||
|
|
||||||
|
|
||||||
class KeyVZtwo(KeyVBase):
|
class KeyVZtwo(KeyVBase):
|
||||||
@ -827,7 +827,7 @@ def vector_z_two(N, logN, M, zpow, twoN, zero_twos=None, dynamic=False, **kwargs
|
|||||||
if dynamic:
|
if dynamic:
|
||||||
return KeyVZtwo(N, logN, M, zpow, twoN, **kwargs)
|
return KeyVZtwo(N, logN, M, zpow, twoN, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
def hash_cache_mash(dst, hash_cache, *args):
|
def hash_cache_mash(dst, hash_cache, *args):
|
||||||
|
@ -56,7 +56,7 @@ def unimport_end(mods):
|
|||||||
def ensure(cond, msg=None):
|
def ensure(cond, msg=None):
|
||||||
if not cond:
|
if not cond:
|
||||||
if msg is None:
|
if msg is None:
|
||||||
raise AssertionError()
|
raise AssertionError
|
||||||
else:
|
else:
|
||||||
raise AssertionError(msg)
|
raise AssertionError(msg)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user