Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Hashing capabilities.
Synopsis
- data AbstractHash algo a
- class HashAlgorithm a
- abstractHash ∷ (HashAlgorithm algo, EncCBOR a) ⇒ a → AbstractHash algo a
- unsafeAbstractHash ∷ HashAlgorithm algo ⇒ LByteString → AbstractHash algo a
- abstractHashFromDigest ∷ Digest algo → AbstractHash algo a
- abstractHashFromBytes ∷ ∀ algo a. HashAlgorithm algo ⇒ ByteString → Maybe (AbstractHash algo a)
- unsafeAbstractHashFromBytes ∷ ByteString → AbstractHash algo a
- abstractHashToBytes ∷ AbstractHash algo a → ByteString
- unsafeAbstractHashFromShort ∷ ShortByteString → AbstractHash algo a
- abstractHashToShort ∷ AbstractHash algo a → ShortByteString
- decodeAbstractHash ∷ HashAlgorithm algo ⇒ Text → Either Text (AbstractHash algo a)
- type Hash = AbstractHash Blake2b_256
- hash ∷ EncCBOR a ⇒ a → Hash a
- hashDecoded ∷ Decoded t ⇒ t → Hash (BaseType t)
- hashRaw ∷ ByteString → Hash Raw
- serializeCborHash ∷ EncCBOR a ⇒ a → Hash a
- hashFromBytes ∷ ByteString → Maybe (Hash a)
- unsafeHashFromBytes ∷ ByteString → Hash a
- hashToBytes ∷ AbstractHash algo a → ByteString
- decodeHash ∷ Text → Either Text (Hash a)
- hashHexF ∷ Format r (AbstractHash algo a → r)
- mediumHashF ∷ Format r (AbstractHash algo a → r)
- shortHashF ∷ Format r (AbstractHash algo a → r)
AbstractHash
type supporting different hash algorithms
data AbstractHash algo a Source #
Hash wrapper with phantom type for more type-safety
Made abstract in order to support different algorithms
Instances
class HashAlgorithm a Source #
Class representing hashing algorithms.
The interface presented here is update in place and lowlevel. the Hash module takes care of hidding the mutable interface properly.
hashBlockSize, hashDigestSize, hashInternalContextSize, hashInternalInit, hashInternalUpdate, hashInternalFinalize
Instances
Hashing
abstractHash ∷ (HashAlgorithm algo, EncCBOR a) ⇒ a → AbstractHash algo a Source #
Hash the EncCBOR
-serialised version of a value
Once this is no longer used outside this module it should be made private.
unsafeAbstractHash ∷ HashAlgorithm algo ⇒ LByteString → AbstractHash algo a Source #
Hash a lazy LByteString
You can choose the phantom type, hence the "unsafe".
Conversion
abstractHashFromDigest ∷ Digest algo → AbstractHash algo a Source #
Make an AbstractHash
from a Digest
for the same HashAlgorithm
.
abstractHashFromBytes ∷ ∀ algo a. HashAlgorithm algo ⇒ ByteString → Maybe (AbstractHash algo a) Source #
Make an AbstractHash
from the bytes representation of the hash. It will
fail if given the wrong number of bytes for the choice of HashAlgorithm
.
unsafeAbstractHashFromBytes ∷ ByteString → AbstractHash algo a Source #
Like abstractHashFromDigestBytes
but the number of bytes provided
must be correct for the choice of HashAlgorithm
.
abstractHashToBytes ∷ AbstractHash algo a → ByteString Source #
The bytes representation of the hash value.
unsafeAbstractHashFromShort ∷ ShortByteString → AbstractHash algo a Source #
The ShortByteString
representation of the hash value.
abstractHashToShort ∷ AbstractHash algo a → ShortByteString Source #
The ShortByteString
representation of the hash value.
Parsing and printing
decodeAbstractHash ∷ HashAlgorithm algo ⇒ Text → Either Text (AbstractHash algo a) Source #
Parses given hash in base16 form.
Standard Hash
type using Blake2b 256
type Hash = AbstractHash Blake2b_256 Source #
The type of our commonly used hash, Blake2b 256
Hashing
hash ∷ EncCBOR a ⇒ a → Hash a Source #
Deprecated: Use serializeCborHash or hash the annotation instead.
The hash of a value, serialised via EncCBOR
.
Conversion
hashFromBytes ∷ ByteString → Maybe (Hash a) Source #
Make a hash from it bytes representation. It must be a 32-byte bytestring. The size is checked.
unsafeHashFromBytes ∷ ByteString → Hash a Source #
Make a hash from a 32-byte bytestring. It must be exactly 32 bytes.
hashToBytes ∷ AbstractHash algo a → ByteString Source #
The bytes representation of the hash value.
Parsing and printing
mediumHashF ∷ Format r (AbstractHash algo a → r) Source #
shortHashF ∷ Format r (AbstractHash algo a → r) Source #