diff --git a/embed/extmod/trezorobj.h b/embed/extmod/trezorobj.h index 2bd3a2fe97..76ff4d4c5d 100644 --- a/embed/extmod/trezorobj.h +++ b/embed/extmod/trezorobj.h @@ -69,4 +69,12 @@ static inline mp_uint_t trezor_obj_get_uint(mp_obj_t obj) { } } +static inline uint8_t trezor_obj_get_uint8(mp_obj_t obj) { + mp_uint_t u = trezor_obj_get_uint(obj); + if (u > 0xFF) { + mp_raise_msg(&mp_type_OverflowError, "value does not fit into byte type"); + } + return u; +} + #endif