| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.Crypto.Blake2b
Description
BLAKE2b digests as immutable byte sequences. This general digest type does not distinguish payment, stake, or script hashes.
import qualified Cometa.Crypto.Blake2b as Blake2b import qualified Data.ByteString.Char8 as ByteString main :: IO () main = do result <- Blake2b.compute 32 (ByteString.pack "abc") print (Blake2b.toHex $ result)
Synopsis
- data Blake2bHash
- compute :: Int -> ByteString -> IO (Either Error Blake2bHash)
- fromBytes :: ByteString -> Either Error Blake2bHash
- fromHex :: Text -> Either Error Blake2bHash
- toBytes :: Blake2bHash -> ByteString
- toHex :: Blake2bHash -> Text
- encodeCbor :: Blake2bHash -> ByteString
- decodeCbor :: ByteString -> Either Error Blake2bHash
Documentation
data Blake2bHash Source #
A nonempty digest byte sequence. Equality compares bytes; ordering is
lexicographic byte ordering.
Show is diagnostic; use toHex for a stable textual encoding.
Instances
| Show Blake2bHash Source # | |
Defined in Cometa.Crypto.Blake2b Methods showsPrec :: Int -> Blake2bHash -> ShowS # show :: Blake2bHash -> String # showList :: [Blake2bHash] -> ShowS # | |
| Eq Blake2bHash Source # | |
Defined in Cometa.Crypto.Blake2b | |
| Ord Blake2bHash Source # | |
Defined in Cometa.Crypto.Blake2b Methods compare :: Blake2bHash -> Blake2bHash -> Ordering # (<) :: Blake2bHash -> Blake2bHash -> Bool # (<=) :: Blake2bHash -> Blake2bHash -> Bool # (>) :: Blake2bHash -> Blake2bHash -> Bool # (>=) :: Blake2bHash -> Blake2bHash -> Bool # max :: Blake2bHash -> Blake2bHash -> Blake2bHash # min :: Blake2bHash -> Blake2bHash -> Blake2bHash # | |
Hashing
Arguments
| :: Int | Digest length in bytes, from 16 through 64 inclusive. |
| -> ByteString | Nonempty message to hash. |
| -> IO (Either Error Blake2bHash) | Digest with the requested length, or a validation or operation failure. |
Compute an unkeyed digest with an output length of 16 through 64 bytes.
Invalid output lengths return InvalidHashLength. Empty messages are currently
unsupported and return NativeError with code OutOfBoundsMemoryRead.
Other cardano-c failures also return NativeError.
Importing digests
fromBytes :: ByteString -> Either Error Blake2bHash Source #
Import digest bytes without hashing them. Any nonempty length is accepted;
this operation does not assert a particular digest role or algorithm variant.
Empty input returns EmptyHash.
fromHex :: Text -> Either Error Blake2bHash Source #
Import nonempty, even-length ASCII hexadecimal text, accepting both cases.
Malformed text returns InvalidHex. No whitespace or prefix is accepted.
Inspection
toBytes :: Blake2bHash -> ByteString Source #
Observe the immutable digest bytes.
toHex :: Blake2bHash -> Text Source #
Encode the digest as lowercase ASCII hex, without a prefix or whitespace.
CBOR
encodeCbor :: Blake2bHash -> ByteString Source #
Encode the digest as one definite-length CBOR byte string.
decodeCbor :: ByteString -> Either Error Blake2bHash Source #
Import exactly one nonempty CBOR byte string without hashing it. Definite
and indefinite byte strings are accepted; invalid CBOR, other types and
trailing data return InvalidHashCbor. Empty bytes return EmptyHash.