1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

embed: use correct string constructors

Reflects micropython commit 4601759bf59e16b860a3f082e9aa4ea78356bf92
This commit is contained in:
Jan Pochyla 2018-06-13 15:26:48 +02:00 committed by Pavol Rusnak
parent 62cc3cb283
commit edcc96ee09
4 changed files with 12 additions and 12 deletions

View File

@ -191,7 +191,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_derive_path_obj, mod_tr
STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public, uint32_t version) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
char xpub[XPUB_MAXLEN];
char xpub[XPUB_MAXLEN] = {0};
int written;
if (use_public) {
hdnode_fill_public_key(&o->hdnode);
@ -202,7 +202,7 @@ STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public, uint32_
if (written <= 0) {
mp_raise_ValueError("Failed to serialize");
}
return mp_obj_new_str(xpub, written - 1, false); // written includes 0 at the end
return mp_obj_new_str_copy(&mp_type_str, (const uint8_t *)xpub, written - 1); // written includes 0 at the end
}
/// def serialize_public(self, version: int) -> str:
@ -309,9 +309,9 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_address(mp_obj_t self, mp_obj_t version)
uint32_t v = trezor_obj_get_uint(version);
char address[ADDRESS_MAXLEN];
char address[ADDRESS_MAXLEN] = {0};
hdnode_get_address(&o->hdnode, v, address, ADDRESS_MAXLEN);
return mp_obj_new_str(address, strlen(address), false);
return mp_obj_new_str_copy(&mp_type_str, (const uint8_t *)address, strlen(address));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_address_obj, mod_trezorcrypto_HDNode_address);
@ -324,11 +324,11 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_nem_address(mp_obj_t self, mp_obj_t netw
uint8_t n = trezor_obj_get_uint8(network);
char address[NEM_ADDRESS_SIZE + 1]; // + 1 for the 0 byte
char address[NEM_ADDRESS_SIZE + 1] = {0}; // + 1 for the 0 byte
if (!hdnode_get_nem_address(&o->hdnode, n, address)) {
mp_raise_ValueError("Failed to compute a NEM address");
}
return mp_obj_new_str_of_type(&mp_type_str, (const uint8_t *)address, strlen(address));
return mp_obj_new_str_copy(&mp_type_str, (const uint8_t *)address, strlen(address));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_HDNode_nem_address_obj, mod_trezorcrypto_HDNode_nem_address);

View File

@ -34,7 +34,7 @@ STATIC mp_obj_t mod_trezorcrypto_bip39_find_word(mp_obj_t prefix)
}
for (const char * const *w = mnemonic_wordlist(); *w != 0; w++) {
if (strncmp(*w, pfx.buf, pfx.len) == 0) {
return mp_obj_new_str(*w, strlen(*w), false);
return mp_obj_new_str(*w, strlen(*w));
}
}
return mp_const_none;
@ -78,7 +78,7 @@ STATIC mp_obj_t mod_trezorcrypto_bip39_generate(mp_obj_t strength) {
mp_raise_ValueError("Invalid bit strength (only 128, 160, 192, 224 and 256 values are allowed)");
}
const char *mnemo = mnemonic_generate(bits);
return mp_obj_new_str(mnemo, strlen(mnemo), false);
return mp_obj_new_str_copy(&mp_type_str, (const uint8_t *)mnemo, strlen(mnemo));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_generate_obj, mod_trezorcrypto_bip39_generate);
@ -93,7 +93,7 @@ STATIC mp_obj_t mod_trezorcrypto_bip39_from_data(mp_obj_t data) {
mp_raise_ValueError("Invalid data length (only 16, 20, 24, 28 and 32 bytes are allowed)");
}
const char *mnemo = mnemonic_from_data(bin.buf, bin.len);
return mp_obj_new_str(mnemo, strlen(mnemo), false);
return mp_obj_new_str_copy(&mp_type_str, (const uint8_t *)mnemo, strlen(mnemo));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip39_from_data_obj, mod_trezorcrypto_bip39_from_data);

View File

@ -125,7 +125,7 @@ STATIC mp_obj_t mod_trezorutils_symbol(mp_obj_t name) {
if (0 == strncmp(str.buf, "GITREV", str.len)) {
#define XSTR(s) STR(s)
#define STR(s) #s
return mp_obj_new_str(XSTR(GITREV), strlen(XSTR(GITREV)), false);
return mp_obj_new_str(XSTR(GITREV), strlen(XSTR(GITREV)));
}
if (0 == strncmp(str.buf, "VERSION_MAJOR", str.len)) {
return mp_obj_new_int(VERSION_MAJOR);
@ -151,7 +151,7 @@ STATIC mp_obj_t mod_trezorutils_model(void) {
#elif defined TREZOR_MODEL_EMU
model = "EMU";
#endif
return model ? mp_obj_new_str(model, strlen(model), false) : mp_const_none;
return model ? mp_obj_new_str(model, strlen(model)) : mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_model_obj, mod_trezorutils_model);

View File

@ -537,7 +537,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
return usage(argv);
}
mp_obj_t import_args[4];
import_args[0] = mp_obj_new_str(argv[a + 1], strlen(argv[a + 1]), false);
import_args[0] = mp_obj_new_str(argv[a + 1], strlen(argv[a + 1]));
import_args[1] = import_args[2] = mp_const_none;
// Ask __import__ to handle imported module specially - set its __name__
// to __main__, and also return this leaf module, not top-level package