raaz-0.0.2: The raaz cryptographic library.

Safe HaskellNone

Raaz.Core.ByteSource

Contents

Description

Module define byte sources.

Synopsis

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. Depending on the nature of the source we have two classes: ByteSource which captures bounded sources and InfiniteSource that captures never ending source of 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 InfiniteSource src whereSource

Never ending stream of bytes. The reads to the stream might get delayed but it will always return the number of bytes that were asked for.

Methods

slurpBytesSource

Arguments

:: BYTES Int

bytes to read,

-> src

the source to fill from,

-> Pointer

the buffer source to fill.

-> IO src 

class ByteSource src whereSource

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

Methods

fillBytesSource

Arguments

:: BYTES Int

Buffer size

-> src

The source to fill.

-> Pointer

Buffer pointer

-> IO (FillResult src) 

Fills a buffer from the source.

Instances

ByteSource Handle 
ByteSource ByteString 
ByteSource ByteString 
ByteSource src => ByteSource [src] 
ByteSource src => ByteSource (Maybe src) 

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

data FillResult a Source

This type captures the result of a fill operation.

Constructors

Remaining a

the buffer is filled completely

Exhausted (BYTES Int)

source exhausted with so much bytes read.

Instances

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

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

slurp :: (LengthUnit len, InfiniteSource src) => len -> src -> Pointer -> IO srcSource

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

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

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

withFillResultSource

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.