8000 Merge pull request #94 from pycom/sigfox_private_key · daq-tools/pycom-micropython@bc2d085 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc2d085

Browse files
authored
Merge pull request pycom#94 from pycom/sigfox_private_key
protect sigfox private key
2 parents cfe72ee + 68c3374 commit bc2d085

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

esp32/mods/modpycom.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,16 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
850850

851851

852852
if (args[ARG_id].u_obj == mp_const_none && args[ARG_pac].u_obj == mp_const_none && args[ARG_public_key].u_obj == mp_const_none && args[ARG_private_key].u_obj == mp_const_none) {
853+
// query sigfox info
853854

854-
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(4, NULL));
855-
856-
t->items[ARG_id] = is_empty(id, sizeof(id)) ? mp_const_none:mp_obj_new_str((const char*)id, sizeof(id));
857-
t->items[ARG_pac] = is_empty(pac, sizeof(pac)) ? mp_const_none:mp_obj_new_str((const char*)pac, sizeof(pac));
858-
t->items[ARG_public_key] = is_empty(public_key, sizeof(public_key)) ? mp_const_none:mp_obj_new_str((const char*)public_key, sizeof(public_key));
859-
t->items[ARG_private_key] = is_empty(private_key, sizeof(private_key)) ? mp_const_none:mp_obj_new_str((const char*)private_key, sizeof(private_key));
860-
861-
return MP_OBJ_FROM_PTR(t);
862-
855+
if ( !is_empty(id, sizeof(id)) && !is_empty(pac, sizeof(pac)) && !is_empty(public_key, sizeof(public_key)) && !is_empty(private_key, sizeof(private_key)) ){
856+
// all configs valid
857+
return mp_const_true;
858+
} else {
859+
return mp_const_false;
860+
}
863861
} else {
862+
// write sigfox info
864863

865864
// temporary array to store even the longest value from id, pac, public_key and private_key
866865
uint8_t tmp_array[16];
@@ -892,7 +891,7 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
892891

893892
ret_val = config_set_sigfox_id(tmp_array);
894893
if (ret_val == false) {
895-
return mp_const_false;
894+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to write id"));
896895
}
897896
} else {
898897
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Use force option to overwrite existing id!"));
@@ -923,7 +922,7 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
923922

924923
ret_val = config_set_sigfox_pac(tmp_array);
925924
if (ret_val == false) {
926-
return mp_const_false;
925+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to write pac"));
927926
}
928927
} else {
929928
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Use force option to overwrite existing pac!"));
@@ -954,7 +953,7 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
954953

955954
ret_val = config_set_sigfox_public_key(tmp_array);
956955
if (ret_val == false) {
957-
return mp_const_false;
956+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to write public key"));
958957
}
959958
} else {
960959
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Use force option to overwrite existing public key!"));
@@ -986,15 +985,14 @@ STATIC mp_obj_t mod_pycom_sigfox_info (size_t n_args, const mp_obj_t *pos_args,
986985

987986
ret_val = config_set_sigfox_private_key(tmp_array);
988987
if (ret_val == false) {
989-
return mp_const_false;
988+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to write private key"));
990989
}
991990
} else {
992991
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Use force option to overwrite existing private key!"));
993992
}
994993
}
995994
return mp_const_true;
996995
}
997-
return mp_const_none;
998996
}
999997
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_pycom_sigfox_info_obj, 0, mod_pycom_sigfox_info);
1000998

0 commit comments

Comments
 (0)
0