Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data BaseEncoding
- 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 ValidAlgo a => NamedAlgo (a :: HashAlgorithm) where
- data SomeNamedDigest = forall a.NamedAlgo a => SomeDigest (Digest a)
- mkNamedDigest :: Text -> Text -> Either String SomeNamedDigest
- hash :: forall a. ValidAlgo a => ByteString -> Digest a
- hashLazy :: forall a. ValidAlgo a => ByteString -> Digest a
- encodeInBase :: BaseEncoding -> Digest a -> Text
- decodeBase :: BaseEncoding -> Text -> Either String (Digest a)
- truncateDigest :: forall n a. KnownNat n => Digest a -> Digest ('Truncated n a)
Documentation
data BaseEncoding Source #
Constructors to indicate the base encodings
data HashAlgorithm Source #
The universe of supported hash algorithms.
Currently only intended for use at the type level.
MD5 | |
SHA1 | |
SHA256 | |
SHA512 | |
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 'SHA512 Source # | Uses Crypto.Hash.SHA512 from cryptohash-sha512. |
(ValidAlgo a, KnownNat n) => ValidAlgo ('Truncated n a) Source # | Reuses the underlying |
class ValidAlgo a => NamedAlgo (a :: HashAlgorithm) where Source #
A HashAlgorithm
with a canonical name, for serialization
purposes (e.g. SRI hashes)
data SomeNamedDigest Source #
A digest whose NamedAlgo
is not known at compile time.
forall a.NamedAlgo a => SomeDigest (Digest a) |
Instances
Show SomeNamedDigest Source # | |
Defined in System.Nix.Internal.Hash showsPrec :: Int -> SomeNamedDigest -> ShowS # show :: SomeNamedDigest -> String # showList :: [SomeNamedDigest] -> ShowS # |
mkNamedDigest :: Text -> Text -> Either String SomeNamedDigest Source #
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.
encodeInBase :: BaseEncoding -> Digest a -> Text Source #
Take BaseEncoding type of the output -> take the Digeest as input -> encode Digest
decodeBase :: BaseEncoding -> Text -> Either String (Digest a) Source #
Take BaseEncoding type of the input -> take the input itself -> decodeBase into Digest
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
.