License | BSD3 |
---|---|
Maintainer | Marcello Seri <marcello.seri@gmail.com> |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
Crypto.Multihash
Description
Multihash library built on top of haskell cryptonite
crypto package
Multihash is a protocol for encoding the hash algorithm and digest length
at the start of the digest, see the official
multihash poroposal github repo.
The library re-exports the needed types and typclasses from Algorithms
namely HashAlgorithm
, SHA1
, SHA256
, SHA512
, SHA3_512
, SHA3_384
,
SHA3_256
, SHA3_224
, Blake2b_512
, Blake2s_256
.
For additional informations refer to the README.md or the gihub repository.
- data MultihashDigest a
- data Base
- class Codable a where
- class Encodable a where
- encode :: IsString s => Base -> a -> Either String s
- encode' :: IsString s => Base -> a -> s
- check :: (IsString s, ConvertibleStrings s ByteString) => s -> a -> Either String Bool
- check' :: (IsString s, ConvertibleStrings s ByteString) => s -> a -> Bool
- multihash :: (HashAlgorithm a, Codable a, ByteArrayAccess bs) => a -> bs -> MultihashDigest a
- multihashlazy :: (HashAlgorithm a, Codable a) => a -> ByteString -> MultihashDigest a
- truncatedMultihash :: (HashAlgorithm a, Codable a, ByteArrayAccess bs) => Int -> a -> bs -> Either String (MultihashDigest a)
- truncatedMultihash' :: (HashAlgorithm a, Codable a, ByteArrayAccess bs) => Int -> a -> bs -> MultihashDigest a
- checkMultihash :: (IsString s, ConvertibleStrings s ByteString, ByteArrayAccess bs) => s -> bs -> Either String Bool
- checkMultihash' :: (IsString s, ConvertibleStrings s ByteString, ByteArrayAccess bs) => s -> bs -> Bool
- getBase :: ByteString -> Either String Base
- class HashAlgorithm a
- data SHA1 :: * = SHA1
- data SHA256 :: * = SHA256
- data SHA512 :: * = SHA512
- data SHA3_512 :: * = SHA3_512
- data SHA3_384 :: * = SHA3_384
- data SHA3_256 :: * = SHA3_256
- data SHA3_224 :: * = SHA3_224
- data Blake2b_512 :: * = Blake2b_512
- data Blake2s_256 :: * = Blake2s_256
Multihash Types
data MultihashDigest a Source
Multihash Digest container
Instances
Eq a => Eq (MultihashDigest a) Source | |
(HashAlgorithm a, Codable a) => Show (MultihashDigest a) Source | |
(HashAlgorithm a, Codable a) => Encodable (MultihashDigest a) Source |
Base
usable to encode the digest
Codable
hash algorithms are the algorithms supported for multihashing
class Encodable a where Source
Methods
encode :: IsString s => Base -> a -> Either String s Source
Safe encoder for Encodable
.
encode' :: IsString s => Base -> a -> s Source
Unsafe encoder for Encodable
.
Throws an error if there are encoding issues.
check :: (IsString s, ConvertibleStrings s ByteString) => s -> a -> Either String Bool Source
check' :: (IsString s, ConvertibleStrings s ByteString) => s -> a -> Bool Source
Unsafe version of check
. Throws on encoding/decoding errors instead of returning an Either type.
Instances
Encodable WeakMultihashDigest Source | |
(HashAlgorithm a, Codable a) => Encodable (MultihashDigest a) Source |
Multihash helpers
multihash :: (HashAlgorithm a, Codable a, ByteArrayAccess bs) => a -> bs -> MultihashDigest a Source
Helper to multihash a ByteArrayAccess
(e.g. a ByteString
) using a
supported hash algorithm. Uses hash
for hashing.
multihashlazy :: (HashAlgorithm a, Codable a) => a -> ByteString -> MultihashDigest a Source
Helper to multihash a lazy ByteString
using a supported hash algorithm.
Uses hashlazy
for hashing.
truncatedMultihash :: (HashAlgorithm a, Codable a, ByteArrayAccess bs) => Int -> a -> bs -> Either String (MultihashDigest a) Source
Helper to multihash a ByteArrayAccess
using a supported hash algorithm.
Uses hash
for hashing and truncates the hash to the lenght
specified (must be positive and not longer than the digest length).
truncatedMultihash' :: (HashAlgorithm a, Codable a, ByteArrayAccess bs) => Int -> a -> bs -> MultihashDigest a Source
Unsafe helper to multihash a ByteArrayAccess
using a supported hash algorithm.
Uses hash
for hashing and truncates the hash to the lenght
specified (must be positive and not longer than the digest length, otherwise
the function will throw an error).
checkMultihash :: (IsString s, ConvertibleStrings s ByteString, ByteArrayAccess bs) => s -> bs -> Either String Bool Source
Safely check the correctness of an encoded Encodable
against the
corresponding data.
checkMultihash' :: (IsString s, ConvertibleStrings s ByteString, ByteArrayAccess bs) => s -> bs -> Bool Source
Unsafe version of checkMultihash
.
Throws on encoding/decoding errors instead of returning an Either
type.
getBase :: ByteString -> Either String Base Source
Infer the Base
encoding function from an encoded BinaryString
.
Supports only Base16
, bitcoin Base58
and Base64
for the moment.
NOTE: it can fail or _infer the wrong encoding_ if the string is too short
or if it is encoded using a different standard.
Re-exported types
class HashAlgorithm a
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.
Minimal complete definition
hashBlockSize, hashDigestSize, hashInternalContextSize, hashInternalInit, hashInternalUpdate, hashInternalFinalize