summaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2018-05-06 12:28:36 -0500
committerJeff Epler <jepler@gmail.com>2018-05-06 12:31:54 -0500
commit005226ae548a45bde03a2b2400998185aa68495e (patch)
tree6d24c4a9437f8616ce8c9b4edefa8526e2714c11 /extmod
parentb2084d37d694df2803756375b62beb2b1ade8b80 (diff)
uhashlib: some functions should refuse unicode for python3 compatibility
.. this maybe should be subject to MICROPY_CPYTHON_COMPAT, except that is not defined in the main circuitpython ports so it would be a change that makes no difference.
Diffstat (limited to 'extmod')
-rw-r--r--extmod/moduhashlib.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c
index 3fad69247..7599b8496 100644
--- a/extmod/moduhashlib.c
+++ b/extmod/moduhashlib.c
@@ -36,6 +36,14 @@
#include "lib/axtls/crypto/crypto.h"
#endif
+static void check_not_unicode(const mp_obj_t arg) {
+#if MICROPY_CPYTHON_COMPAT
+ if (MP_OBJ_IS_STR(arg)) {
+ mp_raise_TypeError("a bytes-like object is required");
+ }
+#endif
+}
+
typedef struct _mp_obj_hash_t {
mp_obj_base_t base;
char state[0];
@@ -70,6 +78,7 @@ STATIC mp_obj_t sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
#endif
STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) {
+ check_not_unicode(arg);
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
@@ -80,6 +89,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(hash_update_obj, hash_update);
#if MICROPY_PY_UHASHLIB_SHA1
STATIC mp_obj_t sha1_update(mp_obj_t self_in, mp_obj_t arg) {
+ check_not_unicode(arg);
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);