-- |
-- SAML Versioning
--
-- <https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf saml-core-2.0-os> §4
module SAML2.Core.Versioning
  ( SAMLVersion(..)
  , samlVersion
  ) where

import Data.Version (Version, makeVersion)

import qualified Text.XML.HXT.Arrow.Pickle.Xml.Invertible as XP

data SAMLVersion
  = SAML10
  | SAML11
  | SAML20
  deriving (SAMLVersion -> SAMLVersion -> Bool
(SAMLVersion -> SAMLVersion -> Bool)
-> (SAMLVersion -> SAMLVersion -> Bool) -> Eq SAMLVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SAMLVersion -> SAMLVersion -> Bool
== :: SAMLVersion -> SAMLVersion -> Bool
$c/= :: SAMLVersion -> SAMLVersion -> Bool
/= :: SAMLVersion -> SAMLVersion -> Bool
Eq, Eq SAMLVersion
Eq SAMLVersion =>
(SAMLVersion -> SAMLVersion -> Ordering)
-> (SAMLVersion -> SAMLVersion -> Bool)
-> (SAMLVersion -> SAMLVersion -> Bool)
-> (SAMLVersion -> SAMLVersion -> Bool)
-> (SAMLVersion -> SAMLVersion -> Bool)
-> (SAMLVersion -> SAMLVersion -> SAMLVersion)
-> (SAMLVersion -> SAMLVersion -> SAMLVersion)
-> Ord SAMLVersion
SAMLVersion -> SAMLVersion -> Bool
SAMLVersion -> SAMLVersion -> Ordering
SAMLVersion -> SAMLVersion -> SAMLVersion
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SAMLVersion -> SAMLVersion -> Ordering
compare :: SAMLVersion -> SAMLVersion -> Ordering
$c< :: SAMLVersion -> SAMLVersion -> Bool
< :: SAMLVersion -> SAMLVersion -> Bool
$c<= :: SAMLVersion -> SAMLVersion -> Bool
<= :: SAMLVersion -> SAMLVersion -> Bool
$c> :: SAMLVersion -> SAMLVersion -> Bool
> :: SAMLVersion -> SAMLVersion -> Bool
$c>= :: SAMLVersion -> SAMLVersion -> Bool
>= :: SAMLVersion -> SAMLVersion -> Bool
$cmax :: SAMLVersion -> SAMLVersion -> SAMLVersion
max :: SAMLVersion -> SAMLVersion -> SAMLVersion
$cmin :: SAMLVersion -> SAMLVersion -> SAMLVersion
min :: SAMLVersion -> SAMLVersion -> SAMLVersion
Ord, Int -> SAMLVersion
SAMLVersion -> Int
SAMLVersion -> [SAMLVersion]
SAMLVersion -> SAMLVersion
SAMLVersion -> SAMLVersion -> [SAMLVersion]
SAMLVersion -> SAMLVersion -> SAMLVersion -> [SAMLVersion]
(SAMLVersion -> SAMLVersion)
-> (SAMLVersion -> SAMLVersion)
-> (Int -> SAMLVersion)
-> (SAMLVersion -> Int)
-> (SAMLVersion -> [SAMLVersion])
-> (SAMLVersion -> SAMLVersion -> [SAMLVersion])
-> (SAMLVersion -> SAMLVersion -> [SAMLVersion])
-> (SAMLVersion -> SAMLVersion -> SAMLVersion -> [SAMLVersion])
-> Enum SAMLVersion
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 :: SAMLVersion -> SAMLVersion
succ :: SAMLVersion -> SAMLVersion
$cpred :: SAMLVersion -> SAMLVersion
pred :: SAMLVersion -> SAMLVersion
$ctoEnum :: Int -> SAMLVersion
toEnum :: Int -> SAMLVersion
$cfromEnum :: SAMLVersion -> Int
fromEnum :: SAMLVersion -> Int
$cenumFrom :: SAMLVersion -> [SAMLVersion]
enumFrom :: SAMLVersion -> [SAMLVersion]
$cenumFromThen :: SAMLVersion -> SAMLVersion -> [SAMLVersion]
enumFromThen :: SAMLVersion -> SAMLVersion -> [SAMLVersion]
$cenumFromTo :: SAMLVersion -> SAMLVersion -> [SAMLVersion]
enumFromTo :: SAMLVersion -> SAMLVersion -> [SAMLVersion]
$cenumFromThenTo :: SAMLVersion -> SAMLVersion -> SAMLVersion -> [SAMLVersion]
enumFromThenTo :: SAMLVersion -> SAMLVersion -> SAMLVersion -> [SAMLVersion]
Enum, SAMLVersion
SAMLVersion -> SAMLVersion -> Bounded SAMLVersion
forall a. a -> a -> Bounded a
$cminBound :: SAMLVersion
minBound :: SAMLVersion
$cmaxBound :: SAMLVersion
maxBound :: SAMLVersion
Bounded)

samlVersion :: SAMLVersion -> Version
samlVersion :: SAMLVersion -> Version
samlVersion SAMLVersion
SAML10 = [Int] -> Version
makeVersion [Int
1,Int
0]
samlVersion SAMLVersion
SAML11 = [Int] -> Version
makeVersion [Int
1,Int
1]
samlVersion SAMLVersion
SAML20 = [Int] -> Version
makeVersion [Int
2,Int
0]

instance Show SAMLVersion where
  show :: SAMLVersion -> String
show SAMLVersion
SAML10 = String
"1.0"
  show SAMLVersion
SAML11 = String
"1.1"
  show SAMLVersion
SAML20 = String
"2.0"

instance Read SAMLVersion where
  readsPrec :: Int -> ReadS SAMLVersion
readsPrec Int
_ (Char
'1':Char
'.':Char
'0':String
s) = [(SAMLVersion
SAML10, String
s)]
  readsPrec Int
_ (Char
'1':Char
'.':Char
'1':String
s) = [(SAMLVersion
SAML11, String
s)]
  readsPrec Int
_ (Char
'2':Char
'.':Char
'0':String
s) = [(SAMLVersion
SAML20, String
s)]
  readsPrec Int
_ String
_ = []

instance XP.XmlPickler SAMLVersion where
  xpickle :: PU SAMLVersion
xpickle = PU SAMLVersion
forall a. (Read a, Show a) => PU a
XP.xpPrim