pureMD5-2.1.4: A Haskell-only implementation of the MD5 digest (hash) algorithm.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Digest.Pure.MD5

Contents

- Types
- Static data
- Functions
- Crypto-API interface

Description

It is suggested you use the 'crypto-api' class-based interface to access the MD5 algorithm. Either rely on type inference or provide an explicit type:

      hashFileStrict = liftM hash' . B.readFile
      hashFileLazyBS = liftM hash . B.readFile

Synopsis

- data MD5Context
- data MD5Digest
- md5InitialContext :: MD5Context
- md5 :: ByteString -> MD5Digest
- md5Update :: MD5Context -> ByteString -> MD5Context
- md5Finalize :: MD5Context -> ByteString -> MD5Digest
- md5DigestBytes :: MD5Digest -> ByteString
- class (Serialize d, Eq d, Ord d) => Hash ctx d | d -> ctx, ctx -> d where
  - outputLength :: Tagged d BitLength
  - blockLength :: Tagged d BitLength
  - initialCtx :: ctx
  - updateCtx :: ctx -> ByteString -> ctx
  - finalize :: ctx -> ByteString -> d
  - hash :: ByteString -> d
  - hash' :: ByteString -> d

# Types

data MD5Context Source #

The type for final results.

#### Instances

Instances details

Binary MD5Context Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods put :: MD5Context -> Put Source # get :: Get MD5Context Source # putList :: [MD5Context] -> Put Source #
Serialize MD5Context Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods put :: Putter MD5Context Source # get :: Get MD5Context Source #
Hash MD5Context MD5Digest Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods outputLength :: Tagged MD5Digest BitLength Source # blockLength :: Tagged MD5Digest BitLength Source # initialCtx :: MD5Context Source # updateCtx :: MD5Context -> ByteString -> MD5Context Source # finalize :: MD5Context -> ByteString -> MD5Digest Source # hash :: ByteString -> MD5Digest Source # hash' :: ByteString -> MD5Digest Source #

data MD5Digest Source #

After finalizing a context, using md5Finalize, a new type is returned to prevent 're-finalizing' the structure.

#### Instances

Instances details

Show MD5Digest Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods showsPrec :: Int -> MD5Digest -> ShowS Source # show :: MD5Digest -> String Source # showList :: [MD5Digest] -> ShowS Source #
Binary MD5Digest Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods put :: MD5Digest -> Put Source # get :: Get MD5Digest Source # putList :: [MD5Digest] -> Put Source #
Serialize MD5Digest Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods put :: Putter MD5Digest Source # get :: Get MD5Digest Source #
Eq MD5Digest Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods (==) :: MD5Digest -> MD5Digest -> Bool Source # (/=) :: MD5Digest -> MD5Digest -> Bool Source #
Ord MD5Digest Source # |

Instance details

Defined in Data.Digest.Pure.MD5

Methods

compare :: MD5Digest -> MD5Digest -> Ordering Source #

(<) :: MD5Digest -> MD5Digest -> Bool Source #

(<=) :: MD5Digest -> MD5Digest -> Bool Source #

(>) :: MD5Digest -> MD5Digest -> Bool Source #

(>=) :: MD5Digest -> MD5Digest -> Bool Source #

max :: MD5Digest -> MD5Digest -> MD5Digest Source #

min :: MD5Digest -> MD5Digest -> MD5Digest Source #

Hash MD5Context MD5Digest Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods outputLength :: Tagged MD5Digest BitLength Source # blockLength :: Tagged MD5Digest BitLength Source # initialCtx :: MD5Context Source # updateCtx :: MD5Context -> ByteString -> MD5Context Source # finalize :: MD5Context -> ByteString -> MD5Digest Source # hash :: ByteString -> MD5Digest Source # hash' :: ByteString -> MD5Digest Source #

# Static data

md5InitialContext :: MD5Context Source #

The initial context to use when calling md5Update for the first time

# Functions

md5 :: ByteString -> MD5Digest Source #

Processes a lazy ByteString and returns the md5 digest. This is probably what you want. You can use `show` to produce the standard hex representation.

md5Update :: MD5Context -> ByteString -> MD5Context Source #

Alters the MD5Context with a partial digest of the data.

The input bytestring MUST be a multiple of the blockSize or bad things can happen (incorrect digest results)!

md5Finalize :: MD5Context -> ByteString -> MD5Digest Source #

Closes an MD5 context, thus producing the digest.

md5DigestBytes :: MD5Digest -> ByteString Source #

The raw bytes of an `MD5Digest`. It is always 16 bytes long.

You can also use the `Binary` or `Serialize` instances to output the raw bytes. Alternatively you can use `show` to produce the standard hex representation.

# Crypto-API interface

class (Serialize d, Eq d, Ord d) => Hash ctx d | d -> ctx, ctx -> d where Source #

The Hash class is intended as the generic interface targeted by maintainers of Haskell digest implementations. Using this generic interface, higher level functions such as `hash` and `hash'` provide a useful API for comsumers of hash implementations.

Any instantiated implementation must handle unaligned data.

Minimum complete definition: `outputLength`, `blockLength`, `initialCtx`, `updateCtx`, and `finalize`.

Minimal complete definition

outputLength, blockLength, initialCtx, updateCtx, finalize

Methods

outputLength Source #

Arguments

:: Tagged d BitLength | The size of the digest when encoded

blockLength Source #

Arguments

:: Tagged d BitLength | The amount of data operated on in each round of the digest computation

initialCtx Source #

Arguments

:: ctx | An initial context, provided with the first call to `updateCtx`

updateCtx Source #

Arguments

:: ctx |
-> ByteString |
-> ctx | Used to update a context, repeatedly called until all data is exhausted must operate correctly for imputs of `n*blockLength` bytes for `n `elem` [0..]`

finalize Source #

Arguments

:: ctx |
-> ByteString |
-> d | Finializing a context, plus any message data less than the block size, into a digest

hash :: ByteString -> d Source #

Hash a lazy ByteString, creating a digest

hash' :: ByteString -> d Source #

Hash a strict ByteString, creating a digest

#### Instances

Instances details

Hash MD5Context MD5Digest Source # |
Instance details Defined in Data.Digest.Pure.MD5 Methods outputLength :: Tagged MD5Digest BitLength Source # blockLength :: Tagged MD5Digest BitLength Source # initialCtx :: MD5Context Source # updateCtx :: MD5Context -> ByteString -> MD5Context Source # finalize :: MD5Context -> ByteString -> MD5Digest Source # hash :: ByteString -> MD5Digest Source # hash' :: ByteString -> MD5Digest Source #