crypton-pem 0.2.5 → 0.3.0
raw patch · 5 files changed
+104/−80 lines, 5 filesdep +base64dep +textdep −basementdep −memoryPVP ok
version bump matches the API change (PVP)
Dependencies added: base64, text
Dependencies removed: basement, memory
API changes (from Hackage documentation)
Files
- CHANGELOG.md +8/−0
- crypton-pem.cabal +62/−62
- src/Data/PEM/Parser.hs +19/−5
- src/Data/PEM/Types.hs +0/−11
- src/Data/PEM/Writer.hs +15/−2
CHANGELOG.md view
@@ -6,6 +6,14 @@ and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). +## 0.3.0 + +* Change default language to `Haskell2010`. +* Remove deprecated `PEM` instance of type class `NormalForm` and the direct + dependency on the `basement` package. +* Depend on the `base64` package, remove direct dependency on the `memory` + package and the indirect dependency on the `basement` package. + ## 0.2.5 * Move library modules to directory `src`.
crypton-pem.cabal view
@@ -1,63 +1,63 @@ cabal-version: 1.18 ---- This file has been generated from package.yaml by hpack version 0.38.1.------ see: https://github.com/sol/hpack--name: crypton-pem-version: 0.2.5-synopsis: Privacy Enhanced Mail (PEM) file format reader and writer.-description: A library to read and write files in the Privacy Enhanced Mail (PEM) format.-category: Data-stability: experimental-homepage: http://github.com/mpilgrem/crypton-pem-bug-reports: https://github.com/mpilgrem/crypton-pem/issues-author: Vincent Hanquez <vincent@snarc.org>-maintainer: Mike Pilgrem <public@pilgrem.com>,- Kazu Yamamoto <kazu@iij.ad.jp>-copyright: Vincent Hanquez <vincent@snarc.org>-license: BSD3-license-file: LICENSE-build-type: Simple-extra-doc-files:- CHANGELOG.md- README.md--source-repository head- type: git- location: https://github.com/mpilgrem/crypton-pem--library- exposed-modules:- Data.PEM- other-modules:- Data.PEM.Parser- Data.PEM.Types- Data.PEM.Writer- hs-source-dirs:- src- ghc-options: -Wall- build-depends:- base >=3 && <5- , basement- , bytestring- , deepseq- , memory- default-language: Haskell98--test-suite test-pem- type: exitcode-stdio-1.0- main-is: Main.hs- hs-source-dirs:- test- ghc-options: -Wall- build-depends:- HUnit- , QuickCheck >=2.4.0.1- , base- , bytestring- , crypton-pem- , test-framework >=0.3.3- , test-framework-hunit- , test-framework-quickcheck2- default-language: Haskell98+ +-- This file has been generated from package.yaml by hpack version 0.38.1. +-- +-- see: https://github.com/sol/hpack + +name: crypton-pem +version: 0.3.0 +synopsis: Privacy Enhanced Mail (PEM) file format reader and writer. +description: A library to read and write files in the Privacy Enhanced Mail (PEM) format. +category: Data +stability: experimental +homepage: http://github.com/mpilgrem/crypton-pem +bug-reports: https://github.com/mpilgrem/crypton-pem/issues +author: Vincent Hanquez <vincent@snarc.org> +maintainer: Mike Pilgrem <public@pilgrem.com>, + Kazu Yamamoto <kazu@iij.ad.jp> +copyright: Vincent Hanquez <vincent@snarc.org> +license: BSD3 +license-file: LICENSE +build-type: Simple +extra-doc-files: + CHANGELOG.md + README.md + +source-repository head + type: git + location: https://github.com/mpilgrem/crypton-pem + +library + exposed-modules: + Data.PEM + other-modules: + Data.PEM.Parser + Data.PEM.Types + Data.PEM.Writer + hs-source-dirs: + src + ghc-options: -Wall + build-depends: + base >=3 && <5 + , base64 >=0.4.2.2 + , bytestring + , deepseq + , text + default-language: Haskell2010 + +test-suite test-pem + type: exitcode-stdio-1.0 + main-is: Main.hs + hs-source-dirs: + test + ghc-options: -Wall + build-depends: + HUnit + , QuickCheck >=2.4.0.1 + , base + , bytestring + , crypton-pem + , test-framework >=0.3.3 + , test-framework-hunit + , test-framework-quickcheck2 + default-language: Haskell2010
src/Data/PEM/Parser.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {- | @@ -18,17 +19,28 @@ , pemParseLBS ) where -import qualified Data.ByteArray as BA -import Data.ByteArray.Encoding ( Base(..), convertFromBase ) import Data.ByteString ( ByteString ) +import qualified Data.ByteString as B +#if MIN_VERSION_base64(1,0,0) +import Data.ByteString.Base64 ( decodeBase64Untyped ) +#else +import Data.ByteString.Base64 ( decodeBase64 ) +#endif import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.Char8 as LC import Data.Either ( partitionEithers ) import Data.PEM.Types ( PEM (..) ) +import qualified Data.Text as T type Line = L.ByteString +-- | A helper function while base64 < 1.0 is supported. +#if !MIN_VERSION_base64(1,0,0) +decodeBase64Untyped :: ByteString -> Either T.Text ByteString +decodeBase64Untyped = decodeBase64 +#endif + parseOnePEM :: [Line] -> Either (Maybe String) (PEM, [Line]) parseOnePEM = findPem where @@ -66,17 +78,19 @@ [] -> Left $ Just "invalid PEM: no end marker found" (l:ls) -> case endMarker `prefixEat` l of Nothing -> - case convertFromBase Base64 $ L.toStrict l of - Left err -> Left $ Just ("invalid PEM: decoding failed: " ++ err) + case decodeBase64Untyped $ L.toStrict l of + Left err -> + Left $ Just ("invalid PEM: decoding failed: " ++ T.unpack err) Right content -> getPemContent name hdrs (content : contentLines) ls Just n -> getPemName (finalizePem name hdrs contentLines) n ls + finalizePem name hdrs contentLines nameEnd lbs | nameEnd /= name = Left $ Just "invalid PEM: end name doesn't match start name" | otherwise = let pem = PEM { pemName = name , pemHeader = hdrs - , pemContent = BA.concat $ reverse contentLines } + , pemContent = B.concat $ reverse contentLines } in Right (pem, lbs) prefixEat prefix x =
src/Data/PEM/Types.hs view
@@ -13,7 +13,6 @@ ( PEM (..) ) where -import Basement.NormalForm ( NormalForm (..) ) import Control.DeepSeq ( NFData (..) ) import Data.ByteString ( ByteString ) import GHC.Generics ( Generic ) @@ -29,13 +28,3 @@ -- ^ Binary content of the section. } deriving (Eq, Generic, NFData, Show) - --- | The t'PEM' instance of 'NormalForm' is deprecated and will be removed from --- a future version of this package. See the 'NFData' type class exported by --- "Control.DeepSeq" of the @deepseq@ GHC boot package. -instance NormalForm PEM where - toNormalForm pem = - toNormalForm (pemName pem) `seq` nfLbs (pemHeader pem) `seq` pemContent pem `seq` () - where - nfLbs [] = () - nfLbs ((s,bs):l) = toNormalForm s `seq` bs `seq` nfLbs l
src/Data/PEM/Writer.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {- | @@ -13,13 +14,25 @@ , pemWriteLBS ) where -import Data.ByteArray.Encoding ( Base (..), convertToBase ) + +#if MIN_VERSION_base64(1,0,0) +import Data.Base64.Types ( extractBase64 ) +#endif import Data.ByteString ( ByteString ) import qualified Data.ByteString as B +import Data.ByteString.Base64 ( encodeBase64' ) import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy as L import Data.PEM.Types ( PEM (..) ) +-- | A helper function while base64 < 1.0 is supported. +encodeBase64 :: ByteString -> ByteString +#if MIN_VERSION_base64(1,0,0) +encodeBase64 = extractBase64 . encodeBase64' +#else +encodeBase64 = encodeBase64' +#endif + -- | Write a t'PEM' to a lazy 'Data.ByteString.Lazy.ByteString'. pemWrite :: PEM -> L.ByteString pemWrite pem = L.fromChunks ([begin, header] ++ section ++ [end]) @@ -36,7 +49,7 @@ toHeader (k,v) = [ BC.pack k, ":", v, "\n" ] -- expect only ASCII. need to find a type to represent it. sectionName = BC.pack $ pemName pem - encodeLine l = convertToBase Base64 l `B.append` "\n" + encodeLine l = encodeBase64 l `B.append` "\n" splitChunks b | B.length b > 48 = let (x,y) = B.splitAt 48 b in x : splitChunks y