pipes-cacophony 0.4.1 → 0.5.0
raw patch · 9 files changed
+250/−217 lines, 9 filesdep −lensdep −memorydep ~basedep ~cacophonyPVP ok
version bump matches the API change (PVP)
Dependencies removed: lens, memory
Dependency ranges changed: base, cacophony
API changes (from Hackage documentation)
- Pipes.Noise: mkNoisePipes :: (MonadIO m, Cipher c, DH d, Hash h) => NoiseState c d h -> IO (InboundNoisePipe m (Either SomeException ()), OutboundNoisePipe m (Either SomeException ()))
+ Pipes.Noise: mkNoisePipes :: (Monad m, Cipher c, DH d, Hash h) => NoiseState c d h -> Maybe (InboundNoisePipe m (NoiseResult c d h), OutboundNoisePipe m (NoiseResult c d h))
Files
- .travis.yml +19/−64
- changelog.md +4/−0
- examples/loopback/Main.hs +35/−16
- package.yaml +79/−0
- pipes-cacophony.cabal +57/−84
- src/Pipes/Noise.hs +34/−37
- stack.yaml +6/−0
- tests/hlint.hs +0/−16
- tests/hlint/hlint.hs +16/−0
.travis.yml view
@@ -1,81 +1,36 @@-# This file has been generated -- see https://github.com/hvr/multi-ghc-travis language: c-sudo: false+dist: trusty cache: directories:- - $HOME/.cabsnap- - $HOME/.cabal/packages+ - $HOME/.stack -before_cache:- - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log- - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar+addons:+ apt:+ packages:+ - libgmp-dev matrix: include:- - env: CABALVER=1.22 GHCVER=7.10.3- compiler: ": #GHC 7.10.3"- addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=1.24 GHCVER=8.0.2- compiler: ": #GHC 8.0.2"- addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=head GHCVER=head- compiler: ": #GHC head"- addons: {apt: {packages: [cabal-install-head,ghc-head,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}+ - env: ARGS="--resolver lts-8"+ compiler: ": #stack 8.0.2" + - env: ARGS="--resolver nightly"+ compiler: ": #stack nightly"+ allow_failures:- - env: CABALVER=head GHCVER=head+ - env: ARGS="--resolver nightly"+ compiler: ": #stack nightly" before_install: - unset CC- - export HAPPYVER=1.19.5- - export ALEXVER=3.1.7- - export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:/opt/happy/$HAPPYVER/bin:/opt/alex/$ALEXVER/bin:$PATH+ - mkdir -p ~/.local/bin+ - export PATH=$HOME/.local/bin:$PATH+ - travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' install:- - cabal --version- - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"- - if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ];- then- zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz >- $HOME/.cabal/packages/hackage.haskell.org/00-index.tar;- fi- - travis_retry cabal update- - "sed -i 's/^jobs:.*$/jobs: 2/' $HOME/.cabal/config"- - cabal install --only-dependencies --enable-tests -fbuild-examples --dry -v pipes-cacophony.cabal > installplan.txt- - sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt-- # check whether current requested install-plan matches cached package-db snapshot- - if diff -u installplan.txt $HOME/.cabsnap/installplan.txt;- then- echo "cabal build-cache HIT";- rm -rfv .ghc;- cp -a $HOME/.cabsnap/ghc $HOME/.ghc;- cp -a $HOME/.cabsnap/lib $HOME/.cabsnap/share $HOME/.cabsnap/bin $HOME/.cabal/;- else- echo "cabal build-cache MISS";- rm -rf $HOME/.cabsnap;- mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;- cabal install --only-dependencies --enable-tests -fbuild-examples pipes-cacophony.cabal;- fi-- # snapshot package-db on cache miss- - if [ ! -d $HOME/.cabsnap ];- then- echo "snapshotting package-db to build-cache";- mkdir $HOME/.cabsnap;- cp -a $HOME/.ghc $HOME/.cabsnap/ghc;- cp -a $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin installplan.txt $HOME/.cabsnap/;- fi+ - stack $ARGS setup script:- - cabal configure --enable-tests -fbuild-examples -v2 # -v2 provides useful information for debugging- - cabal build # this builds all libraries and executables (including tests)- - cabal test- - cabal sdist # tests that a source-distribution can be generated-- # Check that the resulting source distribution can be built & installed.- # If there are no other `.tar.gz` files in `dist`, this can be even simpler:- # `cabal install --force-reinstalls dist/*-*.tar.gz`- - SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz &&- (cd dist && cabal install --enable-tests --run-tests -fbuild-examples --force-reinstalls "$SRC_TGZ")+ - stack $ARGS --no-terminal test --flag "pipes-cacophony:build-examples" --haddock --no-haddock-deps+ - stack sdist
changelog.md view
@@ -1,3 +1,7 @@+# 0.5.0++* Brought up to date with cacophony API changes+ # 0.4.1 * Brought up to date with cacophony API changes
examples/loopback/Main.hs view
@@ -1,10 +1,8 @@ module Main where -import Control.Exception (SomeException)-import Control.Lens import Control.Monad (forever)-import Data.ByteArray (ScrubbedBytes, convert) import Data.ByteString.Char8 (unpack, pack)+import Data.Maybe (fromMaybe) import Pipes import qualified Pipes.Prelude as P @@ -17,28 +15,49 @@ import Pipes.Noise -strToSB :: Pipe String ScrubbedBytes IO (Either SomeException ())+strToSB :: (Cipher c, DH d, Hash h)+ => Pipe String ScrubbedBytes IO (NoiseResult c d h) strToSB = forever $ await >>= yield . convert . pack -sbToStr :: Pipe ScrubbedBytes String IO (Either SomeException ())+sbToStr :: (Cipher c, DH d, Hash h)+ => Pipe ScrubbedBytes String IO (NoiseResult c d h) sbToStr = forever $ await >>= yield . unpack . convert +performHandshake :: (Cipher c, DH d, Hash h)+ => NoiseState c d h+ -> NoiseState c d h+ -> (NoiseState c d h, NoiseState c d h)+performHandshake ins rns = (ins'', rns'')+ where+ (NoiseResultMessage ct ins') = writeMessage mempty ins+ (NoiseResultMessage _ rns') = readMessage ct rns+ (NoiseResultMessage ct' rns'') = writeMessage mempty rns'+ (NoiseResultMessage _ ins'') = readMessage ct' ins'+ main :: IO () main = do iek <- dhGenKey :: IO (KeyPair Curve25519) rek <- dhGenKey :: IO (KeyPair Curve25519) - let idho = defaultHandshakeOpts noiseNN InitiatorRole- rdho = defaultHandshakeOpts noiseNN ResponderRole- iho = idho & hoLocalEphemeral .~ Just iek- rho = rdho & hoLocalEphemeral .~ Just rek- ins = noiseState iho :: NoiseState ChaChaPoly1305 Curve25519 SHA256- rns = noiseState rho :: NoiseState ChaChaPoly1305 Curve25519 SHA256+ let idho = defaultHandshakeOpts InitiatorRole "cacophony"+ rdho = defaultHandshakeOpts ResponderRole "cacophony"+ iho = setLocalEphemeral (Just iek) idho+ rho = setLocalEphemeral (Just rek) rdho+ ins = noiseState iho noiseNN :: NoiseState ChaChaPoly1305 Curve25519 SHA256+ rns = noiseState rho noiseNN :: NoiseState ChaChaPoly1305 Curve25519 SHA256 - (iip, iop) <- mkNoisePipes ins- (rip, rop) <- mkNoisePipes rns+ (ins', rns') = performHandshake ins rns+ (iip, iop) = fromMaybe (error "unable to make Noise pipe") $ mkNoisePipes ins'+ (rip, rop) = fromMaybe (error "unable to make Noise pipe") $ mkNoisePipes rns' - result <- runEffect $ (Right () <$ P.stdinLn) >-> strToSB >-> iop >-> rip >-> rop >-> iip >-> sbToStr >-> (Right () <$ P.stdoutLn)+ result <- runEffect $ (undefined <$ P.stdinLn)+ >-> strToSB+ >-> iop+ >-> rip+ >-> rop+ >-> iip+ >-> sbToStr+ >-> (undefined <$ P.stdoutLn) case result of- Left e -> print e- Right _ -> return ()+ NoiseResultException ex -> print ex+ _ -> return ()
+ package.yaml view
@@ -0,0 +1,79 @@+name: pipes-cacophony+synopsis: Pipes for Noise-secured network connections.+version: 0.5.0+license: PublicDomain+license-file: LICENSE+maintainer: John Galt <jgalt@centromere.net>+category: Cryptography+github: centromere/pipes-cacophony+ghc-options: -Wall+description: |+ A set of pipes to secure network connections with the+ <https://github.com/trevp/noise/blob/master/noise.md Noise> protocol.+extra-source-files:+ - .travis.yml+ - README.md+ - changelog.md+ - LICENSE+ - stack.yaml+ - package.yaml+ - tests/.hlint++flags:+ build-examples:+ description: Build examples+ default: False+ manual: True++library:+ source-dirs: src+ dependencies:+ - base >= 4.9 && < 4.10+ - bytestring+ - cacophony >= 0.10+ - pipes++ exposed-modules:+ - Pipes.Noise++ default-extensions:+ - OverloadedStrings++tests:+ hlint:+ main: hlint.hs+ source-dirs: tests/hlint+ dependencies:+ - base >= 4.9 && < 4.10+ - hlint++ ghc-options:+ - -O2+ - -rtsopts+ - -threaded+ - -with-rtsopts=-N++executables:+ loopback:+ source-dirs: examples/loopback+ main: Main.hs+ when:+ - condition: 'flag(build-examples)'+ then:+ dependencies:+ - base >= 4.9 && < 4.10+ - bytestring+ - cacophony >= 0.10+ - pipes+ - pipes-cacophony+ else:+ buildable: False++ ghc-options:+ - -O2+ - -rtsopts+ - -threaded+ - -with-rtsopts=-N++ default-extensions:+ - OverloadedStrings
pipes-cacophony.cabal view
@@ -1,106 +1,79 @@-name: pipes-cacophony-version: 0.4.1-synopsis: Pipes for Noise-secured network connections.-license: PublicDomain-license-file: LICENSE-author: John Galt-maintainer: jgalt@centromere.net-homepage: https://github.com/centromere/pipes-cacophony-bug-reports: https://github.com/centromere/pipes-cacophony/issues-category: Pipes, Cryptography-build-type: Simple-cabal-version: >=1.10-tested-with: GHC == 7.10.3, GHC == 8.0.2-description:- A set of pipes to secure network connections with the- <https://github.com/trevp/noise/blob/master/noise.md Noise> protocol.+-- This file has been generated from package.yaml by hpack version 0.17.0.+--+-- see: https://github.com/sol/hpack +name: pipes-cacophony+version: 0.5.0+synopsis: Pipes for Noise-secured network connections.+description: A set of pipes to secure network connections with the+ <https://github.com/trevp/noise/blob/master/noise.md Noise> protocol.+category: Cryptography+homepage: https://github.com/centromere/pipes-cacophony#readme+bug-reports: https://github.com/centromere/pipes-cacophony/issues+maintainer: John Galt <jgalt@centromere.net>+license: PublicDomain+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10+ extra-source-files:- .travis.yml- README.md- changelog.md- LICENSE- tests/.hlint+ .travis.yml+ changelog.md+ LICENSE+ package.yaml+ README.md+ stack.yaml+ tests/.hlint source-repository head type: git- location: https://github.com/centromere/pipes-cacophony.git------------------------------------------------------------------------------------- FLAGS--flag hlint- description: Build hlint test+ location: https://github.com/centromere/pipes-cacophony flag build-examples- description: Build example executables- default: False+ description: Build examples manual: True--flag llvm default: False- manual: True ------------------------------------------------------------------------------------ LIBRARY- library+ hs-source-dirs:+ src+ default-extensions: OverloadedStrings+ ghc-options: -Wall build-depends:- base >=4.8 && <5,- bytestring,- cacophony >=0.9,- memory,- pipes- hs-source-dirs: src- default-language: Haskell2010+ base >= 4.9 && < 4.10+ , bytestring+ , cacophony >= 0.10+ , pipes exposed-modules:- Pipes.Noise- ghc-options: -Wall -fwarn-tabs-- if flag(llvm)- ghc-options: -fllvm------------------------------------------------------------------------------------- EXAMPLES--executable loopback+ Pipes.Noise+ other-modules:+ Paths_pipes_cacophony default-language: Haskell2010- hs-source-dirs: examples/loopback- main-is: Main.hs +executable loopback+ main-is: Main.hs+ hs-source-dirs:+ examples/loopback+ default-extensions: OverloadedStrings+ ghc-options: -Wall -O2 -rtsopts -threaded -with-rtsopts=-N if flag(build-examples) build-depends:- base >=4.8 && <5,- bytestring,- cacophony >=0.9,- lens,- memory,- pipes,- pipes-cacophony+ base >= 4.9 && < 4.10+ , bytestring+ , cacophony >= 0.10+ , pipes+ , pipes-cacophony else buildable: False-- ghc-options: -threaded -O2 -rtsopts -with-rtsopts=-N -Wall -fwarn-tabs-- if flag(llvm)- ghc-options: -fllvm------------------------------------------------------------------------------------- TESTS+ default-language: Haskell2010 test-suite hlint- type: exitcode-stdio-1.0- main-is: hlint.hs- ghc-options: -Wall -fwarn-tabs- hs-source-dirs: tests+ type: exitcode-stdio-1.0+ main-is: hlint.hs+ hs-source-dirs:+ tests/hlint+ ghc-options: -Wall -O2 -rtsopts -threaded -with-rtsopts=-N+ build-depends:+ base >= 4.9 && < 4.10+ , hlint default-language: Haskell2010-- if !flag(hlint)- buildable: False- else- build-depends:- base >=4.8 && <5,- hlint-- if flag(llvm)- ghc-options: -fllvm
src/Pipes/Noise.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE OverloadedStrings #-} ---------------------------------------------------------------- -- | -- Module : Pipes.Noise@@ -14,16 +13,13 @@ , mkNoisePipes ) where -import Control.Concurrent.MVar (MVar, newMVar, putMVar, takeMVar)-import Control.Exception (SomeException)-import Data.ByteArray (ScrubbedBytes)-import Data.ByteString (ByteString)-import Pipes (Pipe, MonadIO, await, yield, liftIO)+import Data.ByteString (ByteString)+import Pipes (Pipe, await, yield) -import Crypto.Noise.Cipher (Cipher)-import Crypto.Noise.DH (DH)-import Crypto.Noise.Hash (Hash) import Crypto.Noise+import Crypto.Noise.Cipher (Cipher)+import Crypto.Noise.DH (DH)+import Crypto.Noise.Hash (Hash) -- | Pipe used for inbound Noise messages. type InboundNoisePipe = Pipe ByteString ScrubbedBytes@@ -32,39 +28,40 @@ type OutboundNoisePipe = Pipe ScrubbedBytes ByteString -- | Creates a pair of Pipes, the first used for inbound messages and the--- second used for outbound messages.-mkNoisePipes :: (MonadIO m, Cipher c, DH d, Hash h)+-- second used for outbound messages. Note: The handshake for the given+-- 'NoiseState' must be complete. If it is not, this function will return+-- 'Nothing'.+mkNoisePipes :: (Monad m, Cipher c, DH d, Hash h) => NoiseState c d h- -> IO (InboundNoisePipe m (Either SomeException ()),- OutboundNoisePipe m (Either SomeException ()))-mkNoisePipes ns = do- nsmv <- liftIO . newMVar $ ns- return (inboundPipe nsmv, outboundPipe nsmv)+ -> Maybe (InboundNoisePipe m (NoiseResult c d h),+ OutboundNoisePipe m (NoiseResult c d h))+mkNoisePipes ns | handshakeComplete ns = return (inboundPipe ns, outboundPipe ns)+ | otherwise = Nothing -inboundPipe :: (MonadIO m, Cipher c, DH d, Hash h)- => MVar (NoiseState c d h)- -> InboundNoisePipe m (Either SomeException ())-inboundPipe nsmv = do+inboundPipe :: (Monad m, Cipher c, DH d, Hash h)+ => NoiseState c d h+ -> InboundNoisePipe m (NoiseResult c d h)+inboundPipe ns = do msg <- await - ns <- liftIO . takeMVar $ nsmv- case readMessage ns msg of- Left e -> return . Left $ e- Right (pt, ns') -> do- liftIO . putMVar nsmv $ ns'+ let result = readMessage (convert msg) ns+ case result of+ NoiseResultMessage pt ns' -> do yield pt- inboundPipe nsmv+ inboundPipe ns'+ NoiseResultNeedPSK _ -> return result+ NoiseResultException _ -> return result -outboundPipe :: (MonadIO m, Cipher c, DH d, Hash h)- => MVar (NoiseState c d h)- -> OutboundNoisePipe m (Either SomeException ())-outboundPipe nsmv = do+outboundPipe :: (Monad m, Cipher c, DH d, Hash h)+ => NoiseState c d h+ -> OutboundNoisePipe m (NoiseResult c d h)+outboundPipe ns = do msg <- await - ns <- liftIO . takeMVar $ nsmv- case writeMessage ns msg of- Left e -> return . Left $ e- Right (ct, ns') -> do- liftIO . putMVar nsmv $ ns'- yield ct- outboundPipe nsmv+ let result = writeMessage msg ns+ case result of+ NoiseResultMessage ct ns' -> do+ yield . convert $ ct+ outboundPipe ns'+ NoiseResultNeedPSK _ -> return result+ NoiseResultException _ -> return result
+ stack.yaml view
@@ -0,0 +1,6 @@+resolver: lts-8.20+packages:+ - '.'+extra-deps: []+flags: {}+extra-package-dbs: []
− tests/hlint.hs
@@ -1,16 +0,0 @@-module Main where--import Control.Monad-import Language.Haskell.HLint-import System.Environment-import System.Exit--main :: IO ()-main = do- args <- getArgs- hints <- hlint $ [ "src"- , "tests"- , "--hint=tests/.hlint"- , "--cpp-define=HLINT"- ] `mappend` args- unless (null hints) exitFailure
+ tests/hlint/hlint.hs view
@@ -0,0 +1,16 @@+module Main where++import Control.Monad+import Language.Haskell.HLint+import System.Environment+import System.Exit++main :: IO ()+main = do+ args <- getArgs+ hints <- hlint $ [ "src"+ , "tests"+ , "--hint=tests/.hlint"+ , "--cpp-define=HLINT"+ ] `mappend` args+ unless (null hints) exitFailure