packages feed

nonce 1.0.3 → 1.0.4

raw patch · 2 files changed

+6/−9 lines, 2 filesdep +entropydep −cryptonite

Dependencies added: entropy

Dependencies removed: cryptonite

Files

nonce.cabal view
@@ -1,5 +1,5 @@ name:                nonce-version:             1.0.3+version:             1.0.4 synopsis:            Generate cryptographic nonces. homepage:            https://github.com/prowdsponsor/nonce license:             BSD3@@ -31,9 +31,9 @@       base              >= 4.5   && < 4.11     , base64-bytestring == 1.0.*     , bytestring        >= 0.9-    , cryptonite        >= 0.4     , text              >= 0.9     , transformers      >= 0.2+    , entropy           >= 0.3.7 && < 0.4   hs-source-dirs: src/   default-language: Haskell2010   ghc-options: -Wall
src/Crypto/Nonce.hs view
@@ -32,20 +32,17 @@  import Control.Monad (liftM) import Control.Monad.IO.Class (MonadIO, liftIO)-import Crypto.Random-import Data.Tuple (swap)+import qualified System.Entropy as Entropy import Data.Typeable (Typeable)  import qualified Data.ByteString as B import qualified Data.ByteString.Base64.URL as B64URL-import qualified Data.IORef as I import qualified Data.Text as T import qualified Data.Text.Encoding as TE   -- | An encapsulated nonce generator.-data Generator =-  G (I.IORef SystemDRG)+data Generator = G Entropy.CryptHandle   deriving (Typeable)  instance Show Generator where@@ -54,12 +51,12 @@  -- | Create a new nonce generator using the system entropy. new :: MonadIO m => m Generator-new = liftM G . liftIO $ getSystemDRG >>= I.newIORef+new = liftM G . liftIO $ Entropy.openHandle   -- | (Internal) Generate the given number of bytes from the DRG. genBytes :: MonadIO m => Int -> Generator -> m B.ByteString-genBytes n (G v) = liftIO $ I.atomicModifyIORef v $ swap . randomBytesGenerate n+genBytes n (G v) = liftIO $ Entropy.hGetEntropy v n   -- | Generate a 128 bit nonce as a 'B.ByteString' of 16 bytes.