Message digests as a service (Effect's effect/crypto/Digest)::
digest = yield from Digest()
hex_text = yield from digest.digest_hex(sha256, data)The algorithms are values: md5, sha1, sha256, sha384,
sha512. layer_web_crypto runs the SHA family on the WebCrypto
reference's subtle and MD5 in the process (hashlib), so MD5 works
without subtle. MD5 and SHA-1 are for existing protocols only.
Values#
| Attribute | Type | Description |
|---|---|---|
md5 | Algorithm | |
sha1 | Algorithm | |
sha256 | Algorithm | |
sha384 | Algorithm | |
sha512 | Algorithm | |
layer_web_crypto | Layer[Digest] | Digests on the |
Types#
| Type | Definition | Description |
|---|---|---|
Name | type Name = Literal['MD5', 'SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'] |
Classes#
Functions#
name_suffix#
name_suffix(hash) -> str"Sha256" for SHA-256, as the algorithm names use it.
| Parameter | Type | Description |
|---|---|---|
hash | Algorithm |
Returns str
def name_suffix(hash: Algorithm) -> str:
"""``"Sha256"`` for SHA-256, as the algorithm names use it."""
return hash.name[0] + hash.name[1:].lower().replace("-", "")web_crypto_digest#
web_crypto_digest(crypto, algorithm, data) -> Effect[bytes]algorithm's digest of data: its implementation, or
crypto.subtle (dying when there is none).
| Parameter | Type | Description |
|---|---|---|
crypto | Crypto | None | |
algorithm | Algorithm | |
data | Binary |
Returns Effect[bytes]
def web_crypto_digest(crypto: Crypto | None, algorithm: Algorithm, data: Binary) -> Effect[bytes]:
"""``algorithm``'s digest of ``data``: its ``implementation``, or
``crypto.subtle`` (dying when there is none)."""
implementation = algorithm.implementation
if implementation is not None:
return sync(lambda: implementation(bytes(data)))
def go() -> Effect[bytes]:
subtle = None if crypto is None else crypto.subtle
if subtle is None:
return die(_web.subtle_unavailable())
return sync(lambda: bytes(subtle.digest(algorithm.name, bytes(data))))
return suspend(go)