{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
-- |
-- XML Encryption Syntax and Processing
--
-- <http://www.w3.org/TR/xmlenc-core1/> (selected portions)
module SAML2.XML.Encryption where

import SAML2.XML
import qualified Text.XML.HXT.Arrow.Pickle.Xml.Invertible as XP
import qualified SAML2.XML.Schema as XS
import qualified SAML2.XML.Signature.Types as DS

nsFrag :: String -> URI
nsFrag :: String -> URI
nsFrag = String -> String -> String -> String -> URI
httpURI String
"www.w3.org" String
"/2001/04/xmlenc" String
"" (String -> URI) -> (String -> String) -> String -> URI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char
'#'Char -> String -> String
forall a. a -> [a] -> [a]
:)

ns :: Namespace 
ns :: Namespace
ns = String -> URI -> Namespace
mkNamespace String
"xenc" (URI -> Namespace) -> URI -> Namespace
forall a b. (a -> b) -> a -> b
$ String -> URI
nsFrag String
""

xpElem :: String -> XP.PU a -> XP.PU a
xpElem :: forall a. String -> PU a -> PU a
xpElem = Namespace -> String -> PU a -> PU a
forall a. Namespace -> String -> PU a -> PU a
xpTrimElemNS Namespace
ns

-- |§3.1
data EncryptedType = EncryptedType
  { EncryptedType -> Maybe String
encryptedID :: Maybe ID
  , EncryptedType -> Maybe URI
encryptedType :: Maybe AnyURI
  , EncryptedType -> Maybe String
encryptedMimeType :: Maybe XString
  , EncryptedType -> Maybe (IdentifiedURI EncodingAlgorithm)
encryptedEncoding :: Maybe (IdentifiedURI DS.EncodingAlgorithm)
  , EncryptedType -> Maybe EncryptionMethod
encryptedEncryptionMethod :: Maybe EncryptionMethod
  , EncryptedType -> Maybe KeyInfo
encryptedKeyInfo :: Maybe DS.KeyInfo
  , EncryptedType -> CipherData
encryptedCipherData :: CipherData
  , EncryptedType -> Maybe EncryptionProperties
encryptedEncryptionProperties :: Maybe EncryptionProperties
  } deriving (EncryptedType -> EncryptedType -> Bool
(EncryptedType -> EncryptedType -> Bool)
-> (EncryptedType -> EncryptedType -> Bool) -> Eq EncryptedType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncryptedType -> EncryptedType -> Bool
== :: EncryptedType -> EncryptedType -> Bool
$c/= :: EncryptedType -> EncryptedType -> Bool
/= :: EncryptedType -> EncryptedType -> Bool
Eq, Int -> EncryptedType -> String -> String
[EncryptedType] -> String -> String
EncryptedType -> String
(Int -> EncryptedType -> String -> String)
-> (EncryptedType -> String)
-> ([EncryptedType] -> String -> String)
-> Show EncryptedType
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> EncryptedType -> String -> String
showsPrec :: Int -> EncryptedType -> String -> String
$cshow :: EncryptedType -> String
show :: EncryptedType -> String
$cshowList :: [EncryptedType] -> String -> String
showList :: [EncryptedType] -> String -> String
Show)

instance XP.XmlPickler EncryptedType where
  xpickle :: PU EncryptedType
xpickle = [XP.biCase|(((((((i, t), m), e), c), k), d), p) <-> EncryptedType i t m e c k d p|]
    Bijection
  (->)
  (((((((Maybe String, Maybe URI), Maybe String),
       Maybe (IdentifiedURI EncodingAlgorithm)),
      Maybe EncryptionMethod),
     Maybe KeyInfo),
    CipherData),
   Maybe EncryptionProperties)
  EncryptedType
-> PU
     (((((((Maybe String, Maybe URI), Maybe String),
          Maybe (IdentifiedURI EncodingAlgorithm)),
         Maybe EncryptionMethod),
        Maybe KeyInfo),
       CipherData),
      Maybe EncryptionProperties)
-> PU EncryptedType
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$<  (String -> PU String -> PU (Maybe String)
forall a. String -> PU a -> PU (Maybe a)
XP.xpAttrImplied String
"Id" PU String
XS.xpID
      PU (Maybe String) -> PU (Maybe URI) -> PU (Maybe String, Maybe URI)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< String -> PU URI -> PU (Maybe URI)
forall a. String -> PU a -> PU (Maybe a)
XP.xpAttrImplied String
"Type" PU URI
XS.xpAnyURI
      PU (Maybe String, Maybe URI)
-> PU (Maybe String)
-> PU ((Maybe String, Maybe URI), Maybe String)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< String -> PU String -> PU (Maybe String)
forall a. String -> PU a -> PU (Maybe a)
XP.xpAttrImplied String
"MimeType" PU String
XS.xpString
      PU ((Maybe String, Maybe URI), Maybe String)
-> PU (Maybe (IdentifiedURI EncodingAlgorithm))
-> PU
     (((Maybe String, Maybe URI), Maybe String),
      Maybe (IdentifiedURI EncodingAlgorithm))
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< String
-> PU (IdentifiedURI EncodingAlgorithm)
-> PU (Maybe (IdentifiedURI EncodingAlgorithm))
forall a. String -> PU a -> PU (Maybe a)
XP.xpAttrImplied String
"Encoding" PU (IdentifiedURI EncodingAlgorithm)
forall a. XmlPickler a => PU a
XP.xpickle
      PU
  (((Maybe String, Maybe URI), Maybe String),
   Maybe (IdentifiedURI EncodingAlgorithm))
-> PU (Maybe EncryptionMethod)
-> PU
     ((((Maybe String, Maybe URI), Maybe String),
       Maybe (IdentifiedURI EncodingAlgorithm)),
      Maybe EncryptionMethod)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU EncryptionMethod -> PU (Maybe EncryptionMethod)
forall a. PU a -> PU (Maybe a)
XP.xpOption PU EncryptionMethod
forall a. XmlPickler a => PU a
XP.xpickle
      PU
  ((((Maybe String, Maybe URI), Maybe String),
    Maybe (IdentifiedURI EncodingAlgorithm)),
   Maybe EncryptionMethod)
-> PU (Maybe KeyInfo)
-> PU
     (((((Maybe String, Maybe URI), Maybe String),
        Maybe (IdentifiedURI EncodingAlgorithm)),
       Maybe EncryptionMethod),
      Maybe KeyInfo)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU KeyInfo -> PU (Maybe KeyInfo)
forall a. PU a -> PU (Maybe a)
XP.xpOption PU KeyInfo
forall a. XmlPickler a => PU a
XP.xpickle
      PU
  (((((Maybe String, Maybe URI), Maybe String),
     Maybe (IdentifiedURI EncodingAlgorithm)),
    Maybe EncryptionMethod),
   Maybe KeyInfo)
-> PU CipherData
-> PU
     ((((((Maybe String, Maybe URI), Maybe String),
         Maybe (IdentifiedURI EncodingAlgorithm)),
        Maybe EncryptionMethod),
       Maybe KeyInfo),
      CipherData)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU CipherData
forall a. XmlPickler a => PU a
XP.xpickle
      PU
  ((((((Maybe String, Maybe URI), Maybe String),
      Maybe (IdentifiedURI EncodingAlgorithm)),
     Maybe EncryptionMethod),
    Maybe KeyInfo),
   CipherData)
-> PU (Maybe EncryptionProperties)
-> PU
     (((((((Maybe String, Maybe URI), Maybe String),
          Maybe (IdentifiedURI EncodingAlgorithm)),
         Maybe EncryptionMethod),
        Maybe KeyInfo),
       CipherData),
      Maybe EncryptionProperties)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU EncryptionProperties -> PU (Maybe EncryptionProperties)
forall a. PU a -> PU (Maybe a)
XP.xpOption PU EncryptionProperties
forall a. XmlPickler a => PU a
XP.xpickle)

-- |§3.2
data EncryptionMethod = EncryptionMethod
  { EncryptionMethod -> IdentifiedURI EncryptionAlgorithm
encryptionAlgorithm :: IdentifiedURI EncryptionAlgorithm
  , EncryptionMethod -> Maybe Int
encryptionKeySize :: Maybe Int
  , EncryptionMethod -> Maybe Base64Binary
encryptionOAEPparams :: Maybe XS.Base64Binary
  , EncryptionMethod -> Maybe DigestMethod
encryptionDigestMethod :: Maybe DS.DigestMethod
  , EncryptionMethod -> Nodes
encryption :: Nodes
  } deriving (EncryptionMethod -> EncryptionMethod -> Bool
(EncryptionMethod -> EncryptionMethod -> Bool)
-> (EncryptionMethod -> EncryptionMethod -> Bool)
-> Eq EncryptionMethod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncryptionMethod -> EncryptionMethod -> Bool
== :: EncryptionMethod -> EncryptionMethod -> Bool
$c/= :: EncryptionMethod -> EncryptionMethod -> Bool
/= :: EncryptionMethod -> EncryptionMethod -> Bool
Eq, Int -> EncryptionMethod -> String -> String
[EncryptionMethod] -> String -> String
EncryptionMethod -> String
(Int -> EncryptionMethod -> String -> String)
-> (EncryptionMethod -> String)
-> ([EncryptionMethod] -> String -> String)
-> Show EncryptionMethod
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> EncryptionMethod -> String -> String
showsPrec :: Int -> EncryptionMethod -> String -> String
$cshow :: EncryptionMethod -> String
show :: EncryptionMethod -> String
$cshowList :: [EncryptionMethod] -> String -> String
showList :: [EncryptionMethod] -> String -> String
Show)

xpEncryptionMethodType :: XP.PU EncryptionMethod
xpEncryptionMethodType :: PU EncryptionMethod
xpEncryptionMethodType =
  [XP.biCase|((((a, s), p), d), x) <-> EncryptionMethod a s p d x|] 
  Bijection
  (->)
  ((((IdentifiedURI EncryptionAlgorithm, Maybe Int),
     Maybe Base64Binary),
    Maybe DigestMethod),
   Nodes)
  EncryptionMethod
-> PU
     ((((IdentifiedURI EncryptionAlgorithm, Maybe Int),
        Maybe Base64Binary),
       Maybe DigestMethod),
      Nodes)
-> PU EncryptionMethod
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$< (String
-> PU (IdentifiedURI EncryptionAlgorithm)
-> PU (IdentifiedURI EncryptionAlgorithm)
forall a. String -> PU a -> PU a
XP.xpAttr String
"Algorithm" PU (IdentifiedURI EncryptionAlgorithm)
forall a. XmlPickler a => PU a
XP.xpickle
    PU (IdentifiedURI EncryptionAlgorithm)
-> PU (Maybe Int)
-> PU (IdentifiedURI EncryptionAlgorithm, Maybe Int)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU Int -> PU (Maybe Int)
forall a. PU a -> PU (Maybe a)
XP.xpOption (String -> PU Int -> PU Int
forall a. String -> PU a -> PU a
xpElem String
"KeySize" PU Int
forall a. XmlPickler a => PU a
XP.xpickle)
    PU (IdentifiedURI EncryptionAlgorithm, Maybe Int)
-> PU (Maybe Base64Binary)
-> PU
     ((IdentifiedURI EncryptionAlgorithm, Maybe Int),
      Maybe Base64Binary)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU Base64Binary -> PU (Maybe Base64Binary)
forall a. PU a -> PU (Maybe a)
XP.xpOption (String -> PU Base64Binary -> PU Base64Binary
forall a. String -> PU a -> PU a
xpElem String
"OAEPparams" PU Base64Binary
XS.xpBase64Binary)
    PU
  ((IdentifiedURI EncryptionAlgorithm, Maybe Int),
   Maybe Base64Binary)
-> PU (Maybe DigestMethod)
-> PU
     (((IdentifiedURI EncryptionAlgorithm, Maybe Int),
       Maybe Base64Binary),
      Maybe DigestMethod)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU DigestMethod -> PU (Maybe DigestMethod)
forall a. PU a -> PU (Maybe a)
XP.xpOption PU DigestMethod
forall a. XmlPickler a => PU a
XP.xpickle
    PU
  (((IdentifiedURI EncryptionAlgorithm, Maybe Int),
    Maybe Base64Binary),
   Maybe DigestMethod)
-> PU Nodes
-> PU
     ((((IdentifiedURI EncryptionAlgorithm, Maybe Int),
        Maybe Base64Binary),
       Maybe DigestMethod),
      Nodes)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU Nodes
XP.xpAnyCont)

instance XP.XmlPickler EncryptionMethod where
  xpickle :: PU EncryptionMethod
xpickle = String -> PU EncryptionMethod -> PU EncryptionMethod
forall a. String -> PU a -> PU a
xpElem String
"EncryptionMethod" PU EncryptionMethod
xpEncryptionMethodType

-- |§3.3
data CipherData
  = CipherValue XS.Base64Binary
  | CipherReference
    { CipherData -> URI
cipherURI :: AnyURI
    , CipherData -> List1 Transform
cipherTransforms :: List1 DS.Transform
    }
  deriving (CipherData -> CipherData -> Bool
(CipherData -> CipherData -> Bool)
-> (CipherData -> CipherData -> Bool) -> Eq CipherData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CipherData -> CipherData -> Bool
== :: CipherData -> CipherData -> Bool
$c/= :: CipherData -> CipherData -> Bool
/= :: CipherData -> CipherData -> Bool
Eq, Int -> CipherData -> String -> String
[CipherData] -> String -> String
CipherData -> String
(Int -> CipherData -> String -> String)
-> (CipherData -> String)
-> ([CipherData] -> String -> String)
-> Show CipherData
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> CipherData -> String -> String
showsPrec :: Int -> CipherData -> String -> String
$cshow :: CipherData -> String
show :: CipherData -> String
$cshowList :: [CipherData] -> String -> String
showList :: [CipherData] -> String -> String
Show)

instance XP.XmlPickler CipherData where
  xpickle :: PU CipherData
xpickle = String -> PU CipherData -> PU CipherData
forall a. String -> PU a -> PU a
xpElem String
"CipherData" (PU CipherData -> PU CipherData) -> PU CipherData -> PU CipherData
forall a b. (a -> b) -> a -> b
$
    [XP.biCase|
      Left b <-> CipherValue b
      Right (u, t) <-> CipherReference u t |]
    Bijection
  (->) (Either Base64Binary (URI, List1 Transform)) CipherData
-> PU (Either Base64Binary (URI, List1 Transform)) -> PU CipherData
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$<  (String -> PU Base64Binary -> PU Base64Binary
forall a. String -> PU a -> PU a
xpElem String
"CipherValue" PU Base64Binary
XS.xpBase64Binary
      PU Base64Binary
-> PU (URI, List1 Transform)
-> PU (Either Base64Binary (URI, List1 Transform))
forall a b. PU a -> PU b -> PU (Either a b)
forall (f :: * -> *) a b.
MonoidalAlt f =>
f a -> f b -> f (Either a b)
XP.>|< String -> PU (URI, List1 Transform) -> PU (URI, List1 Transform)
forall a. String -> PU a -> PU a
xpElem String
"CipherReference"
              (String -> PU URI -> PU URI
forall a. String -> PU a -> PU a
XP.xpAttr String
"URI" PU URI
XS.xpAnyURI
        PU URI -> PU (List1 Transform) -> PU (URI, List1 Transform)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< String -> PU (List1 Transform) -> PU (List1 Transform)
forall a. String -> PU a -> PU a
xpElem String
"Transforms" (PU Transform -> PU (List1 Transform)
forall a. PU a -> PU (List1 a)
xpList1 PU Transform
forall a. XmlPickler a => PU a
XP.xpickle)))

-- |§3.4
newtype EncryptedData = EncryptedData{ EncryptedData -> EncryptedType
encryptedData :: EncryptedType }
  deriving (EncryptedData -> EncryptedData -> Bool
(EncryptedData -> EncryptedData -> Bool)
-> (EncryptedData -> EncryptedData -> Bool) -> Eq EncryptedData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncryptedData -> EncryptedData -> Bool
== :: EncryptedData -> EncryptedData -> Bool
$c/= :: EncryptedData -> EncryptedData -> Bool
/= :: EncryptedData -> EncryptedData -> Bool
Eq, Int -> EncryptedData -> String -> String
[EncryptedData] -> String -> String
EncryptedData -> String
(Int -> EncryptedData -> String -> String)
-> (EncryptedData -> String)
-> ([EncryptedData] -> String -> String)
-> Show EncryptedData
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> EncryptedData -> String -> String
showsPrec :: Int -> EncryptedData -> String -> String
$cshow :: EncryptedData -> String
show :: EncryptedData -> String
$cshowList :: [EncryptedData] -> String -> String
showList :: [EncryptedData] -> String -> String
Show)

instance XP.XmlPickler EncryptedData where
  xpickle :: PU EncryptedData
xpickle = String -> PU EncryptedData -> PU EncryptedData
forall a. String -> PU a -> PU a
xpElem String
"EncryptedData" (PU EncryptedData -> PU EncryptedData)
-> PU EncryptedData -> PU EncryptedData
forall a b. (a -> b) -> a -> b
$
    [XP.biCase|e <-> EncryptedData e|] 
    Bijection (->) EncryptedType EncryptedData
-> PU EncryptedType -> PU EncryptedData
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$< PU EncryptedType
forall a. XmlPickler a => PU a
XP.xpickle

-- |§3.5.1
data EncryptedKey = EncryptedKey
  { EncryptedKey -> EncryptedType
encryptedKey :: !EncryptedType
  , EncryptedKey -> Maybe String
encryptedKeyRecipient :: Maybe XString
  , EncryptedKey -> [Reference]
encryptedKeyReferenceList :: [Reference] -- ^empty for missing
  , EncryptedKey -> Maybe String
encryptedKeyCarriedKeyName :: Maybe XString
  } deriving (EncryptedKey -> EncryptedKey -> Bool
(EncryptedKey -> EncryptedKey -> Bool)
-> (EncryptedKey -> EncryptedKey -> Bool) -> Eq EncryptedKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncryptedKey -> EncryptedKey -> Bool
== :: EncryptedKey -> EncryptedKey -> Bool
$c/= :: EncryptedKey -> EncryptedKey -> Bool
/= :: EncryptedKey -> EncryptedKey -> Bool
Eq, Int -> EncryptedKey -> String -> String
[EncryptedKey] -> String -> String
EncryptedKey -> String
(Int -> EncryptedKey -> String -> String)
-> (EncryptedKey -> String)
-> ([EncryptedKey] -> String -> String)
-> Show EncryptedKey
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> EncryptedKey -> String -> String
showsPrec :: Int -> EncryptedKey -> String -> String
$cshow :: EncryptedKey -> String
show :: EncryptedKey -> String
$cshowList :: [EncryptedKey] -> String -> String
showList :: [EncryptedKey] -> String -> String
Show)

instance XP.XmlPickler EncryptedKey where
  xpickle :: PU EncryptedKey
xpickle = String -> PU EncryptedKey -> PU EncryptedKey
forall a. String -> PU a -> PU a
xpElem String
"EncryptedKey" (PU EncryptedKey -> PU EncryptedKey)
-> PU EncryptedKey -> PU EncryptedKey
forall a b. (a -> b) -> a -> b
$
    [XP.biCase|
      (e, ((r, Nothing), n)) <-> EncryptedKey e r [] n
      (e, ((r, Just l), n)) <-> EncryptedKey e r l n
    |] 
    Bijection
  (->)
  (EncryptedType, ((Maybe String, Maybe [Reference]), Maybe String))
  EncryptedKey
-> PU
     (EncryptedType, ((Maybe String, Maybe [Reference]), Maybe String))
-> PU EncryptedKey
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$< (PU EncryptedType
forall a. XmlPickler a => PU a
XP.xpickle
      PU EncryptedType
-> PU ((Maybe String, Maybe [Reference]), Maybe String)
-> PU
     (EncryptedType, ((Maybe String, Maybe [Reference]), Maybe String))
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*<  (String -> PU String -> PU (Maybe String)
forall a. String -> PU a -> PU (Maybe a)
XP.xpAttrImplied String
"Recipient" PU String
XS.xpString
        PU (Maybe String)
-> PU (Maybe [Reference]) -> PU (Maybe String, Maybe [Reference])
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU [Reference] -> PU (Maybe [Reference])
forall a. PU a -> PU (Maybe a)
XP.xpOption (String -> PU [Reference] -> PU [Reference]
forall a. String -> PU a -> PU a
xpElem String
"ReferenceList" (PU [Reference] -> PU [Reference])
-> PU [Reference] -> PU [Reference]
forall a b. (a -> b) -> a -> b
$ PU Reference -> PU [Reference]
forall a. PU a -> PU [a]
XP.xpList1 PU Reference
forall a. XmlPickler a => PU a
XP.xpickle)
        PU (Maybe String, Maybe [Reference])
-> PU (Maybe String)
-> PU ((Maybe String, Maybe [Reference]), Maybe String)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU String -> PU (Maybe String)
forall a. PU a -> PU (Maybe a)
XP.xpOption (String -> PU String -> PU String
forall a. String -> PU a -> PU a
xpElem String
"CarriedKeyName" PU String
XS.xpString)))

-- |§3.6
data Reference
  = DataReference
    { Reference -> URI
referenceURI :: URI
    , Reference -> Nodes
reference :: Nodes
    }
  | KeyReference
    { referenceURI :: URI
    , reference :: Nodes
    }
  deriving (Reference -> Reference -> Bool
(Reference -> Reference -> Bool)
-> (Reference -> Reference -> Bool) -> Eq Reference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Reference -> Reference -> Bool
== :: Reference -> Reference -> Bool
$c/= :: Reference -> Reference -> Bool
/= :: Reference -> Reference -> Bool
Eq, Int -> Reference -> String -> String
[Reference] -> String -> String
Reference -> String
(Int -> Reference -> String -> String)
-> (Reference -> String)
-> ([Reference] -> String -> String)
-> Show Reference
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> Reference -> String -> String
showsPrec :: Int -> Reference -> String -> String
$cshow :: Reference -> String
show :: Reference -> String
$cshowList :: [Reference] -> String -> String
showList :: [Reference] -> String -> String
Show)

instance XP.XmlPickler Reference where
  xpickle :: PU Reference
xpickle = [XP.biCase|
      Left (u, r) <-> DataReference u r
      Right (u, r) <-> KeyReference u r |]
    Bijection (->) (Either (URI, Nodes) (URI, Nodes)) Reference
-> PU (Either (URI, Nodes) (URI, Nodes)) -> PU Reference
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$< (String -> PU (URI, Nodes)
refs String
"DataReference" PU (URI, Nodes)
-> PU (URI, Nodes) -> PU (Either (URI, Nodes) (URI, Nodes))
forall a b. PU a -> PU b -> PU (Either a b)
forall (f :: * -> *) a b.
MonoidalAlt f =>
f a -> f b -> f (Either a b)
XP.>|< String -> PU (URI, Nodes)
refs String
"KeyReference")
    where
    refs :: String -> PU (URI, Nodes)
refs String
n = String -> PU (URI, Nodes) -> PU (URI, Nodes)
forall a. String -> PU a -> PU a
xpElem String
n
      (PU (URI, Nodes) -> PU (URI, Nodes))
-> PU (URI, Nodes) -> PU (URI, Nodes)
forall a b. (a -> b) -> a -> b
$ String -> PU URI -> PU URI
forall a. String -> PU a -> PU a
XP.xpAttr String
"URI" PU URI
XS.xpAnyURI
      PU URI -> PU Nodes -> PU (URI, Nodes)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU (NTree XNode) -> PU Nodes
forall a. PU a -> PU [a]
XP.xpList PU (NTree XNode)
xpTrimAnyElem

-- |§3.7
data EncryptionProperties = EncryptionProperties
  { EncryptionProperties -> Maybe String
encryptionPropertiesId :: Maybe ID
  , EncryptionProperties -> List1 EncryptionProperty
encryptionProperties :: List1 EncryptionProperty
  } deriving (EncryptionProperties -> EncryptionProperties -> Bool
(EncryptionProperties -> EncryptionProperties -> Bool)
-> (EncryptionProperties -> EncryptionProperties -> Bool)
-> Eq EncryptionProperties
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncryptionProperties -> EncryptionProperties -> Bool
== :: EncryptionProperties -> EncryptionProperties -> Bool
$c/= :: EncryptionProperties -> EncryptionProperties -> Bool
/= :: EncryptionProperties -> EncryptionProperties -> Bool
Eq, Int -> EncryptionProperties -> String -> String
[EncryptionProperties] -> String -> String
EncryptionProperties -> String
(Int -> EncryptionProperties -> String -> String)
-> (EncryptionProperties -> String)
-> ([EncryptionProperties] -> String -> String)
-> Show EncryptionProperties
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> EncryptionProperties -> String -> String
showsPrec :: Int -> EncryptionProperties -> String -> String
$cshow :: EncryptionProperties -> String
show :: EncryptionProperties -> String
$cshowList :: [EncryptionProperties] -> String -> String
showList :: [EncryptionProperties] -> String -> String
Show)

instance XP.XmlPickler EncryptionProperties where
  xpickle :: PU EncryptionProperties
xpickle = String -> PU EncryptionProperties -> PU EncryptionProperties
forall a. String -> PU a -> PU a
xpElem String
"EncryptionProperties" (PU EncryptionProperties -> PU EncryptionProperties)
-> PU EncryptionProperties -> PU EncryptionProperties
forall a b. (a -> b) -> a -> b
$
    [XP.biCase|(i, l) <-> EncryptionProperties i l|] 
    Bijection
  (->) (Maybe String, List1 EncryptionProperty) EncryptionProperties
-> PU (Maybe String, List1 EncryptionProperty)
-> PU EncryptionProperties
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$<  (String -> PU String -> PU (Maybe String)
forall a. String -> PU a -> PU (Maybe a)
XP.xpAttrImplied String
"Id" PU String
XS.xpID
      PU (Maybe String)
-> PU (List1 EncryptionProperty)
-> PU (Maybe String, List1 EncryptionProperty)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU EncryptionProperty -> PU (List1 EncryptionProperty)
forall a. PU a -> PU (List1 a)
xpList1 PU EncryptionProperty
forall a. XmlPickler a => PU a
XP.xpickle)

data EncryptionProperty = EncryptionProperty
  { EncryptionProperty -> Maybe String
encryptionPropertyId :: Maybe ID
  , EncryptionProperty -> Maybe URI
encryptionPropertyTarget :: Maybe AnyURI
  , EncryptionProperty -> Nodes
encryptionProperty :: Nodes
  } deriving (EncryptionProperty -> EncryptionProperty -> Bool
(EncryptionProperty -> EncryptionProperty -> Bool)
-> (EncryptionProperty -> EncryptionProperty -> Bool)
-> Eq EncryptionProperty
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncryptionProperty -> EncryptionProperty -> Bool
== :: EncryptionProperty -> EncryptionProperty -> Bool
$c/= :: EncryptionProperty -> EncryptionProperty -> Bool
/= :: EncryptionProperty -> EncryptionProperty -> Bool
Eq, Int -> EncryptionProperty -> String -> String
[EncryptionProperty] -> String -> String
EncryptionProperty -> String
(Int -> EncryptionProperty -> String -> String)
-> (EncryptionProperty -> String)
-> ([EncryptionProperty] -> String -> String)
-> Show EncryptionProperty
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> EncryptionProperty -> String -> String
showsPrec :: Int -> EncryptionProperty -> String -> String
$cshow :: EncryptionProperty -> String
show :: EncryptionProperty -> String
$cshowList :: [EncryptionProperty] -> String -> String
showList :: [EncryptionProperty] -> String -> String
Show)

instance XP.XmlPickler EncryptionProperty where
  xpickle :: PU EncryptionProperty
xpickle = String -> PU EncryptionProperty -> PU EncryptionProperty
forall a. String -> PU a -> PU a
xpElem String
"EncryptionProperty" (PU EncryptionProperty -> PU EncryptionProperty)
-> PU EncryptionProperty -> PU EncryptionProperty
forall a b. (a -> b) -> a -> b
$
    [XP.biCase|((i, t), x) <-> EncryptionProperty i t x|] 
    Bijection
  (->) ((Maybe String, Maybe URI), Nodes) EncryptionProperty
-> PU ((Maybe String, Maybe URI), Nodes) -> PU EncryptionProperty
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$<  (String -> PU String -> PU (Maybe String)
forall a. String -> PU a -> PU (Maybe a)
XP.xpAttrImplied String
"Id" PU String
XS.xpID
      PU (Maybe String) -> PU (Maybe URI) -> PU (Maybe String, Maybe URI)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< String -> PU URI -> PU (Maybe URI)
forall a. String -> PU a -> PU (Maybe a)
XP.xpAttrImplied String
"Target" PU URI
XS.xpAnyURI
      PU (Maybe String, Maybe URI)
-> PU Nodes -> PU ((Maybe String, Maybe URI), Nodes)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU Nodes
XP.xpAny)

-- |§5.1
data EncryptionAlgorithm
  = BlockEncryptionTripleDES -- ^§5.2.2
  | BlockEncryptionAES128 -- ^§5.2.3
  | BlockEncryptionAES192 -- ^§5.2.3
  | BlockEncryptionAES256 -- ^§5.2.3
  | BlockEncryptionAES128GCM -- ^§5.2.4
  | BlockEncryptionAES192GCM -- ^§5.2.4
  | BlockEncryptionAES256GCM -- ^§5.2.4
  | KeyTransportRSA1_5 -- ^§5.5.1
  | KeyTransportRSAOAEPMGF1P -- ^§5.5.2
  | KeyTransportRSAOAEP -- ^§5.5.2
  deriving (EncryptionAlgorithm -> EncryptionAlgorithm -> Bool
(EncryptionAlgorithm -> EncryptionAlgorithm -> Bool)
-> (EncryptionAlgorithm -> EncryptionAlgorithm -> Bool)
-> Eq EncryptionAlgorithm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncryptionAlgorithm -> EncryptionAlgorithm -> Bool
== :: EncryptionAlgorithm -> EncryptionAlgorithm -> Bool
$c/= :: EncryptionAlgorithm -> EncryptionAlgorithm -> Bool
/= :: EncryptionAlgorithm -> EncryptionAlgorithm -> Bool
Eq, EncryptionAlgorithm
EncryptionAlgorithm
-> EncryptionAlgorithm -> Bounded EncryptionAlgorithm
forall a. a -> a -> Bounded a
$cminBound :: EncryptionAlgorithm
minBound :: EncryptionAlgorithm
$cmaxBound :: EncryptionAlgorithm
maxBound :: EncryptionAlgorithm
Bounded, Int -> EncryptionAlgorithm
EncryptionAlgorithm -> Int
EncryptionAlgorithm -> [EncryptionAlgorithm]
EncryptionAlgorithm -> EncryptionAlgorithm
EncryptionAlgorithm -> EncryptionAlgorithm -> [EncryptionAlgorithm]
EncryptionAlgorithm
-> EncryptionAlgorithm
-> EncryptionAlgorithm
-> [EncryptionAlgorithm]
(EncryptionAlgorithm -> EncryptionAlgorithm)
-> (EncryptionAlgorithm -> EncryptionAlgorithm)
-> (Int -> EncryptionAlgorithm)
-> (EncryptionAlgorithm -> Int)
-> (EncryptionAlgorithm -> [EncryptionAlgorithm])
-> (EncryptionAlgorithm
    -> EncryptionAlgorithm -> [EncryptionAlgorithm])
-> (EncryptionAlgorithm
    -> EncryptionAlgorithm -> [EncryptionAlgorithm])
-> (EncryptionAlgorithm
    -> EncryptionAlgorithm
    -> EncryptionAlgorithm
    -> [EncryptionAlgorithm])
-> Enum EncryptionAlgorithm
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: EncryptionAlgorithm -> EncryptionAlgorithm
succ :: EncryptionAlgorithm -> EncryptionAlgorithm
$cpred :: EncryptionAlgorithm -> EncryptionAlgorithm
pred :: EncryptionAlgorithm -> EncryptionAlgorithm
$ctoEnum :: Int -> EncryptionAlgorithm
toEnum :: Int -> EncryptionAlgorithm
$cfromEnum :: EncryptionAlgorithm -> Int
fromEnum :: EncryptionAlgorithm -> Int
$cenumFrom :: EncryptionAlgorithm -> [EncryptionAlgorithm]
enumFrom :: EncryptionAlgorithm -> [EncryptionAlgorithm]
$cenumFromThen :: EncryptionAlgorithm -> EncryptionAlgorithm -> [EncryptionAlgorithm]
enumFromThen :: EncryptionAlgorithm -> EncryptionAlgorithm -> [EncryptionAlgorithm]
$cenumFromTo :: EncryptionAlgorithm -> EncryptionAlgorithm -> [EncryptionAlgorithm]
enumFromTo :: EncryptionAlgorithm -> EncryptionAlgorithm -> [EncryptionAlgorithm]
$cenumFromThenTo :: EncryptionAlgorithm
-> EncryptionAlgorithm
-> EncryptionAlgorithm
-> [EncryptionAlgorithm]
enumFromThenTo :: EncryptionAlgorithm
-> EncryptionAlgorithm
-> EncryptionAlgorithm
-> [EncryptionAlgorithm]
Enum, Int -> EncryptionAlgorithm -> String -> String
[EncryptionAlgorithm] -> String -> String
EncryptionAlgorithm -> String
(Int -> EncryptionAlgorithm -> String -> String)
-> (EncryptionAlgorithm -> String)
-> ([EncryptionAlgorithm] -> String -> String)
-> Show EncryptionAlgorithm
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> EncryptionAlgorithm -> String -> String
showsPrec :: Int -> EncryptionAlgorithm -> String -> String
$cshow :: EncryptionAlgorithm -> String
show :: EncryptionAlgorithm -> String
$cshowList :: [EncryptionAlgorithm] -> String -> String
showList :: [EncryptionAlgorithm] -> String -> String
Show)

instance Identifiable URI EncryptionAlgorithm where
  identifier :: EncryptionAlgorithm -> URI
identifier EncryptionAlgorithm
BlockEncryptionTripleDES = String -> URI
nsFrag String
"tripledes-cbc"
  identifier EncryptionAlgorithm
BlockEncryptionAES128 = String -> URI
nsFrag String
"aes128-cbc"
  identifier EncryptionAlgorithm
BlockEncryptionAES256 = String -> URI
nsFrag String
"aes256-cbc"
  identifier EncryptionAlgorithm
BlockEncryptionAES192 = String -> URI
nsFrag String
"aes192-cbc"
  identifier EncryptionAlgorithm
BlockEncryptionAES128GCM = String -> String -> String -> String -> URI
httpURI String
"www.w3.org" String
"/2009/xmlenc11" String
"" String
"#aes128-gcm"
  identifier EncryptionAlgorithm
BlockEncryptionAES192GCM = String -> String -> String -> String -> URI
httpURI String
"www.w3.org" String
"/2009/xmlenc11" String
"" String
"#aes192-gcm"
  identifier EncryptionAlgorithm
BlockEncryptionAES256GCM = String -> String -> String -> String -> URI
httpURI String
"www.w3.org" String
"/2009/xmlenc11" String
"" String
"#aes256-gcm"
  identifier EncryptionAlgorithm
KeyTransportRSA1_5 = String -> URI
nsFrag String
"rsa-1_5"
  identifier EncryptionAlgorithm
KeyTransportRSAOAEPMGF1P = String -> URI
nsFrag String
"rsa-oaep-mgf1p"
  identifier EncryptionAlgorithm
KeyTransportRSAOAEP = String -> String -> String -> String -> URI
httpURI String
"www.w3.org" String
"/2009/xmlenc11" String
"" String
"#rsa-oaep"

-- |§5.5
data AgreementMethod = AgreementMethod
  { AgreementMethod -> IdentifiedURI EncryptionAlgorithm
agreementMethodAlgorithm :: IdentifiedURI EncryptionAlgorithm
  , AgreementMethod -> Maybe Base64Binary
agreementMethodKA_Nonce :: Maybe XS.Base64Binary
  , AgreementMethod -> Maybe DigestMethod
agreementMethodDigestMethod :: Maybe DS.DigestMethod
  -- Nodes...
  , AgreementMethod -> Maybe KeyInfo
agreementMethodOriginatorKeyInfo :: Maybe DS.KeyInfo
  , AgreementMethod -> Maybe KeyInfo
agreementMethodRecipientKeyInfo :: Maybe DS.KeyInfo
  }

instance XP.XmlPickler AgreementMethod where
  xpickle :: PU AgreementMethod
xpickle = String -> PU AgreementMethod -> PU AgreementMethod
forall a. String -> PU a -> PU a
xpElem String
"AgreementMethod" (PU AgreementMethod -> PU AgreementMethod)
-> PU AgreementMethod -> PU AgreementMethod
forall a b. (a -> b) -> a -> b
$
    [XP.biCase|((((a, n), d), o), r) <-> AgreementMethod a n d o r|]
    Bijection
  (->)
  ((((IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary),
     Maybe DigestMethod),
    Maybe KeyInfo),
   Maybe KeyInfo)
  AgreementMethod
-> PU
     ((((IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary),
        Maybe DigestMethod),
       Maybe KeyInfo),
      Maybe KeyInfo)
-> PU AgreementMethod
forall (f :: * -> *) a b. Functor f => (a <-> b) -> f a -> f b
XP.>$< (String
-> PU (IdentifiedURI EncryptionAlgorithm)
-> PU (IdentifiedURI EncryptionAlgorithm)
forall a. String -> PU a -> PU a
XP.xpAttr String
"Algorithm" PU (IdentifiedURI EncryptionAlgorithm)
forall a. XmlPickler a => PU a
XP.xpickle
      PU (IdentifiedURI EncryptionAlgorithm)
-> PU (Maybe Base64Binary)
-> PU (IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU Base64Binary -> PU (Maybe Base64Binary)
forall a. PU a -> PU (Maybe a)
XP.xpOption (String -> PU Base64Binary -> PU Base64Binary
forall a. String -> PU a -> PU a
xpElem String
"KA-Nonce" PU Base64Binary
XS.xpBase64Binary)
      PU (IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary)
-> PU (Maybe DigestMethod)
-> PU
     ((IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary),
      Maybe DigestMethod)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU DigestMethod -> PU (Maybe DigestMethod)
forall a. PU a -> PU (Maybe a)
XP.xpOption PU DigestMethod
forall a. XmlPickler a => PU a
XP.xpickle
      PU
  ((IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary),
   Maybe DigestMethod)
-> PU (Maybe KeyInfo)
-> PU
     (((IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary),
       Maybe DigestMethod),
      Maybe KeyInfo)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU KeyInfo -> PU (Maybe KeyInfo)
forall a. PU a -> PU (Maybe a)
XP.xpOption (String -> PU KeyInfo -> PU KeyInfo
forall a. String -> PU a -> PU a
xpElem String
"OriginatorKeyInfo" PU KeyInfo
DS.xpKeyInfoType)
      PU
  (((IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary),
    Maybe DigestMethod),
   Maybe KeyInfo)
-> PU (Maybe KeyInfo)
-> PU
     ((((IdentifiedURI EncryptionAlgorithm, Maybe Base64Binary),
        Maybe DigestMethod),
       Maybe KeyInfo),
      Maybe KeyInfo)
forall a b. PU a -> PU b -> PU (a, b)
forall (f :: * -> *) a b. Monoidal f => f a -> f b -> f (a, b)
XP.>*< PU KeyInfo -> PU (Maybe KeyInfo)
forall a. PU a -> PU (Maybe a)
XP.xpOption (String -> PU KeyInfo -> PU KeyInfo
forall a. String -> PU a -> PU a
xpElem String
"RecipientKeyInfo" PU KeyInfo
DS.xpKeyInfoType))