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.
This commit is contained in:
Yonatan Goldschmidt 2018-06-09 02:48:29 +03:00 committed by Damien George
parent 38682d4629
commit 6630354ffe
2 changed files with 16 additions and 0 deletions

View File

@ -31,7 +31,9 @@
#if MICROPY_PY_UHASHLIB #if MICROPY_PY_UHASHLIB
#if MICROPY_PY_UHASHLIB_SHA256
#include "crypto-algorithms/sha256.h" #include "crypto-algorithms/sha256.h"
#endif
#if MICROPY_PY_UHASHLIB_SHA1 #if MICROPY_PY_UHASHLIB_SHA1
@ -50,6 +52,7 @@ typedef struct _mp_obj_hash_t {
char state[0]; char state[0];
} mp_obj_hash_t; } mp_obj_hash_t;
#if MICROPY_PY_UHASHLIB_SHA256
STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);
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) { 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 = {
.make_new = uhashlib_sha256_make_new, .make_new = uhashlib_sha256_make_new,
.locals_dict = (void*)&uhashlib_sha256_locals_dict, .locals_dict = (void*)&uhashlib_sha256_locals_dict,
}; };
#endif
#if MICROPY_PY_UHASHLIB_SHA1 #if MICROPY_PY_UHASHLIB_SHA1
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); 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 = {
STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = { STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uhashlib) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uhashlib) },
#if MICROPY_PY_UHASHLIB_SHA256
{ MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&uhashlib_sha256_type) }, { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&uhashlib_sha256_type) },
#endif
#if MICROPY_PY_UHASHLIB_SHA1 #if MICROPY_PY_UHASHLIB_SHA1
{ MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&uhashlib_sha1_type) }, { MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&uhashlib_sha1_type) },
#endif #endif
@ -190,6 +196,8 @@ const mp_obj_module_t mp_module_uhashlib = {
.globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals, .globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals,
}; };
#if MICROPY_PY_UHASHLIB_SHA256
#include "crypto-algorithms/sha256.c" #include "crypto-algorithms/sha256.c"
#endif
#endif //MICROPY_PY_UHASHLIB #endif //MICROPY_PY_UHASHLIB

View File

@ -1155,6 +1155,14 @@ typedef double mp_float_t;
#define MICROPY_PY_UHASHLIB (0) #define MICROPY_PY_UHASHLIB (0)
#endif #endif
#ifndef MICROPY_PY_UHASHLIB_SHA1
#define MICROPY_PY_UHASHLIB_SHA1 (0)
#endif
#ifndef MICROPY_PY_UHASHLIB_SHA256
#define MICROPY_PY_UHASHLIB_SHA256 (1)
#endif
#ifndef MICROPY_PY_UBINASCII #ifndef MICROPY_PY_UBINASCII
#define MICROPY_PY_UBINASCII (0) #define MICROPY_PY_UBINASCII (0)
#endif #endif