Skip to content

Commit aba36e4

Browse files
committed
aesio: use bufinfo rather than mp_str_bytes
In order to accept both `bytes` objects and `bytearray` objects, use a `bufinfo` construct to retrieve the data rather than `mp_obj_str_get_data()`. Signed-off-by: Sean Cross <[email protected]>
1 parent 0f55f58 commit aba36e4

File tree

1 file changed

+9
-10
lines changed
  • shared-bindings/aesio

1 file changed

+9
-10
lines changed

shared-bindings/aesio/aes.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ STATIC mp_obj_t aesio_aes_make_new(const mp_obj_type_t *type, size_t n_args,
103103
STATIC mp_obj_t aesio_aes_rekey(size_t n_args, const mp_obj_t *pos_args) {
104104
aesio_aes_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
105105

106-
size_t key_length = 0;
107-
const uint8_t *key =
108-
(const uint8_t *)mp_obj_str_get_data(pos_args[1], &key_length);
106+
mp_buffer_info_t bufinfo;
107+
mp_get_buffer_raise(pos_args[1], &bufinfo, MP_BUFFER_READ);
108+
const uint8_t *key = bufinfo.buf;
109+
size_t key_length = bufinfo.len;
109110
if (key == NULL) {
110111
mp_raise_ValueError(translate("No key was specified"));
111112
}
@@ -115,8 +116,9 @@ STATIC mp_obj_t aesio_aes_rekey(size_t n_args, const mp_obj_t *pos_args) {
115116

116117
const uint8_t *iv = NULL;
117118
if (n_args > 2) {
118-
size_t iv_length = 0;
119-
iv = (const uint8_t *)mp_obj_str_get_data(pos_args[2], &iv_length);
119+
mp_get_buffer_raise(pos_args[2], &bufinfo, MP_BUFFER_READ);
120+
size_t iv_length = bufinfo.len;
121+
iv = (const uint8_t *)bufinfo.buf;
120122
if (iv_length != AES_BLOCKLEN) {
121123
mp_raise_TypeError_varg(translate("IV must be %d bytes long"),
122124
AES_BLOCKLEN);
@@ -246,11 +248,8 @@ MP_DEFINE_CONST_FUN_OBJ_2(aesio_aes_set_mode_obj, aesio_aes_set_mode);
246248

247249
const mp_obj_property_t aesio_aes_mode_obj = {
248250
.base.type = &mp_type_property,
249-
.proxy = {
250-
(mp_obj_t)&aesio_aes_get_mode_obj,
251-
(mp_obj_t)&aesio_aes_set_mode_obj,
252-
(mp_obj_t)&mp_const_none_obj
253-
},
251+
.proxy = {(mp_obj_t)&aesio_aes_get_mode_obj,
252+
(mp_obj_t)&aesio_aes_set_mode_obj, (mp_obj_t)&mp_const_none_obj},
254253
};
255254

256255
STATIC const mp_rom_map_elem_t aesio_locals_dict_table[] = {

0 commit comments

Comments
 (0)