h-gpgme-0.2.0.0

Copyright(c) Reto Hablützel 2014
LicenseMIT
Maintainerrethab@rethab.ch
Stabilityexperimental
Portabilityuntested
Safe HaskellNone
LanguageHaskell2010

Crypto.Gpgme

Contents

Description

High Level Binding for GnuPG Made Easy (gpgme)

Most of these functions are a one-to-one translation from GnuPG API with some Haskell idiomatics to make the API more convenient.

See the GnuPG manual for more information: https://www.gnupg.org/documentation/manuals/gpgme.pdf

Example (from the tests):

let alice_pub_fpr = "EAACEB8A"

-- encrypt
enc <- withCtx "test/bob" "C" openPGP $ \bCtx ->
          withKey bCtx alice_pub_fpr noSecret $ \aPubKey ->
              encrypt bCtx [aPubKey] noFlag plain

-- decrypt
dec <- withCtx "test/alice" "C" openPGP $ \aCtx ->
        decrypt aCtx (fromJustAndRight enc)

Synopsis

Context

data Ctx Source

Context to be passed around with operations. Use newCtx or withCtx in order to obtain an instance.

newCtx Source

Arguments

:: String

path to gpg homedirectory

-> String

locale

-> Protocol

protocol

-> IO Ctx 

Creates a new Ctx from a homedirectory, a locale and a protocol. Needs to be freed with freeCtx, which is why you are encouraged to use withCtx.

freeCtx :: Ctx -> IO () Source

Free a previously created Ctx

withCtx Source

Arguments

:: String

path to gpg homedirectory

-> String

locale

-> Protocol

protocol

-> (Ctx -> IO a)

action to be run with ctx

-> IO a 

Runs the action with a new Ctx and frees it afterwards

See newCtx for a descrption of the parameters.

withArmor :: (Ctx -> IO a) -> Ctx -> IO a Source

Sets the produced output to be ASCII armored

Inject between withCtx and your 'IO a' like

   withCtx homedir locale OpenPGP $ withArmor $ \ctx ->
       withKey ctx fpr NoSecret $ \pubkey ->
           encrypt ctx [pubkey] NoFlag plaintext

Keys

data Key Source

A key from the context

getKey Source

Arguments

:: Ctx

context to operate in

-> Fpr

fingerprint

-> IncludeSecret

whether to include secrets when searching for the key

-> IO (Maybe Key) 

Returns a Key from the context based on its fingerprint. As a Key returned from the function needs to be freed with freeKey, the use of withKey is encouraged. Returns Nothing if no Key with this Fpr exists.

freeKey :: Key -> IO () Source

Frees a key previously created with getKey

withKey Source

Arguments

:: Ctx

context to operate in

-> Fpr

fingerprint

-> IncludeSecret

whether to include secrets when searching for the key

-> (Key -> IO a)

action to be run with key

-> IO (Maybe a) 

Conveniently runs the action with the Key associated with the Fpr in the Ctx and frees it afterwards. If no Key with this Fpr exists, Nothing is returned.

Encryption

encrypt :: Ctx -> [Key] -> Flag -> Plain -> IO (Either [InvalidKey] Encrypted) Source

encrypt for a list of recipients

encryptSign :: Ctx -> [Key] -> Flag -> Plain -> IO (Either [InvalidKey] Encrypted) Source

encrypt and sign for a list of recipients

encrypt' :: String -> Fpr -> Plain -> IO (Either String Encrypted) Source

Convenience wrapper around withCtx and withKey to encrypt a single plaintext for a single recipient with its homedirectory.

encryptSign' :: String -> Fpr -> Plain -> IO (Either String Encrypted) Source

Convenience wrapper around withCtx and withKey to encrypt and sign a single plaintext for a single recipient with its homedirectory.

decrypt :: Ctx -> Encrypted -> IO (Either DecryptError Plain) Source

Decrypts a ciphertext

decrypt' :: String -> Encrypted -> IO (Either DecryptError Plain) Source

Convenience wrapper around withCtx and withKey to decrypt a single ciphertext with its homedirectory.

decryptVerify :: Ctx -> Encrypted -> IO (Either DecryptError Plain) Source

Decrypts and verifies a ciphertext

decryptVerify' :: String -> Encrypted -> IO (Either DecryptError Plain) Source

Convenience wrapper around withCtx and withKey to decrypt and verify a single ciphertext with its homedirectory.

Other Types

type Fpr = ByteString Source

a fingerprint

type Encrypted = ByteString Source

an ciphertext

type Plain = ByteString Source

a plaintext

data Protocol Source

the protocol to be used in the crypto engine

Constructors

CMS 
GPGCONF 
OpenPGP 
UNKNOWN 

type InvalidKey = (String, Int) Source

The fingerprint and an error code

data IncludeSecret Source

Whether to include secret keys when searching

Constructors

WithSecret

do not include secret keys

NoSecret

include secret keys

data Flag Source

Constructors

AlwaysTrust 
NoFlag 

data DecryptError Source

error indicating what went wrong in decryption

Constructors

NoData

no data to decrypt

Failed

not a valid cipher

BadPass

passphrase for secret was wrong

Unknown Int

something else went wrong