raaz-0.2.1: The raaz cryptographic library.

Safe Haskell | None
Language | Haskell2010

Raaz.Core.ByteSource

Contents

- Byte sources.

Description

Module define byte sources.

Synopsis

- class ByteSource src where
  - fillBytes :: BYTES Int -> src -> Pointer -> IO (FillResult src)
- class ByteSource src => PureByteSource src
- data FillResult a
  - = Remaining a
  - | Exhausted (BYTES Int)
- fill :: (LengthUnit len, ByteSource src) => len -> src -> Pointer -> IO (FillResult src)
- processChunks :: (MonadIO m, LengthUnit chunkSize, ByteSource src) => m a -> (BYTES Int -> m b) -> src -> chunkSize -> Pointer -> m b
- withFillResult :: (a -> b) -> (BYTES Int -> b) -> FillResult a -> b

# Byte sources.

Cryptographic input come from various sources; they can come from network sockets or might be just a string in the Haskell. To give a uniform interfaces for all such inputs, we define the abstract concept of a byte source. Essentially a byte source is one from which we can fill a buffer with bytes.

Among instances of `ByteSource`, some like for example `ByteString` are pure in the sense filling a buffer with bytes from such a source has no other side-effects. This is in contrast to a source like a sockets. The type class `PureByteSource` captures such byte sources.

class ByteSource src where Source #

Abstract byte sources. A bytesource is something that you can use to fill a buffer.

WARNING: The source is required to return `Exhausted` in the boundary case where it has exactly the number of bytes requested. In other words, if the source returns `Remaining` on any particular request, there should be at least 1 additional byte left on the source for the next request. Cryptographic block primitives have do certain special processing for the last block and it is required to know whether the last block has been read or not.

Methods

fillBytes Source #

Arguments

:: BYTES Int | Buffer size
-> src | The source to fill.
-> Pointer | Buffer pointer
-> IO (FillResult src) |

Fills a buffer from the source.

#### Instances

Instances details

ByteSource Handle Source # | __WARNING:_ The `fillBytes` may block.
Instance details Defined in Raaz.Core.ByteSource Methods fillBytes :: BYTES Int -> Handle -> Pointer -> IO (FillResult Handle) Source #
ByteSource ByteString Source # |
Instance details Defined in Raaz.Core.ByteSource Methods fillBytes :: BYTES Int -> ByteString -> Pointer -> IO (FillResult ByteString) Source #
ByteSource ByteString Source # |
Instance details Defined in Raaz.Core.ByteSource Methods fillBytes :: BYTES Int -> ByteString -> Pointer -> IO (FillResult ByteString) Source #
ByteSource src => ByteSource [src] Source # |
Instance details Defined in Raaz.Core.ByteSource Methods fillBytes :: BYTES Int -> [src] -> Pointer -> IO (FillResult [src]) Source #
ByteSource src => ByteSource (Maybe src) Source # |
Instance details Defined in Raaz.Core.ByteSource Methods fillBytes :: BYTES Int -> Maybe src -> Pointer -> IO (FillResult (Maybe src)) Source #

class ByteSource src => PureByteSource src Source #

A byte source src is pure if filling from it does not have any other side effect on the state of the byte source. Formally, two different fills form the same source should fill the buffer with the same bytes. This additional constraint on the source helps to purify certain crypto computations like computing the hash or mac of the source. Usualy sources like `ByteString` etc are pure byte sources. A file handle is a byte source that is not a pure source.

#### Instances

Instances details

PureByteSource ByteString Source # |
Instance details Defined in Raaz.Core.ByteSource
PureByteSource ByteString Source # |
Instance details Defined in Raaz.Core.ByteSource
PureByteSource src => PureByteSource [src] Source # |
Instance details Defined in Raaz.Core.ByteSource
PureByteSource src => PureByteSource (Maybe src) Source # |
Instance details Defined in Raaz.Core.ByteSource

data FillResult a Source #

This type captures the result of a fill operation.

Constructors

Remaining a | There is still bytes left.
Exhausted (BYTES Int) | source exhausted with so much bytes read.

#### Instances

Instances details

Functor FillResult Source # |
Instance details Defined in Raaz.Core.ByteSource Methods fmap :: (a -> b) -> FillResult a -> FillResult b Source # (<$) :: a -> FillResult b -> FillResult a Source #
Eq a => Eq (FillResult a) Source # |
Instance details Defined in Raaz.Core.ByteSource Methods (==) :: FillResult a -> FillResult a -> Bool Source # (/=) :: FillResult a -> FillResult a -> Bool Source #
Show a => Show (FillResult a) Source # |
Instance details Defined in Raaz.Core.ByteSource Methods showsPrec :: Int -> FillResult a -> ShowS Source # show :: FillResult a -> String Source # showList :: [FillResult a] -> ShowS Source #

fill :: (LengthUnit len, ByteSource src) => len -> src -> Pointer -> IO (FillResult src) Source #

A version of fillBytes that takes type safe lengths as input.

processChunks :: (MonadIO m, LengthUnit chunkSize, ByteSource src) => m a -> (BYTES Int -> m b) -> src -> chunkSize -> Pointer -> m b Source #

Process data from a source in chunks of a particular size.

withFillResult Source #

Arguments

:: (a -> b) | stuff to do when filled
-> (BYTES Int -> b) | stuff to do when exhausted
-> FillResult a | the fill result to process
-> b |

Combinator to handle a fill result.