module Crypto.GnuPG (
Recipient
, decrypt
, decryptLbs
, encrypt
, encryptLbs
) where
import Control.Concurrent (ThreadId, forkIO)
import qualified Data.ByteString.Lazy as LBS (ByteString, hGetContents, hPutStr)
import System.Process (runInteractiveProcess)
import System.IO (Handle, hClose, hFlush, hGetContents, hPutStr)
type Recipient = String
decrypt ::
String
-> IO String
decrypt input =
do
(hIn, hOut, _, _) <- runInteractiveProcess
"gpg"
[
"--decrypt"
, "--no-mdc-warning"
, "--quiet"
, "--batch"
]
Nothing
Nothing
consumeInput hPutStr hIn input
hGetContents hOut
encrypt ::
[Recipient]
-> String
-> IO String
encrypt recipients input =
do
(hIn, hOut, _, _) <- runInteractiveProcess
"gpg"
(
[
"--encrypt"
, "--armor"
, "--quiet"
, "--batch"
]
++
concatMap (\r -> ["--recipient", r]) recipients
)
Nothing
Nothing
consumeInput hPutStr hIn input
hGetContents hOut
decryptLbs ::
LBS.ByteString
-> IO LBS.ByteString
decryptLbs input =
do
(hIn, hOut, _, _) <- runInteractiveProcess
"gpg"
[
"--decrypt"
, "--no-mdc-warning"
, "--quiet"
, "--batch"
]
Nothing
Nothing
consumeInput LBS.hPutStr hIn input
LBS.hGetContents hOut
encryptLbs ::
[Recipient]
-> LBS.ByteString
-> IO LBS.ByteString
encryptLbs recipients input =
do
(hIn, hOut, _, _) <- runInteractiveProcess
"gpg"
(
[
"--encrypt"
, "--quiet"
, "--batch"
]
++
concatMap (\r -> ["--recipient", r]) recipients
)
Nothing
Nothing
consumeInput LBS.hPutStr hIn input
LBS.hGetContents hOut
consumeInput ::
(Handle -> a -> IO ())
-> Handle
-> a
-> IO ThreadId
consumeInput putter hIn input =
forkIO
(
do
putter hIn input
hFlush hIn
hClose hIn
)