GPGME integration

GPGME integration — MIME operations using caller-owned GPGME contexts

Functions

Description

Include gmime/gmime-gpgme.h and use the gmime-gpgme-4.0 pkg-config package. These APIs are available only in crypto-enabled builds and are not exposed through introspection.

Contexts are borrowed for synchronous, exclusive use. Applications configure protocols, signers, engines, callbacks, network policies, and session-key flags using GPGME. GMime never releases the context or clears its signers. Stream operations respect its armor and text-mode settings; MIME operations temporarily select the required representation and restore those settings.

Optional result outputs start as NULL. Returned results have independent references, including diagnostic results returned on failure, and must be released with gpgme_result_unref(). Nested records are borrowed. Operations replace the context's current results as normal GPGME operations do.

Successful verification means the operation completed, not that signatures are valid or trusted. Inspect each signature's status and validity. Discard partial stream output when an operation fails.

Functions

g_mime_gpgme_data_new ()

gboolean
g_mime_gpgme_data_new (GMimeStream *stream,
                       gpgme_data_t *data,
                       GError **error);

Adapts a stream without copying its contents or resetting its position. The handle owns a reference to stream , released by gpgme_data_release(). Reading, writing, and seeking use the stream's capabilities and absolute stream offsets. The stream is neither flushed nor explicitly closed.

[skip]

Parameters

stream

a stream at the desired starting position

 

data

the new GPGME data handle.

[out]

error

return location for an error

 

Returns

TRUE on success.


g_mime_gpgme_sign ()

gboolean
g_mime_gpgme_sign (gpgme_ctx_t ctx,
                   gpgme_sig_mode_t mode,
                   GMimeStream *input,
                   GMimeStream *output,
                   gpgme_sign_result_t *result,
                   GError **error);

Signs using the context's configured signers and representation settings. No signer list or context configuration is changed.

[skip]

Parameters

ctx

a caller-owned OpenPGP or CMS context

 

mode

the signature mode

 

input

input stream

 

output

signature or signed-content stream

 

result

a retained signing result.

[out][optional]

error

return location for an error

 

Returns

TRUE if signing completed.


g_mime_gpgme_verify ()

gboolean
g_mime_gpgme_verify (gpgme_ctx_t ctx,
                     GMimeStream *input,
                     GMimeStream *signature,
                     GMimeStream *output,
                     gpgme_verify_result_t *result,
                     GError **error);

Verifies without changing context policy. An output stream is required for embedded verification. Inspect individual signatures even on success.

[skip]

Parameters

ctx

a caller-owned OpenPGP or CMS context

 

input

signed content

 

signature

detached signature, or NULL for embedded signatures.

[nullable]

output

extracted content for embedded verification.

[nullable]

result

a retained verification result.

[out][optional]

error

return location for an error

 

Returns

TRUE if verification completed.


g_mime_gpgme_encrypt ()

gboolean
g_mime_gpgme_encrypt (gpgme_ctx_t ctx,
                      gboolean sign,
                      gpgme_encrypt_flags_t flags,
                      gpgme_key_t *recipients,
                      gpgme_key_t *hidden_recipients,
                      GMimeStream *input,
                      GMimeStream *output,
                      gpgme_encrypt_result_t *encrypt_result,
                      gpgme_sign_result_t *sign_result,
                      GError **error);

Encrypts using native keys and context settings. Passing NULL for both recipient arrays requests GPGME's symmetric-encryption behavior; empty arrays are not treated as NULL. Hidden recipients receive the same content without exposing their key IDs. Keys must not appear in both arrays. GPGME_ENCRYPT_THROW_KEYIDS hides all recipient IDs, including those in recipients . With hidden_recipients set, all keys must have valid OpenPGP fingerprints; GPGME selects the encryption subkeys. Combined signing and encryption requires OpenPGP; use nested signed/encrypted MIME entities for CMS.

[skip]

Parameters

ctx

a caller-owned OpenPGP or CMS context

 

sign

whether to sign using the configured signers

 

flags

native GPGME encryption flags

 

recipients

borrowed NULL-terminated recipient keys.

[nullable]

hidden_recipients

borrowed NULL-terminated hidden recipient keys (OpenPGP only).

[nullable]

input

plaintext stream

 

output

ciphertext stream

 

encrypt_result

a retained encryption result.

[out][optional]

sign_result

a retained signing result.

[out][optional]

error

return location for an error

 

Returns

TRUE if encryption completed.


g_mime_gpgme_decrypt ()

gboolean
g_mime_gpgme_decrypt (gpgme_ctx_t ctx,
                      gboolean verify,
                      GMimeStream *input,
                      GMimeStream *output,
                      gpgme_decrypt_result_t *decrypt_result,
                      gpgme_verify_result_t *verify_result,
                      GError **error);

Decrypts without changing network or session-key policies. Configure export-session-key and override-session-key on ctx when needed.

[skip]

Parameters

ctx

a caller-owned OpenPGP or CMS context

 

verify

whether to verify embedded signatures (OpenPGP only)

 

input

ciphertext stream

 

output

plaintext stream

 

decrypt_result

a retained decryption result.

[out][optional]

verify_result

a retained verification result.

[out][optional]

error

return location for an error

 

Returns

TRUE if decryption completed.


g_mime_openpgp_block_verify ()

gboolean
g_mime_openpgp_block_verify (GMimeOpenPGPBlock *block,
                             gpgme_ctx_t ctx,
                             GMimeStream *output,
                             gpgme_verify_result_t *result,
                             GError **error);

Verifies one block without modifying it, its source part, or caller settings. PGP MESSAGE armor may contain opaque signed data; the engine determines whether verification is possible. Standalone signatures and keys are not supported. No key is automatically imported.

Inspect every signature's status and validity; successful completion does not authenticate surrounding text or neighboring blocks. Discard partial output on failure. Release every non-NULL result with gpgme_result_unref(), including diagnostic results returned on failure.

[skip]

Parameters

block

a complete clear-signed or PGP MESSAGE block

 

ctx

a borrowed GPGME OpenPGP context

 

output

stream for extracted bytes

 

result

a retained native verification result.

[out][optional]

error

return location for an error

 

Returns

TRUE if the operation completed, not a signature-validity flag.


g_mime_openpgp_block_decrypt ()

gboolean
g_mime_openpgp_block_decrypt (GMimeOpenPGPBlock *block,
                              gpgme_ctx_t ctx,
                              GMimeStream *output,
                              gpgme_decrypt_result_t *decrypt_result,
                              gpgme_verify_result_t *verify_result,
                              GError **error);

Decrypts and verifies embedded signatures for this block only. Neither the snapshot nor the source part is modified. Caller context settings, including session-key flags and passphrase handling, are preserved. Output is not interpreted as MIME, HTML, or another inline-PGP document.

Decryption alone does not authenticate a sender. Inspect native signature results and keep each output associated with its source block. Discard partial output on failure; release all returned results using gpgme_result_unref(), even if the operation failed.

[skip]

Parameters

block

a complete PGP MESSAGE block

 

ctx

a borrowed GPGME OpenPGP context

 

output

stream for decrypted bytes

 

decrypt_result

a retained decryption result.

[out][optional]

verify_result

a retained verification result.

[out][optional]

error

return location for an error

 

Returns

TRUE if the operation completed.