Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cardano.Crypto.Hash.Class
Description
Abstract hashing functionality.
Synopsis
- class (KnownNat (SizeHash h), Typeable h) => HashAlgorithm h where
- type SizeHash h :: Nat
- hashAlgorithmName :: proxy h -> String
- digest :: proxy h -> ByteString -> ByteString
- sizeHash :: forall h proxy. HashAlgorithm h => proxy h -> Word
- data ByteString
- newtype Hash h a = UnsafeHash ShortByteString
- hashWith :: forall h a. HashAlgorithm h => (a -> ByteString) -> a -> Hash h a
- hashWithSerialiser :: forall h a. HashAlgorithm h => (a -> Encoding) -> a -> Hash h a
- castHash :: Hash h a -> Hash h b
- hashToBytes :: Hash h a -> ByteString
- hashFromBytes :: forall h a. HashAlgorithm h => ByteString -> Maybe (Hash h a)
- hashToBytesShort :: Hash h a -> ShortByteString
- hashFromBytesShort :: forall h a. HashAlgorithm h => ShortByteString -> Maybe (Hash h a)
- hashToBytesAsHex :: Hash h a -> ByteString
- hashFromBytesAsHex :: HashAlgorithm h => ByteString -> Maybe (Hash h a)
- hashToTextAsHex :: Hash h a -> Text
- hashFromTextAsHex :: HashAlgorithm h => Text -> Maybe (Hash h a)
- hashToStringAsHex :: Hash h a -> String
- hashFromStringAsHex :: HashAlgorithm h => String -> Maybe (Hash h a)
- xor :: Hash h a -> Hash h a -> Hash h a
- hash :: forall h a. (HashAlgorithm h, ToCBOR a) => a -> Hash h a
- fromHash :: Hash h a -> Natural
- hashRaw :: forall h a. HashAlgorithm h => (a -> ByteString) -> a -> Hash h a
- getHash :: Hash h a -> ByteString
- getHashBytesAsHex :: Hash h a -> ByteString
Documentation
class (KnownNat (SizeHash h), Typeable h) => HashAlgorithm h where Source #
Methods
hashAlgorithmName :: proxy h -> String Source #
digest :: proxy h -> ByteString -> ByteString Source #
Instances
sizeHash :: forall h proxy. HashAlgorithm h => proxy h -> Word Source #
The size in bytes of the output of digest
data ByteString #
A space-efficient representation of a Word8
vector, supporting many
efficient operations.
A ByteString
contains 8-bit bytes, or by using the operations from
Data.ByteString.Char8 it can be interpreted as containing 8-bit
characters.
Instances
Constructors
UnsafeHash ShortByteString |
Instances
Core operations
hashWith :: forall h a. HashAlgorithm h => (a -> ByteString) -> a -> Hash h a Source #
Hash the given value, using a serialisation function to turn it into bytes.
hashWithSerialiser :: forall h a. HashAlgorithm h => (a -> Encoding) -> a -> Hash h a Source #
A variation on hashWith
, but specially for CBOR encodings.
Conversions
castHash :: Hash h a -> Hash h b Source #
Cast the type of the hashed data.
The Hash
type has a phantom type parameter to indicate what type the
hash is of. It is sometimes necessary to fake this and hash a value of one
type and use it where as hash of a different type is expected.
hashToBytes :: Hash h a -> ByteString Source #
The representation of the hash as bytes.
hashFromBytes :: forall h a. HashAlgorithm h => ByteString -> Maybe (Hash h a) Source #
Make a hash from it bytes representation.
It must be a a bytestring of the correct length, as given by sizeHash
.
hashToBytesShort :: Hash h a -> ShortByteString Source #
The representation of the hash as bytes, as a ShortByteString
.
hashFromBytesShort :: forall h a. HashAlgorithm h => ShortByteString -> Maybe (Hash h a) Source #
Make a hash from it bytes representation, as a ShortByteString
.
It must be a a bytestring of the correct length, as given by sizeHash
.
Rendering and parsing
hashToBytesAsHex :: Hash h a -> ByteString Source #
Convert the hash to hex encoding, as ByteString
.
hashFromBytesAsHex :: HashAlgorithm h => ByteString -> Maybe (Hash h a) Source #
Make a hash from hex-encoded ByteString
representation.
This can fail for the same reason as hashFromBytes
, or because the input
is invalid hex. The whole byte string must be valid hex, not just a prefix.
hashFromTextAsHex :: HashAlgorithm h => Text -> Maybe (Hash h a) Source #
Make a hash from hex-encoded Text
representation.
This can fail for the same reason as hashFromBytes
, or because the input
is invalid hex. The whole byte string must be valid hex, not just a prefix.
hashFromStringAsHex :: HashAlgorithm h => String -> Maybe (Hash h a) Source #
Make a hash from hex-encoded String
representation.
This can fail for the same reason as hashFromBytes
, or because the input
is invalid hex. The whole byte string must be valid hex, not just a prefix.
Other operations
xor :: Hash h a -> Hash h a -> Hash h a Source #
XOR two hashes together TODO: fully deprecate this, or rename it and make it efficient.
Deprecated
hash :: forall h a. (HashAlgorithm h, ToCBOR a) => a -> Hash h a Source #
Deprecated: Use hashWith or hashWithSerialiser
hashRaw :: forall h a. HashAlgorithm h => (a -> ByteString) -> a -> Hash h a Source #
Deprecated: Use hashWith
getHash :: Hash h a -> ByteString Source #
Deprecated: Use hashToBytes
getHashBytesAsHex :: Hash h a -> ByteString Source #
Deprecated: Use hashToBytesAsHex