hnix-store-core-0.1.0.0: Core effects for interacting with the Nix store.

Safe HaskellNone
LanguageHaskell2010

System.Nix.Hash

Description

 
Synopsis

Documentation

data Digest (a :: HashAlgorithm) Source #

The result of running a HashAlgorithm.

Instances
Eq (Digest a) Source # 
Instance details

Defined in System.Nix.Internal.Hash

Methods

(==) :: Digest a -> Digest a -> Bool #

(/=) :: Digest a -> Digest a -> Bool #

Ord (Digest a) Source # 
Instance details

Defined in System.Nix.Internal.Hash

Methods

compare :: Digest a -> Digest a -> Ordering #

(<) :: Digest a -> Digest a -> Bool #

(<=) :: Digest a -> Digest a -> Bool #

(>) :: Digest a -> Digest a -> Bool #

(>=) :: Digest a -> Digest a -> Bool #

max :: Digest a -> Digest a -> Digest a #

min :: Digest a -> Digest a -> Digest a #

Show (Digest a) Source # 
Instance details

Defined in System.Nix.Internal.Hash

Methods

showsPrec :: Int -> Digest a -> ShowS #

show :: Digest a -> String #

showList :: [Digest a] -> ShowS #

Hashable (Digest a) Source # 
Instance details

Defined in System.Nix.Internal.Hash

Methods

hashWithSalt :: Int -> Digest a -> Int #

hash :: Digest a -> Int #

data HashAlgorithm Source #

The universe of supported hash algorithms.

Currently only intended for use at the type level.

Constructors

MD5 
SHA1 
SHA256 
Truncated Nat HashAlgorithm

The hash algorithm obtained by truncating the result of the input HashAlgorithm to the given number of bytes. See truncateDigest for a description of the truncation algorithm.

class ValidAlgo (a :: HashAlgorithm) where Source #

The primitive interface for incremental hashing for a given HashAlgorithm. Every HashAlgorithm should have an instance.

Associated Types

type AlgoCtx a Source #

The incremental state for constructing a hash.

Methods

initialize :: AlgoCtx a Source #

Start building a new hash.

update :: AlgoCtx a -> ByteString -> AlgoCtx a Source #

Append a ByteString to the overall contents to be hashed.

finalize :: AlgoCtx a -> Digest a Source #

Finish hashing and generate the output.

Instances
ValidAlgo MD5 Source #

Uses Crypto.Hash.MD5 from cryptohash-md5.

Instance details

Defined in System.Nix.Internal.Hash

Associated Types

type AlgoCtx MD5 :: Type Source #

ValidAlgo SHA1 Source #

Uses Crypto.Hash.SHA1 from cryptohash-sha1.

Instance details

Defined in System.Nix.Internal.Hash

Associated Types

type AlgoCtx SHA1 :: Type Source #

ValidAlgo SHA256 Source #

Uses Crypto.Hash.SHA256 from cryptohash-sha256.

Instance details

Defined in System.Nix.Internal.Hash

Associated Types

type AlgoCtx SHA256 :: Type Source #

(ValidAlgo a, KnownNat n) => ValidAlgo (Truncated n a) Source #

Reuses the underlying ValidAlgo instance, but does a truncateDigest at the end.

Instance details

Defined in System.Nix.Internal.Hash

Associated Types

type AlgoCtx (Truncated n a) :: Type Source #

class NamedAlgo (a :: HashAlgorithm) where Source #

A HashAlgorithm with a canonical name, for serialization purposes (e.g. SRI hashes)

Methods

algoName :: Text Source #

Instances
NamedAlgo MD5 Source # 
Instance details

Defined in System.Nix.Internal.Hash

Methods

algoName :: Text Source #

NamedAlgo SHA1 Source # 
Instance details

Defined in System.Nix.Internal.Hash

Methods

algoName :: Text Source #

NamedAlgo SHA256 Source # 
Instance details

Defined in System.Nix.Internal.Hash

Methods

algoName :: Text Source #

hash :: forall a. ValidAlgo a => ByteString -> Digest a Source #

Hash an entire (strict) ByteString as a single call.

For example: > let d = hash "Hello, sha-256!" :: Digest SHA256 or > :set -XTypeApplications > let d = hash @SHA256 "Hello, sha-256!"

hashLazy :: forall a. ValidAlgo a => ByteString -> Digest a Source #

Hash an entire (lazy) ByteString as a single call.

Use is the same as for hash. This runs in constant space, but forces the entire bytestring.

encodeBase32 :: Digest a -> Text Source #

Encode a Digest in the special Nix base-32 encoding.

encodeBase16 :: Digest a -> Text Source #

Encode a Digest in hex.