Skip to content

Commit

Permalink
extmod/moduhashlib: Allow to disable the sha256 class.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jongy authored and dpgeorge committed Jun 12, 2018
1 parent 38682d4 commit 6630354
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions extmod/moduhashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

#if MICROPY_PY_UHASHLIB

#if MICROPY_PY_UHASHLIB_SHA256
#include "crypto-algorithms/sha256.h"
#endif

#if MICROPY_PY_UHASHLIB_SHA1

Expand All @@ -50,6 +52,7 @@ typedef struct _mp_obj_hash_t {
char state[0];
} 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_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
Expand Down Expand Up @@ -94,6 +97,7 @@ STATIC const mp_obj_type_t uhashlib_sha256_type = {
.make_new = uhashlib_sha256_make_new,
.locals_dict = (void*)&uhashlib_sha256_locals_dict,
};
#endif

#if MICROPY_PY_UHASHLIB_SHA1
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg);
Expand Down Expand Up @@ -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[] = {
{ 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) },
#endif
#if MICROPY_PY_UHASHLIB_SHA1
{ MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&uhashlib_sha1_type) },
#endif
Expand All @@ -190,6 +196,8 @@ const mp_obj_module_t mp_module_uhashlib = {
.globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals,
};

#if MICROPY_PY_UHASHLIB_SHA256
#include "crypto-algorithms/sha256.c"
#endif

#endif //MICROPY_PY_UHASHLIB
8 changes: 8 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,14 @@ typedef double mp_float_t;
#define MICROPY_PY_UHASHLIB (0)
#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
#define MICROPY_PY_UBINASCII (0)
#endif
Expand Down

0 comments on commit 6630354

Please sign in to comment.