pantry-0.4.0.2: Content addressable Haskell package management

Safe Haskell | None
Language | Haskell2010

Pantry.SHA256

Contents

- Types
- Hashing
- Convert from a hash representation
- Convert to a hash representation

Description

Provides a data type (`SHA256`) for efficient memory representation of a sha-256 hash value, together with helper functions for converting to and from that value. This module is intended to be imported qualified as `SHA256`.

Some nomenclature:

- Hashing calculates a new hash value from some input. `from` takes a value that representats an existing hash.
- Raw means a raw binary representation of the hash value, without any hex encoding.
- Text always uses lower case hex encoding

Since: 0.1.0.0

Synopsis

- data SHA256
- data SHA256Exception
  - = InvalidByteCount !ByteString !StaticBytesException
  - | InvalidHexBytes !ByteString !Text
- hashFile :: MonadIO m => FilePath -> m SHA256
- hashBytes :: ByteString -> SHA256
- hashLazyBytes :: LByteString -> SHA256
- sinkHash :: Monad m => ConduitT ByteString o m SHA256
- fromHexText :: Text -> Either SHA256Exception SHA256
- fromHexBytes :: ByteString -> Either SHA256Exception SHA256
- fromDigest :: Digest SHA256 -> SHA256
- fromRaw :: ByteString -> Either SHA256Exception SHA256
- toHexText :: SHA256 -> Text
- toHexBytes :: SHA256 -> ByteString
- toRaw :: SHA256 -> ByteString

# Types

data SHA256 Source #

A SHA256 hash, stored in a static size for more efficient memory representation.

Since: 0.1.0.0

#### Instances

Instances details

Eq SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods (==) :: SHA256 -> SHA256 -> Bool Source # (/=) :: SHA256 -> SHA256 -> Bool Source #
Data SHA256 Source # |

Instance details

Defined in Pantry.SHA256

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SHA256 -> c SHA256 Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SHA256 Source #

toConstr :: SHA256 -> Constr Source #

dataTypeOf :: SHA256 -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SHA256) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SHA256) Source #

gmapT :: (forall b. Data b => b -> b) -> SHA256 -> SHA256 Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SHA256 -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SHA256 -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> SHA256 -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> SHA256 -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> SHA256 -> m SHA256 Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SHA256 -> m SHA256 Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SHA256 -> m SHA256 Source #

Ord SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods compare :: SHA256 -> SHA256 -> Ordering Source # (<) :: SHA256 -> SHA256 -> Bool Source # (<=) :: SHA256 -> SHA256 -> Bool Source # (>) :: SHA256 -> SHA256 -> Bool Source # (>=) :: SHA256 -> SHA256 -> Bool Source # max :: SHA256 -> SHA256 -> SHA256 Source # min :: SHA256 -> SHA256 -> SHA256 Source #
Show SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods showsPrec :: Int -> SHA256 -> ShowS Source # show :: SHA256 -> String Source # showList :: [SHA256] -> ShowS Source #
Generic SHA256 Source # |
Instance details Defined in Pantry.SHA256 Associated Types type Rep SHA256 :: Type -> Type Source # Methods from :: SHA256 -> Rep SHA256 x Source # to :: Rep SHA256 x -> SHA256 Source #
NFData SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods rnf :: SHA256 -> () Source #
Hashable SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods hashWithSalt :: Int -> SHA256 -> Int hash :: SHA256 -> Int
ToJSON SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods toJSON :: SHA256 -> Value Source # toEncoding :: SHA256 -> Encoding Source # toJSONList :: [SHA256] -> Value Source # toEncodingList :: [SHA256] -> Encoding Source #
FromJSON SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods parseJSON :: Value -> Parser SHA256 Source # parseJSONList :: Value -> Parser [SHA256] Source #
PersistFieldSql SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods sqlType :: Proxy SHA256 -> SqlType Source #
PersistField SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods toPersistValue :: SHA256 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text SHA256 Source #
Display SHA256 Source # |
Instance details Defined in Pantry.SHA256 Methods display :: SHA256 -> Utf8Builder Source # textDisplay :: SHA256 -> Text Source #
type Rep SHA256 Source # |
Instance details Defined in Pantry.SHA256 type Rep SHA256 = D1 ('MetaData "SHA256" "Pantry.SHA256" "pantry-0.4.0.2-ETSzthT64wgLZ1gxgdpmY6" 'True) (C1 ('MetaCons "SHA256" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bytes32)))

data SHA256Exception Source #

Exceptions which can occur in this module

Since: 0.1.0.0

Constructors

InvalidByteCount !ByteString !StaticBytesException |
InvalidHexBytes !ByteString !Text |

#### Instances

Instances details

Show SHA256Exception Source # |
Instance details Defined in Pantry.SHA256 Methods showsPrec :: Int -> SHA256Exception -> ShowS Source # show :: SHA256Exception -> String Source # showList :: [SHA256Exception] -> ShowS Source #
Exception SHA256Exception Source # |
Instance details Defined in Pantry.SHA256 Methods toException :: SHA256Exception -> SomeException Source # fromException :: SomeException -> Maybe SHA256Exception Source # displayException :: SHA256Exception -> String Source #
Display SHA256Exception Source # |
Instance details Defined in Pantry.SHA256 Methods display :: SHA256Exception -> Utf8Builder Source # textDisplay :: SHA256Exception -> Text Source #

# Hashing

hashFile :: MonadIO m => FilePath -> m SHA256 Source #

Generate a `SHA256` value by hashing the contents of a file.

Since: 0.1.0.0

hashBytes :: ByteString -> SHA256 Source #

Generate a `SHA256` value by hashing a `ByteString`.

Since: 0.1.0.0

hashLazyBytes :: LByteString -> SHA256 Source #

Generate a `SHA256` value by hashing a lazy `ByteString`.

Since: 0.1.0.0

sinkHash :: Monad m => ConduitT ByteString o m SHA256 Source #

Generate a `SHA256` value by hashing the contents of a stream.

Since: 0.1.0.0

# Convert from a hash representation

fromHexText :: Text -> Either SHA256Exception SHA256 Source #

Convert a base16-encoded `Text` value containing a hash into a `SHA256`.

Since: 0.1.0.0

fromHexBytes :: ByteString -> Either SHA256Exception SHA256 Source #

Convert a base16-encoded `ByteString` value containing a hash into a `SHA256`.

Since: 0.1.0.0

fromDigest :: Digest SHA256 -> SHA256 Source #

Convert a `Digest` into a `SHA256`

Since: 0.1.0.0

fromRaw :: ByteString -> Either SHA256Exception SHA256 Source #

Convert a raw representation of a hash into a `SHA256`.

Since: 0.1.0.0

# Convert to a hash representation

toHexText :: SHA256 -> Text Source #

Convert a `SHA256` into a base16-encoded SHA256 hash.

Since: 0.1.0.0

toHexBytes :: SHA256 -> ByteString Source #

Convert a `SHA256` into a base16-encoded SHA256 hash.

Since: 0.1.0.0

toRaw :: SHA256 -> ByteString Source #

Convert a `SHA256` into a raw binary representation.

Since: 0.1.0.0