-- |
-- 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
showList :: [PEM] -> ShowS
$cshowList :: [PEM] -> ShowS
show :: PEM -> String
$cshow :: PEM -> String
showsPrec :: Int -> PEM -> ShowS
$cshowsPrec :: Int -> PEM -> ShowS
Show,PEM -> PEM -> Bool
(PEM -> PEM -> Bool) -> (PEM -> PEM -> Bool) -> Eq PEM
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PEM -> PEM -> Bool
$c/= :: PEM -> PEM -> Bool
== :: PEM -> PEM -> Bool
$c== :: 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) () -> () -> ()
`seq` [(String, ByteString)] -> ()
forall a a. NormalForm a => [(a, a)] -> ()
nfLbs (PEM -> [(String, ByteString)]
pemHeader PEM
pem) () -> () -> ()
`seq` PEM -> ByteString
pemContent PEM
pem ByteString -> () -> ()
`seq` ()
      where
        nfLbs :: [(a, a)] -> ()
nfLbs []         = ()
        nfLbs ((a
s,a
bs):[(a, a)]
l) = a -> ()
forall a. NormalForm a => a -> ()
toNormalForm a
s () -> () -> ()
`seq` a
bs a -> () -> ()
`seq` [(a, a)] -> ()
nfLbs [(a, a)]
l