keep Utility.Gpg free of dependencies on git-annex
This commit is contained in:
parent
ce53acf4fe
commit
08f026e886
2 changed files with 25 additions and 25 deletions
24
Crypto.hs
24
Crypto.hs
|
@ -8,6 +8,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
|
|
||||||
module Crypto (
|
module Crypto (
|
||||||
Cipher,
|
Cipher,
|
||||||
KeyIds(..),
|
KeyIds(..),
|
||||||
|
@ -23,7 +25,7 @@ module Crypto (
|
||||||
readBytes,
|
readBytes,
|
||||||
encrypt,
|
encrypt,
|
||||||
decrypt,
|
decrypt,
|
||||||
Gpg.getGpgEncParams,
|
getGpgEncParams,
|
||||||
|
|
||||||
prop_HmacSha1WithCipher_sane
|
prop_HmacSha1WithCipher_sane
|
||||||
) where
|
) where
|
||||||
|
@ -31,11 +33,13 @@ module Crypto (
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import Data.ByteString.Lazy.UTF8 (fromString)
|
import Data.ByteString.Lazy.UTF8 (fromString)
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
import qualified Data.Map as M
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import qualified Utility.Gpg as Gpg
|
import qualified Utility.Gpg as Gpg
|
||||||
import Types.Key
|
import Types.Key
|
||||||
import Types.Crypto
|
import Types.Crypto
|
||||||
|
import Types.Remote
|
||||||
|
|
||||||
{- The beginning of a Cipher is used for MAC'ing; the remainder is used
|
{- The beginning of a Cipher is used for MAC'ing; the remainder is used
|
||||||
- as the GPG symmetric encryption passphrase when using the hybrid
|
- as the GPG symmetric encryption passphrase when using the hybrid
|
||||||
|
@ -175,3 +179,21 @@ prop_HmacSha1WithCipher_sane :: Bool
|
||||||
prop_HmacSha1WithCipher_sane = known_good == macWithCipher' HmacSha1 "foo" "bar"
|
prop_HmacSha1WithCipher_sane = known_good == macWithCipher' HmacSha1 "foo" "bar"
|
||||||
where
|
where
|
||||||
known_good = "46b4ec586117154dacd49d664e5d63fdc88efb51"
|
known_good = "46b4ec586117154dacd49d664e5d63fdc88efb51"
|
||||||
|
|
||||||
|
{- Return some options suitable for GnuPG encryption, symmetric or not. -}
|
||||||
|
class LensGpgEncParams a where getGpgEncParams :: a -> [CommandParam]
|
||||||
|
|
||||||
|
{- Extract the GnuPG options from a pair of a Remote Config and a Remote
|
||||||
|
- Git Config. If the remote is configured to use public-key encryption,
|
||||||
|
- look up the recipient keys and add them to the option list. -}
|
||||||
|
instance LensGpgEncParams (RemoteConfig, RemoteGitConfig) where
|
||||||
|
getGpgEncParams (c,gc) = map Param (remoteAnnexGnupgOptions gc) ++ recipients
|
||||||
|
where
|
||||||
|
recipients = case M.lookup "encryption" c of
|
||||||
|
Just "pubkey" -> Gpg.pkEncTo $ maybe [] (split ",") $
|
||||||
|
M.lookup "cipherkeys" c
|
||||||
|
_ -> []
|
||||||
|
|
||||||
|
{- Extract the GnuPG options from a Remote. -}
|
||||||
|
instance LensGpgEncParams (RemoteA a) where
|
||||||
|
getGpgEncParams r = getGpgEncParams (config r, gitconfig r)
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
{-# LANGUAGE CPP, FlexibleInstances #-}
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Utility.Gpg where
|
module Utility.Gpg where
|
||||||
|
|
||||||
|
@ -24,10 +24,6 @@ import Utility.Env
|
||||||
import Utility.Tmp
|
import Utility.Tmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import qualified Data.Map as M
|
|
||||||
import Types.GitConfig
|
|
||||||
import Types.Remote hiding (setup)
|
|
||||||
|
|
||||||
newtype KeyIds = KeyIds { keyIds :: [String] }
|
newtype KeyIds = KeyIds { keyIds :: [String] }
|
||||||
deriving (Ord, Eq)
|
deriving (Ord, Eq)
|
||||||
|
|
||||||
|
@ -36,28 +32,10 @@ newtype KeyIds = KeyIds { keyIds :: [String] }
|
||||||
gpgcmd :: FilePath
|
gpgcmd :: FilePath
|
||||||
gpgcmd = fromMaybe "gpg" SysConfig.gpg
|
gpgcmd = fromMaybe "gpg" SysConfig.gpg
|
||||||
|
|
||||||
{- Return some options suitable for GnuPG encryption, symmetric or not. -}
|
|
||||||
class LensGpgEncParams a where getGpgEncParams :: a -> [CommandParam]
|
|
||||||
|
|
||||||
{- Extract the GnuPG options from a pair of a Remote Config and a Remote
|
|
||||||
- Git Config. If the remote is configured to use public-key encryption,
|
|
||||||
- look up the recipient keys and add them to the option list. -}
|
|
||||||
instance LensGpgEncParams (RemoteConfig, RemoteGitConfig) where
|
|
||||||
getGpgEncParams (c,gc) = map Param (remoteAnnexGnupgOptions gc) ++ recipients
|
|
||||||
where
|
|
||||||
recipients = case M.lookup "encryption" c of
|
|
||||||
Just "pubkey" -> pkEncTo $ maybe [] (split ",") $
|
|
||||||
M.lookup "cipherkeys" c
|
|
||||||
_ -> []
|
|
||||||
|
|
||||||
-- Generate an argument list to asymetrically encrypt to the given recipients.
|
-- Generate an argument list to asymetrically encrypt to the given recipients.
|
||||||
pkEncTo :: [String] -> [CommandParam]
|
pkEncTo :: [String] -> [CommandParam]
|
||||||
pkEncTo = concatMap (\r -> [Param "--recipient", Param r])
|
pkEncTo = concatMap (\r -> [Param "--recipient", Param r])
|
||||||
|
|
||||||
{- Extract the GnuPG options from a Remote. -}
|
|
||||||
instance LensGpgEncParams (RemoteA a) where
|
|
||||||
getGpgEncParams r = getGpgEncParams (config r, gitconfig r)
|
|
||||||
|
|
||||||
stdParams :: [CommandParam] -> IO [String]
|
stdParams :: [CommandParam] -> IO [String]
|
||||||
stdParams params = do
|
stdParams params = do
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
|
|
Loading…
Reference in a new issue