    -- BlockCipher.hs: OpenPGP (RFC4880) block cipher stuff
    -- Copyright © 2013-2016  Clint Adams
    -- This software is released under the terms of the Expat license.
    -- (See the LICENSE file).
    {-# LANGUAGE RankNTypes #-}

    module Codec.Encryption.OpenPGP.BlockCipher
      ( keySize
      , withSymmetricCipher
      ) where

    import Codec.Encryption.OpenPGP.Internal.CryptoCipherTypes (HOWrappedOldCCT(..))
    import Codec.Encryption.OpenPGP.Internal.Cryptonite (HOWrappedCCT(..))
    import Codec.Encryption.OpenPGP.Internal.HOBlockCipher
    import Codec.Encryption.OpenPGP.Types

    import qualified Crypto.Cipher.AES as AES
    import qualified Crypto.Cipher.Blowfish as Blowfish
    import qualified Crypto.Cipher.Camellia as Camellia
    import qualified Crypto.Cipher.TripleDES as TripleDES
    import qualified Crypto.Nettle.Ciphers as CNC
    import qualified Data.ByteString as B

    type HOCipher a
       = forall cipher. HOBlockCipher cipher =>
                          cipher -> Either String a

    withSymmetricCipher ::
         SymmetricAlgorithm -> B.ByteString -> HOCipher a -> Either String a
    withSymmetricCipher :: SymmetricAlgorithm -> ByteString -> HOCipher a -> Either String a
    withSymmetricCipher Plaintext _ _ = String -> Either String a
    forall a b. a -> Either a b
    Left "this shouldn't have happened" -- FIXME: orphan instance?
    withSymmetricCipher IDEA _ _ = String -> Either String a
    forall a b. a -> Either a b
    Left "IDEA not yet implemented" -- FIXME: IDEA
    withSymmetricCipher ReservedSAFER _ _ = String -> Either String a
    forall a b. a -> Either a b
    Left "SAFER not implemented" -- FIXME: or not?
    withSymmetricCipher ReservedDES _ _ = String -> Either String a
    forall a b. a -> Either a b
    Left "DES not implemented" -- FIXME: or not?
    withSymmetricCipher (OtherSA _) _ _ =
      String -> Either String a
    forall a b. a -> Either a b
    Left "Unknown, unimplemented symmetric algorithm"
    withSymmetricCipher CAST5 key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedOldCCT CAST128)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedOldCCT CNC.CAST128)) Either String (HOWrappedOldCCT CAST128)
    -> (HOWrappedOldCCT CAST128 -> Either String a) -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedOldCCT CAST128 -> Either String a
    HOCipher a
    f
    withSymmetricCipher Twofish key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedOldCCT TWOFISH)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedOldCCT CNC.TWOFISH)) Either String (HOWrappedOldCCT TWOFISH)
    -> (HOWrappedOldCCT TWOFISH -> Either String a) -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedOldCCT TWOFISH -> Either String a
    HOCipher a
    f
    withSymmetricCipher TripleDES key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedCCT DES_EDE3)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedCCT TripleDES.DES_EDE3)) Either String (HOWrappedCCT DES_EDE3)
    -> (HOWrappedCCT DES_EDE3 -> Either String a) -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedCCT DES_EDE3 -> Either String a
    HOCipher a
    f
    withSymmetricCipher Blowfish key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedCCT Blowfish128)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedCCT Blowfish.Blowfish128)) Either String (HOWrappedCCT Blowfish128)
    -> (HOWrappedCCT Blowfish128 -> Either String a) -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedCCT Blowfish128 -> Either String a
    HOCipher a
    f
    withSymmetricCipher AES128 key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedCCT AES128)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedCCT AES.AES128)) Either String (HOWrappedCCT AES128)
    -> (HOWrappedCCT AES128 -> Either String a) -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedCCT AES128 -> Either String a
    HOCipher a
    f
    withSymmetricCipher AES192 key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedCCT AES192)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedCCT AES.AES192)) Either String (HOWrappedCCT AES192)
    -> (HOWrappedCCT AES192 -> Either String a) -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedCCT AES192 -> Either String a
    HOCipher a
    f
    withSymmetricCipher AES256 key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedCCT AES256)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedCCT AES.AES256)) Either String (HOWrappedCCT AES256)
    -> (HOWrappedCCT AES256 -> Either String a) -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedCCT AES256 -> Either String a
    HOCipher a
    f
    withSymmetricCipher Camellia128 key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedCCT Camellia128)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedCCT Camellia.Camellia128)) Either String (HOWrappedCCT Camellia128)
    -> (HOWrappedCCT Camellia128 -> Either String a) -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedCCT Camellia128 -> Either String a
    HOCipher a
    f
    withSymmetricCipher Camellia192 key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedOldCCT Camellia192)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedOldCCT CNC.Camellia192)) Either String (HOWrappedOldCCT Camellia192)
    -> (HOWrappedOldCCT Camellia192 -> Either String a)
    -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedOldCCT Camellia192 -> Either String a
    HOCipher a
    f
    withSymmetricCipher Camellia256 key :: ByteString
    key f :: HOCipher a
    f =
      (ByteString -> Either String (HOWrappedOldCCT Camellia256)
    forall cipher.
    HOBlockCipher cipher =>
    ByteString -> Either String cipher
    cipherInit ByteString
    key :: Either String (HOWrappedOldCCT CNC.Camellia256)) Either String (HOWrappedOldCCT Camellia256)
    -> (HOWrappedOldCCT Camellia256 -> Either String a)
    -> Either String a
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HOWrappedOldCCT Camellia256 -> Either String a
    HOCipher a
    f

    -- in octets; FIXME: co-opt Cipher's cipherKeySize or not?
    keySize :: SymmetricAlgorithm -> Int
    keySize :: SymmetricAlgorithm -> Int
    keySize Plaintext = 0
    keySize IDEA = 16 -- according to https://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
    keySize TripleDES = 24 -- RFC 4880 says 168 bits (derived from 192 bits) but we don't know who does the derivation
    keySize CAST5 = 16
    keySize Blowfish = 16
    keySize ReservedSAFER = Int
    forall a. HasCallStack => a
    undefined
    keySize ReservedDES = Int
    forall a. HasCallStack => a
    undefined
    keySize AES128 = 16
    keySize AES192 = 24
    keySize AES256 = 32
    keySize Twofish = 32
    keySize Camellia128 = 16
    keySize Camellia192 = 24
    keySize Camellia256 = 32
    keySize (OtherSA _) = Int
    forall a. HasCallStack => a
    undefined