Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data HashAlgorithm
- newtype Digest (a :: HashAlgorithm) = Digest ByteString
- class ValidAlgo (a :: HashAlgorithm) where
- type AlgoCtx a
- initialize :: AlgoCtx a
- update :: AlgoCtx a -> ByteString -> AlgoCtx a
- finalize :: AlgoCtx a -> Digest a
- class NamedAlgo (a :: HashAlgorithm) where
- hash :: forall a. ValidAlgo a => ByteString -> Digest a
- hashLazy :: forall a. ValidAlgo a => ByteString -> Digest a
- encodeBase32 :: Digest a -> Text
- encodeBase16 :: Digest a -> Text
- truncateDigest :: forall n a. KnownNat n => Digest a -> Digest (Truncated n a)
Documentation
data HashAlgorithm Source #
The universe of supported hash algorithms.
Currently only intended for use at the type level.
MD5 | |
SHA1 | |
SHA256 | |
Truncated Nat HashAlgorithm | The hash algorithm obtained by truncating the result of the
input |
newtype Digest (a :: HashAlgorithm) Source #
The result of running a HashAlgorithm
.
class ValidAlgo (a :: HashAlgorithm) where Source #
The primitive interface for incremental hashing for a given
HashAlgorithm
. Every HashAlgorithm
should have an instance.
initialize :: AlgoCtx a Source #
Start building a new hash.
update :: AlgoCtx a -> ByteString -> AlgoCtx a Source #
Append a ByteString
to the overall contents to be hashed.
finalize :: AlgoCtx a -> Digest a Source #
Finish hashing and generate the output.
Instances
ValidAlgo MD5 Source # | Uses Crypto.Hash.MD5 from cryptohash-md5. |
ValidAlgo SHA1 Source # | Uses Crypto.Hash.SHA1 from cryptohash-sha1. |
ValidAlgo SHA256 Source # | Uses Crypto.Hash.SHA256 from cryptohash-sha256. |
(ValidAlgo a, KnownNat n) => ValidAlgo (Truncated n a) Source # | Reuses the underlying |
class NamedAlgo (a :: HashAlgorithm) where Source #
A HashAlgorithm
with a canonical name, for serialization
purposes (e.g. SRI hashes)
hash :: forall a. ValidAlgo a => ByteString -> Digest a Source #
Hash an entire (strict) ByteString
as a single call.
For example: > let d = hash "Hello, sha-256!" :: Digest SHA256 or > :set -XTypeApplications > let d = hash @SHA256 "Hello, sha-256!"
hashLazy :: forall a. ValidAlgo a => ByteString -> Digest a Source #
Hash an entire (lazy) ByteString
as a single call.
Use is the same as for hash
. This runs in constant space, but
forces the entire bytestring.
truncateDigest :: forall n a. KnownNat n => Digest a -> Digest (Truncated n a) Source #
Bytewise truncation of a Digest
.
When truncation length is greater than the length of the bytestring
but less than twice the bytestring length, truncation splits the
bytestring into a head part (truncation length) and tail part
(leftover part), right-pads the leftovers with 0 to the truncation
length, and combines the two strings bytewise with xor
.