extmod/moduhashlib: allow multiple calls to digest() method
Some checks failed
Check code formatting / build (push) Has been cancelled
Check code size / build (push) Has been cancelled
Check commit message formatting / build (push) Has been cancelled
cc3200 port / build (push) Has been cancelled
esp32 port / idf3_build (push) Has been cancelled
esp32 port / idf4_build (push) Has been cancelled
esp8266 port / build (push) Has been cancelled
nrf port / build (push) Has been cancelled
powerpc port / build (push) Has been cancelled
qemu-arm port / build_and_test (push) Has been cancelled
rp2 port / build (push) Has been cancelled
samd port / build (push) Has been cancelled
stm32 port / build_pyb (push) Has been cancelled
stm32 port / build_nucleo (push) Has been cancelled
teensy port / build (push) Has been cancelled
unix port / minimal (push) Has been cancelled
unix port / reproducible (push) Has been cancelled
unix port / standard (push) Has been cancelled
unix port / coverage (push) Has been cancelled
unix port / coverage_32bit (push) Has been cancelled
unix port / nanbox (push) Has been cancelled
unix port / float (push) Has been cancelled
unix port / stackless_clang (push) Has been cancelled
unix port / float_clang (push) Has been cancelled
unix port / settrace (push) Has been cancelled
unix port / settrace_stackless (push) Has been cancelled
unix port / macos (push) Has been cancelled
windows port / build (push) Has been cancelled
zephyr port / build (push) Has been cancelled
Some checks failed
Check code formatting / build (push) Has been cancelled
Check code size / build (push) Has been cancelled
Check commit message formatting / build (push) Has been cancelled
cc3200 port / build (push) Has been cancelled
esp32 port / idf3_build (push) Has been cancelled
esp32 port / idf4_build (push) Has been cancelled
esp8266 port / build (push) Has been cancelled
nrf port / build (push) Has been cancelled
powerpc port / build (push) Has been cancelled
qemu-arm port / build_and_test (push) Has been cancelled
rp2 port / build (push) Has been cancelled
samd port / build (push) Has been cancelled
stm32 port / build_pyb (push) Has been cancelled
stm32 port / build_nucleo (push) Has been cancelled
teensy port / build (push) Has been cancelled
unix port / minimal (push) Has been cancelled
unix port / reproducible (push) Has been cancelled
unix port / standard (push) Has been cancelled
unix port / coverage (push) Has been cancelled
unix port / coverage_32bit (push) Has been cancelled
unix port / nanbox (push) Has been cancelled
unix port / float (push) Has been cancelled
unix port / stackless_clang (push) Has been cancelled
unix port / float_clang (push) Has been cancelled
unix port / settrace (push) Has been cancelled
unix port / settrace_stackless (push) Has been cancelled
unix port / macos (push) Has been cancelled
windows port / build (push) Has been cancelled
zephyr port / build (push) Has been cancelled
This commit is contained in:
parent
0f1973fb68
commit
cfb6444a79
@ -98,7 +98,8 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, 32);
|
||||
mbedtls_sha256_finish_ret((mbedtls_sha256_context *)&self->state, (unsigned char *)vstr.buf);
|
||||
mbedtls_sha256_context tmp_ctx = *(mbedtls_sha256_context *)self->state;
|
||||
mbedtls_sha256_finish_ret(&tmp_ctx, (unsigned char *)vstr.buf);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
|
||||
@ -129,7 +130,8 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
|
||||
sha256_final((CRYAL_SHA256_CTX *)self->state, (byte *)vstr.buf);
|
||||
CRYAL_SHA256_CTX tmp_ctx = *(CRYAL_SHA256_CTX *)self->state;
|
||||
sha256_final(&tmp_ctx, (byte *)vstr.buf);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -26,13 +26,13 @@ print(hashlib.sha256(b"\xff" * 64).digest())
|
||||
# 56 bytes is a boundary case in the algorithm
|
||||
print(hashlib.sha256(b"\xff" * 56).digest())
|
||||
|
||||
# TODO: running .digest() several times in row is not supported()
|
||||
# h = hashlib.sha256(b'123')
|
||||
# print(h.digest())
|
||||
# print(h.digest())
|
||||
# running .digest() several times in row is now supported
|
||||
h = hashlib.sha256(b'123')
|
||||
print(h.digest())
|
||||
print(h.digest())
|
||||
|
||||
# TODO: partial digests are not supported
|
||||
# h = hashlib.sha256(b'123')
|
||||
# print(h.digest())
|
||||
# h.update(b'456')
|
||||
# print(h.digest())
|
||||
# partial digests are supported
|
||||
h = hashlib.sha256(b'123')
|
||||
print(h.digest())
|
||||
h.update(b'456')
|
||||
print(h.digest())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user