Skip to content

Commit 6630354

Browse files
Jongydpgeorge
authored andcommitted
extmod/moduhashlib: Allow to disable the sha256 class.
Via the config value MICROPY_PY_UHASHLIB_SHA256. Default to enabled to keep backwards compatibility. Also add default value for the sha1 class, to at least document its existence.
1 parent 38682d4 commit 6630354

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

extmod/moduhashlib.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
#if MICROPY_PY_UHASHLIB
3333

34+
#if MICROPY_PY_UHASHLIB_SHA256
3435
#include "crypto-algorithms/sha256.h"
36+
#endif
3537

3638
#if MICROPY_PY_UHASHLIB_SHA1
3739

@@ -50,6 +52,7 @@ typedef struct _mp_obj_hash_t {
5052
char state[0];
5153
} mp_obj_hash_t;
5254

55+
#if MICROPY_PY_UHASHLIB_SHA256
5356
STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);
5457

5558
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
@@ -94,6 +97,7 @@ STATIC const mp_obj_type_t uhashlib_sha256_type = {
9497
.make_new = uhashlib_sha256_make_new,
9598
.locals_dict = (void*)&uhashlib_sha256_locals_dict,
9699
};
100+
#endif
97101

98102
#if MICROPY_PY_UHASHLIB_SHA1
99103
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg);
@@ -177,7 +181,9 @@ STATIC const mp_obj_type_t uhashlib_sha1_type = {
177181

178182
STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = {
179183
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uhashlib) },
184+
#if MICROPY_PY_UHASHLIB_SHA256
180185
{ MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&uhashlib_sha256_type) },
186+
#endif
181187
#if MICROPY_PY_UHASHLIB_SHA1
182188
{ MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&uhashlib_sha1_type) },
183189
#endif
@@ -190,6 +196,8 @@ const mp_obj_module_t mp_module_uhashlib = {
190196
.globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals,
191197
};
192198

199+
#if MICROPY_PY_UHASHLIB_SHA256
193200
#include "crypto-algorithms/sha256.c"
201+
#endif
194202

195203
#endif //MICROPY_PY_UHASHLIB

py/mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,14 @@ typedef double mp_float_t;
11551155
#define MICROPY_PY_UHASHLIB (0)
11561156
#endif
11571157

1158+
#ifndef MICROPY_PY_UHASHLIB_SHA1
1159+
#define MICROPY_PY_UHASHLIB_SHA1 (0)
1160+
#endif
1161+
1162+
#ifndef MICROPY_PY_UHASHLIB_SHA256
1163+
#define MICROPY_PY_UHASHLIB_SHA256 (1)
1164+
#endif
1165+
11581166
#ifndef MICROPY_PY_UBINASCII
11591167
#define MICROPY_PY_UBINASCII (0)
11601168
#endif

0 commit comments

Comments
 (0)