module Botan.X509 where
import Botan.Prelude
import Data.Bits
import qualified Botan.Low.X509 as Low
import Data.List (nub)
data DistinguishedName
= SerialNumber
| Mail
| UserID
| CommonName
| Title
| OrganizationalUnit
| DomainComponent
| Organization
| Street
| Locality
| StateOrProvince
| PostalCode
| Country
| UnstructuredName
| UnstructuredAddress
| ExtensionDN ByteString
fromDN :: DistinguishedName -> Low.DistinguishedName
fromDN :: DistinguishedName -> DistinguishedName
fromDN = DistinguishedName -> DistinguishedName
forall a. HasCallStack => a
undefined
toDN :: DistinguishedName -> Low.DistinguishedName
toDN :: DistinguishedName -> DistinguishedName
toDN = DistinguishedName -> DistinguishedName
forall a. HasCallStack => a
undefined
data KeyConstraint
= NoConstraints
| DigitalSignature
| NonRepudiation
| KeyEncipherment
| DataEncipherment
| KeyAgreement
| KeyCertSign
| CRLSign
| EncipherOnly
| DecipherOnly
| KeyConstraints [KeyConstraint]
deriving (KeyConstraint -> KeyConstraint -> Bool
(KeyConstraint -> KeyConstraint -> Bool)
-> (KeyConstraint -> KeyConstraint -> Bool) -> Eq KeyConstraint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: KeyConstraint -> KeyConstraint -> Bool
== :: KeyConstraint -> KeyConstraint -> Bool
$c/= :: KeyConstraint -> KeyConstraint -> Bool
/= :: KeyConstraint -> KeyConstraint -> Bool
Eq)
allKeyConstraints :: [KeyConstraint]
allKeyConstraints :: [KeyConstraint]
allKeyConstraints =
[ KeyConstraint
DigitalSignature
, KeyConstraint
NonRepudiation
, KeyConstraint
KeyEncipherment
, KeyConstraint
DataEncipherment
, KeyConstraint
KeyAgreement
, KeyConstraint
KeyCertSign
, KeyConstraint
CRLSign
, KeyConstraint
EncipherOnly
, KeyConstraint
DecipherOnly
]
allConstraints :: KeyConstraint
allConstraints :: KeyConstraint
allConstraints = [KeyConstraint] -> KeyConstraint
KeyConstraints [KeyConstraint]
allKeyConstraints
instance Semigroup KeyConstraint where
(<>) :: KeyConstraint -> KeyConstraint -> KeyConstraint
<> :: KeyConstraint -> KeyConstraint -> KeyConstraint
(<>) KeyConstraint
NoConstraints KeyConstraint
kc = KeyConstraint
kc
(<>) KeyConstraint
kc KeyConstraint
NoConstraints = KeyConstraint
kc
(<>) (KeyConstraints [KeyConstraint]
a) (KeyConstraints [KeyConstraint]
b) = [KeyConstraint] -> KeyConstraint
KeyConstraints ([KeyConstraint] -> KeyConstraint)
-> [KeyConstraint] -> KeyConstraint
forall a b. (a -> b) -> a -> b
$ [KeyConstraint] -> [KeyConstraint]
forall a. Eq a => [a] -> [a]
nub ([KeyConstraint] -> [KeyConstraint])
-> [KeyConstraint] -> [KeyConstraint]
forall a b. (a -> b) -> a -> b
$ [KeyConstraint]
a [KeyConstraint] -> [KeyConstraint] -> [KeyConstraint]
forall a. [a] -> [a] -> [a]
++ [KeyConstraint]
b
(<>) (KeyConstraints [KeyConstraint]
kcs) KeyConstraint
kc = [KeyConstraint] -> KeyConstraint
KeyConstraints (KeyConstraint
kcKeyConstraint -> [KeyConstraint] -> [KeyConstraint]
forall a. a -> [a] -> [a]
:[KeyConstraint]
kcs)
(<>) KeyConstraint
kc (KeyConstraints [KeyConstraint]
kcs) = [KeyConstraint] -> KeyConstraint
KeyConstraints (KeyConstraint
kcKeyConstraint -> [KeyConstraint] -> [KeyConstraint]
forall a. a -> [a] -> [a]
:[KeyConstraint]
kcs)
(<>) KeyConstraint
a KeyConstraint
b = [KeyConstraint] -> KeyConstraint
KeyConstraints [KeyConstraint
a,KeyConstraint
b]
instance Monoid KeyConstraint where
mempty :: KeyConstraint
mempty :: KeyConstraint
mempty = KeyConstraint
NoConstraints
instance (Enum KeyConstraint) where
toEnum :: Int -> KeyConstraint
toEnum :: Int -> KeyConstraint
toEnum Int
0 = KeyConstraint
NoConstraints
toEnum Int
32768 = KeyConstraint
DigitalSignature
toEnum Int
16384 = KeyConstraint
NonRepudiation
toEnum Int
8192 = KeyConstraint
KeyEncipherment
toEnum Int
4096 = KeyConstraint
DataEncipherment
toEnum Int
2048 = KeyConstraint
KeyAgreement
toEnum Int
1024 = KeyConstraint
KeyCertSign
toEnum Int
512 = KeyConstraint
CRLSign
toEnum Int
256 = KeyConstraint
EncipherOnly
toEnum Int
128 = KeyConstraint
DecipherOnly
toEnum Int
n = [KeyConstraint] -> KeyConstraint
KeyConstraints ([KeyConstraint] -> KeyConstraint)
-> [KeyConstraint] -> KeyConstraint
forall a b. (a -> b) -> a -> b
$ (KeyConstraint -> Bool) -> [KeyConstraint] -> [KeyConstraint]
forall a. (a -> Bool) -> [a] -> [a]
filter (\ KeyConstraint
kc -> (Int
n Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. KeyConstraint -> Int
forall a. Enum a => a -> Int
fromEnum KeyConstraint
kc) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== KeyConstraint -> Int
forall a. Enum a => a -> Int
fromEnum KeyConstraint
kc) [KeyConstraint]
allKeyConstraints
fromEnum :: KeyConstraint -> Int
fromEnum :: KeyConstraint -> Int
fromEnum KeyConstraint
NoConstraints = Int
0
fromEnum KeyConstraint
DigitalSignature = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.DigitalSignature
fromEnum KeyConstraint
NonRepudiation = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.NonRepudiation
fromEnum KeyConstraint
KeyEncipherment = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.KeyEncipherment
fromEnum KeyConstraint
DataEncipherment = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.DataEncipherment
fromEnum KeyConstraint
KeyAgreement = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.KeyAgreement
fromEnum KeyConstraint
KeyCertSign = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.KeyCertSign
fromEnum KeyConstraint
CRLSign = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.CRLSign
fromEnum KeyConstraint
EncipherOnly = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.EncipherOnly
fromEnum KeyConstraint
DecipherOnly = X509KeyConstraints -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral X509KeyConstraints
Low.DecipherOnly
fromEnum (KeyConstraints (KeyConstraint
kc:[KeyConstraint]
kcs)) = KeyConstraint -> Int
forall a. Enum a => a -> Int
fromEnum KeyConstraint
kc Int -> Int -> Int
forall a. Bits a => a -> a -> a
.|. KeyConstraint -> Int
forall a. Enum a => a -> Int
fromEnum ([KeyConstraint] -> KeyConstraint
KeyConstraints [KeyConstraint]
kcs)
data X509VerifyStatusCode
data X509CertificateAuthority
data X509CertificateStore
data X509CRL