feedback
This commit is contained in:
parent
b7de08ba0b
commit
d1d33c4bce
2 changed files with 6 additions and 5 deletions
|
@ -1063,6 +1063,9 @@ async def asyncify_for_loop(gen, ticks_per_sleep: int = 1000):
|
||||||
await async_sleep(0)
|
await async_sleep(0)
|
||||||
|
|
||||||
|
|
||||||
|
_SHA256_DIGEST_STATE_SIZE = 120
|
||||||
|
|
||||||
|
|
||||||
class ResumableSHA256:
|
class ResumableSHA256:
|
||||||
__slots__ = ['_hasher']
|
__slots__ = ['_hasher']
|
||||||
|
|
||||||
|
@ -1071,6 +1074,8 @@ class ResumableSHA256:
|
||||||
if state is not None:
|
if state is not None:
|
||||||
ctx = self._get_evp_md_ctx()
|
ctx = self._get_evp_md_ctx()
|
||||||
ctx_size = ctx.digest.contents.ctx_size
|
ctx_size = ctx.digest.contents.ctx_size
|
||||||
|
if len(state) != _SHA256_DIGEST_STATE_SIZE != ctx_size:
|
||||||
|
raise Exception(f'invalid sha256 digester state, got {len(state)} bytes')
|
||||||
memmove(ctx.md_data, state, ctx_size)
|
memmove(ctx.md_data, state, ctx_size)
|
||||||
|
|
||||||
def _get_evp_md_ctx(self):
|
def _get_evp_md_ctx(self):
|
||||||
|
@ -1086,7 +1091,7 @@ class ResumableSHA256:
|
||||||
hasher_state = ctx.md_data[:ctx_size]
|
hasher_state = ctx.md_data[:ctx_size]
|
||||||
return hasher_state
|
return hasher_state
|
||||||
|
|
||||||
def copy(self):
|
def __copy__(self):
|
||||||
return ResumableSHA256(self.get_state())
|
return ResumableSHA256(self.get_state())
|
||||||
|
|
||||||
def update(self, data: bytes):
|
def update(self, data: bytes):
|
||||||
|
@ -1094,6 +1099,3 @@ class ResumableSHA256:
|
||||||
|
|
||||||
def digest(self):
|
def digest(self):
|
||||||
return self._hasher.digest()
|
return self._hasher.digest()
|
||||||
|
|
||||||
def hexdigest(self):
|
|
||||||
return self.digest().hex()
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import rehash
|
|
||||||
import time
|
import time
|
||||||
import asyncio
|
import asyncio
|
||||||
import typing
|
import typing
|
||||||
|
|
Loading…
Reference in a new issue