| Copyright | (c) Galois Inc 2014-2016 | 
|---|---|
| Maintainer | Joe Hendrix <jhendrix@galois.com> | 
| Safe Haskell | Trustworthy | 
| Language | Haskell98 | 
Data.Parameterized.Nonce
Description
This module provides a simple generator of new indexes in the ST monad. It is predictable and not intended for cryptographic purposes.
This module also provides a global nonce generator that will generate 2^64 nonces before looping.
NOTE: The TestEquality and OrdF instances for the Nonce type simply
compare the generated nonce values and then assert to the compiler
(via unsafeCoerce) that the types ascribed to the nonces are equal
if their values are equal.
Synopsis
- data NonceGenerator (m :: * -> *) (s :: *)
 - freshNonce :: NonceGenerator m s -> forall k (tp :: k). m (Nonce s tp)
 - data Nonce (s :: *) (tp :: k)
 - indexValue :: Nonce s tp -> Word64
 - newSTNonceGenerator :: ST t (Some (NonceGenerator (ST t)))
 - newIONonceGenerator :: IO (Some (NonceGenerator IO))
 - withIONonceGenerator :: (forall s. NonceGenerator IO s -> IO r) -> IO r
 - withSTNonceGenerator :: (forall s. NonceGenerator (ST t) s -> ST t r) -> ST t r
 - withGlobalSTNonceGenerator :: (forall t. NonceGenerator (ST t) t -> ST t r) -> r
 - data GlobalNonceGenerator
 - globalNonceGenerator :: NonceGenerator IO GlobalNonceGenerator
 
NonceGenerator
data NonceGenerator (m :: * -> *) (s :: *) Source #
Provides a monadic action for getting fresh typed names.
The first type parameter m is the monad used for generating names, and
 the second parameter s is used for the counter.
freshNonce :: NonceGenerator m s -> forall k (tp :: k). m (Nonce s tp) Source #
data Nonce (s :: *) (tp :: k) Source #
An index generated by the counter.
Instances
| TestEquality (Nonce s :: k -> *) Source # | |
Defined in Data.Parameterized.Nonce  | |
| HashableF (Nonce s :: k -> *) Source # | |
| ShowF (Nonce s :: k -> *) Source # | |
| OrdF (Nonce s :: k -> *) Source # | |
| Eq (Nonce s tp) Source # | |
| Ord (Nonce s tp) Source # | |
Defined in Data.Parameterized.Nonce  | |
| Show (Nonce s tp) Source # | |
| Hashable (Nonce s tp) Source # | |
Defined in Data.Parameterized.Nonce  | |
indexValue :: Nonce s tp -> Word64 Source #
Accessing a nonce generator
newSTNonceGenerator :: ST t (Some (NonceGenerator (ST t))) Source #
Create a new nonce generator in the ST monad.
newIONonceGenerator :: IO (Some (NonceGenerator IO)) Source #
Create a new nonce generator in the ST monad.
withIONonceGenerator :: (forall s. NonceGenerator IO s -> IO r) -> IO r Source #
Create a new nonce generator in the IO monad.
withSTNonceGenerator :: (forall s. NonceGenerator (ST t) s -> ST t r) -> ST t r Source #
Run a ST computation with a new nonce generator in the ST monad.
withGlobalSTNonceGenerator :: (forall t. NonceGenerator (ST t) t -> ST t r) -> r Source #
Create a new counter.
data GlobalNonceGenerator Source #
globalNonceGenerator :: NonceGenerator IO GlobalNonceGenerator Source #
A nonce generator that uses a globally-defined counter.