-- |
-- Module      : Data.PEM.Types
-- License     : BSD-style
-- Maintainer  : Vincent Hanquez <vincent@snarc.org>
-- Stability   : experimental
-- Portability : portable
--
module Data.PEM.Types where

import Data.ByteString (ByteString)
import Basement.NormalForm

-- | Represent one PEM section
--
-- for now headers are not serialized at all.
-- this is just available here as a placeholder for a later implementation.
data PEM = PEM
    { PEM -> String
pemName    :: String                 -- ^ the name of the section, found after the dash BEGIN tag.
    , PEM -> [(String, ByteString)]
pemHeader  :: [(String, ByteString)] -- ^ optionals key value pair header
    , PEM -> ByteString
pemContent :: ByteString             -- ^ binary content of the section
    } deriving (Int -> PEM -> ShowS
[PEM] -> ShowS
PEM -> String
(Int -> PEM -> ShowS)
-> (PEM -> String) -> ([PEM] -> ShowS) -> Show PEM
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PEM -> ShowS
showsPrec :: Int -> PEM -> ShowS
$cshow :: PEM -> String
show :: PEM -> String
$cshowList :: [PEM] -> ShowS
showList :: [PEM] -> ShowS
Show,PEM -> PEM -> Bool
(PEM -> PEM -> Bool) -> (PEM -> PEM -> Bool) -> Eq PEM
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PEM -> PEM -> Bool
== :: PEM -> PEM -> Bool
$c/= :: PEM -> PEM -> Bool
/= :: PEM -> PEM -> Bool
Eq)

instance NormalForm PEM where
    toNormalForm :: PEM -> ()
toNormalForm PEM
pem =
        String -> ()
forall a. NormalForm a => a -> ()
toNormalForm (PEM -> String
pemName PEM
pem) () -> () -> ()
forall a b. a -> b -> b
`seq` [(String, ByteString)] -> ()
forall {a} {a}. NormalForm a => [(a, a)] -> ()
nfLbs (PEM -> [(String, ByteString)]
pemHeader PEM
pem) () -> () -> ()
forall a b. a -> b -> b
`seq` PEM -> ByteString
pemContent PEM
pem ByteString -> () -> ()
forall a b. a -> b -> b
`seq` ()
      where
        nfLbs :: [(a, a)] -> ()
nfLbs []         = ()
        nfLbs ((a
s,a
bs):[(a, a)]
l) = a -> ()
forall a. NormalForm a => a -> ()
toNormalForm a
s () -> () -> ()
forall a b. a -> b -> b
`seq` a
bs a -> () -> ()
forall a b. a -> b -> b
`seq` [(a, a)] -> ()
nfLbs [(a, a)]
l