diff options
Diffstat (limited to 'lib/PEM.hs')
-rw-r--r-- | lib/PEM.hs | 9 |
1 files changed, 0 insertions, 9 deletions
@@ -1,5 +1,4 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | {-# LANGUAGE CPP #-} | ||
3 | module PEM where | 2 | module PEM where |
4 | 3 | ||
5 | import Data.Monoid | 4 | import Data.Monoid |
@@ -7,12 +6,8 @@ import qualified Data.ByteString.Lazy as LW | |||
7 | import qualified Data.ByteString.Lazy.Char8 as L | 6 | import qualified Data.ByteString.Lazy.Char8 as L |
8 | import Control.Monad | 7 | import Control.Monad |
9 | import Control.Applicative | 8 | import Control.Applicative |
10 | #if defined(VERSION_memory) | ||
11 | import qualified Data.ByteString.Char8 as S8 | 9 | import qualified Data.ByteString.Char8 as S8 |
12 | import Data.ByteArray.Encoding | 10 | import Data.ByteArray.Encoding |
13 | #elif defined(VERSION_dataenc) | ||
14 | import qualified Codec.Binary.Base64 as Base64 | ||
15 | #endif | ||
16 | import ScanningParser | 11 | import ScanningParser |
17 | import FunctorToMaybe | 12 | import FunctorToMaybe |
18 | data PEMBlob = PEMBlob { pemType :: L.ByteString | 13 | data PEMBlob = PEMBlob { pemType :: L.ByteString |
@@ -36,11 +31,7 @@ pemParser mtyp = ScanningParser (maybe fndany fndtyp mtyp) pbdy | |||
36 | pbdy typ xs = (mblob, drop 1 rs) | 31 | pbdy typ xs = (mblob, drop 1 rs) |
37 | where | 32 | where |
38 | (ys,rs) = span (/="-----END " <> typ <> "-----") xs | 33 | (ys,rs) = span (/="-----END " <> typ <> "-----") xs |
39 | #if defined(VERSION_memory) | ||
40 | mblob = PEMBlob typ <$> LW.fromStrict <$> (functorToMaybe $ convertFromBase Base64 $ L.toStrict dta) | 34 | mblob = PEMBlob typ <$> LW.fromStrict <$> (functorToMaybe $ convertFromBase Base64 $ L.toStrict dta) |
41 | #elif defined(VERSION_dataenc) | ||
42 | mblob = PEMBlob typ <$> LW.pack <$> Base64.decode (L.unpack dta) | ||
43 | #endif | ||
44 | dta = case ys of | 35 | dta = case ys of |
45 | [] -> "" | 36 | [] -> "" |
46 | dta_lines -> L.concat dta_lines | 37 | dta_lines -> L.concat dta_lines |