From 006d1f0b7f36c25a91006fce24cbe76416fcee86 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 13 Jul 2019 15:22:45 -0400 Subject: no cpp needed, since my love is unconditional --- lib/KeyRing/BuildKeyDB.hs | 52 ----------------------------------------------- 1 file changed, 52 deletions(-) (limited to 'lib/KeyRing') diff --git a/lib/KeyRing/BuildKeyDB.hs b/lib/KeyRing/BuildKeyDB.hs index 0a90cbc..943578f 100644 --- a/lib/KeyRing/BuildKeyDB.hs +++ b/lib/KeyRing/BuildKeyDB.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DoAndIfThenElse #-} {-# LANGUAGE ForeignFunctionInterface #-} @@ -9,13 +8,8 @@ {-# LANGUAGE ViewPatterns #-} module KeyRing.BuildKeyDB where -#if defined(VERSION_memory) import Data.ByteArray.Encoding import qualified Data.ByteString as S -#elif defined(VERSION_dataenc) -import qualified Codec.Binary.Base32 as Base32 -import qualified Codec.Binary.Base64 as Base64 -#endif import qualified Codec.Encryption.OpenPGP.ASCIIArmor as ASCIIArmor import Codec.Encryption.OpenPGP.ASCIIArmor.Types import Control.Arrow (first, second) @@ -49,12 +43,7 @@ import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds) import System.Directory (doesFileExist) import System.IO.Error (isDoesNotExistError) -#if !defined(VERSION_cryptonite) -import qualified Crypto.Hash.SHA1 as SHA1 -import qualified Crypto.Types.PubKey.ECC as ECC -#else import qualified Crypto.PubKey.ECC.Types as ECC -#endif import qualified Codec.Compression.GZip as GZip import qualified Crypto.PubKey.RSA as RSA import qualified Data.X509 as X509 @@ -63,28 +52,13 @@ import System.Posix.Files (getFdStatus, getFileStatus, import qualified System.Posix.Types as Posix -#if MIN_VERSION_x509(1,5,0) import Data.Hourglass -#endif -#if MIN_VERSION_unix(2,7,0) import Foreign.C.Types (CTime (..)) -#else -import Foreign.C.Error (throwErrnoIfMinus1_) -import Foreign.C.Types (CInt (..), CLong, CTime (..)) -import Foreign.Marshal.Array (withArray) -import Foreign.Ptr -import Foreign.Storable -#endif import Data.Traversable (sequenceA) import qualified Data.Traversable as Traversable import System.IO (openFile, IOMode(ReadMode)) import System.Posix.IO (fdToHandle) -#if ! MIN_VERSION_base(4,6,0) -import GHC.Exts (Down (..)) -#endif -#if MIN_VERSION_binary(0,7,0) -#endif import Compat () import qualified Data.ByteString.Lazy.Char8 as Char8 import Network.Socket @@ -151,11 +125,7 @@ buildKeyDB ctx grip0 keyring = do -- KeyRings (todo: KikiCondition reporting?) (spilled,mwk,grip,accs,keyqs,unspilled) <- do -#if MIN_VERSION_containers(0,5,0) ringPackets <- Map.traverseWithKey readp ringMap -#else - ringPackets <- Traversable.traverse (uncurry readp) $ Map.mapWithKey (,) ringMap -#endif let _ = ringPackets :: Map.Map InputFile (StreamInfo, Message) let grip = grip0 `mplus` (fingerprint <$> fstkey) @@ -208,11 +178,7 @@ buildKeyDB ctx grip0 keyring = do -- XXX: Unspilled keys are not obtainable from rtKeyDB. -- If the working key is marked non spillable, then how -- would we look up it's UID and such? -#if MIN_VERSION_containers(0,5,0) in fmap sequenceA $ Map.traverseWithKey trans spilled -#else - in fmap sequenceA $ Traversable.traverse (uncurry trans) $ Map.mapWithKey (,) spilled -#endif try transformed0 $ \transformed -> do let -- | db_rings - all keyrings combined into one db_rings = Map.foldlWithKey' mergeIt emptyKeyDB transformed @@ -290,16 +256,9 @@ isring _ = False decodePacketList :: L.ByteString -> [Packet] decodePacketList some = -#if MIN_VERSION_binary(0,7,0) case decodeOrFail some of Right (more,_,msg ) -> msg : decodePacketList more Left (_,_,_) -> [] -#else - either (const []) (\(Message xs) -> xs) $ decode input - -decodeOrFail bs = Right (L.empty,1,decode bs) -#endif - readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message) readPacketsFromFile ctx fname = do @@ -1309,12 +1268,8 @@ parseCertBlob comp bs = do cert <- either (const Nothing) (Just . fst) (fromASN1 asn1') let _ = cert :: X509.Certificate notBefore :: UTCTime -#if MIN_VERSION_x509(1,5,0) notBefore = toUTC ( timeFromElapsedP (timeGetElapsedP vincentTime) :: CTime) -- nanoToUTCTime nano where (vincentTime,_) = X509.certValidity cert -#else - (notBefore,_) = X509.certValidity cert -#endif case X509.certPubKey cert of X509.PubKeyRSA key -> do let withoutkey = @@ -1389,17 +1344,10 @@ extractRSAKeyFields kvs = do , rsaCoefficient = u } where parseField blob = MPI <$> m -#if defined(VERSION_memory) where m = bigendian <$> functorToMaybe (convertFromBase Base64 $ Char8.toStrict blob) bigendian bs = snd $ S.foldl' (\(c,a) w8 -> (c-1, a + 256^c * fromIntegral w8)) (nlen-1,0) bs where nlen = S.length bs -#elif defined(VERSION_dataenc) - where m = bigendian <$> Base64.decode (Char8.unpack blob) - bigendian bs = snd $ foldl' (\(c,a) w8 -> (c-1, a + 256^c * fromIntegral w8)) (nlen-1,0) bs - where - nlen = length bs -#endif selectKey0 :: Bool -> (KeySpec,Maybe String) -> KeyDB -> Maybe Packet -- cgit v1.2.3