1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Orphan instances.
module PKCS8.Instances
( arbitraryPassword
) where
import Data.X509
import Test.Tasty.QuickCheck
import Crypto.Store.CMS
import Crypto.Store.PKCS5
import Crypto.Store.PKCS8
import CMS.Instances
instance Arbitrary ProtectionPassword where
arbitrary = oneof [ return emptyNotTerminated
, toProtectionPassword <$> arbitraryPassword
]
instance Arbitrary PBEParameter where
arbitrary = do
salt <- generateSalt 8
PBEParameter salt <$> choose (1,512)
instance Arbitrary PBES2Parameter where
arbitrary = PBES2Parameter <$> arbitrary <*> arbitrary
instance Arbitrary EncryptionScheme where
arbitrary = oneof [ PBES2 <$> arbitrary
, PBE_MD5_DES_CBC <$> arbitrary
, PBE_SHA1_DES_CBC <$> arbitrary
, PBE_SHA1_RC4_128 <$> arbitrary
, PBE_SHA1_RC4_40 <$> arbitrary
, PBE_SHA1_DES_EDE3_CBC <$> arbitrary
, PBE_SHA1_DES_EDE2_CBC <$> arbitrary
, PBE_SHA1_RC2_128 <$> arbitrary
, PBE_SHA1_RC2_40 <$> arbitrary
]
instance Arbitrary PrivateKeyFormat where
arbitrary = elements [ TraditionalFormat, PKCS8Format ]
instance Arbitrary (FormattedKey PrivKey) where
arbitrary = do
key <- arbitrary
fmt <- if pkcs8only key then return PKCS8Format else arbitrary
return (FormattedKey fmt key)
pkcs8only :: PrivKey -> Bool
pkcs8only (PrivKeyX25519 _) = True
pkcs8only (PrivKeyX448 _) = True
pkcs8only (PrivKeyEd25519 _) = True
pkcs8only (PrivKeyEd448 _) = True
pkcs8only _ = False
|