crypto-multihash-0.4.0.0: Multihash library on top of cryptonite crypto library

LicenseBSD3
MaintainerMarcello Seri <marcello.seri@gmail.com>
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Crypto.Multihash

Contents

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.

Synopsis

Multihash Types

data MultihashDigest a Source

Multihash Digest container

data Base Source

Base usable to encode the digest

Constructors

Base2

Binary form

Base16

Hex encoding

Base32

Not yet implemented. Waiting for this issue to resolve

Base58

Bitcoin base58 encoding

Base64

Base64 encoding

class Codable a where Source

Codable hash algorithms are the algorithms supported for multihashing

Methods

toCode :: a -> Int Source

Return the first byte for the head of the multihash digest

class Encodable a where Source

Minimal complete definition

encode, check

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

Safely check the correctness of an encoded Encodable against a plain Encodable.

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.

class Checkable b where Source

Minimal complete definition

checkPayload

Methods

checkPayload :: (IsString s, ConvertibleStrings s ByteString) => s -> b -> Either String Bool Source

Safely check the correctness of an encoded Encodable against the corresponding data.

checkPayload' :: (IsString s, ConvertibleStrings s ByteString) => s -> b -> Bool Source

Unsafe version of checkPayload. Throws on encoding/decoding errors instead of returning an Either type.

newtype Payload bs Source

Newtype to allow the creation of a Checkable typeclass for all ByteArrayAccess without recurring to UndecidableInstances

Constructors

Payload bs 

Instances

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.

checkMultihash :: (IsString s, ConvertibleStrings s ByteString, ByteArrayAccess bs) => s -> bs -> Either String Bool Source

checkPayload wrapper for API retro-compatibility

checkMultihash' :: (IsString s, ConvertibleStrings s ByteString, ByteArrayAccess bs) => s -> bs -> Bool Source

Unsafe checkPayload wrapper for API retro-compatibility

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.

data SHA1 :: *

SHA1 cryptographic hash algorithm

Constructors

SHA1 

data SHA256 :: *

SHA256 cryptographic hash algorithm

Constructors

SHA256 

data SHA512 :: *

SHA512 cryptographic hash algorithm

Constructors

SHA512 

data SHA3_512 :: *

SHA3 (512 bits) cryptographic hash algorithm

Constructors

SHA3_512 

data SHA3_384 :: *

SHA3 (384 bits) cryptographic hash algorithm

Constructors

SHA3_384 

data SHA3_256 :: *

SHA3 (256 bits) cryptographic hash algorithm

Constructors

SHA3_256 

data SHA3_224 :: *

SHA3 (224 bits) cryptographic hash algorithm

Constructors

SHA3_224 

data Blake2b_512 :: *

Blake2b (512 bits) cryptographic hash algorithm

Constructors

Blake2b_512 

data Blake2s_256 :: *

Blake2s (256 bits) cryptographic hash algorithm

Constructors

Blake2s_256