1 /* decrypt-verify.c - Decrypt and verify function.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34 decrypt_verify_status_handler (void *priv, gpgme_status_code_t code,
39 err = _gpgme_progress_status_handler (priv, code, args);
41 err = _gpgme_decrypt_status_handler (priv, code, args);
43 err = _gpgme_verify_status_handler (priv, code, args);
49 decrypt_verify_start (gpgme_ctx_t ctx, int synchronous,
50 gpgme_decrypt_flags_t flags,
51 gpgme_data_t cipher, gpgme_data_t plain)
55 assert ((flags & GPGME_DECRYPT_VERIFY));
57 err = _gpgme_op_reset (ctx, synchronous);
61 err = _gpgme_op_decrypt_init_result (ctx);
65 err = _gpgme_op_verify_init_result (ctx);
70 return gpg_error (GPG_ERR_NO_DATA);
72 return gpg_error (GPG_ERR_INV_VALUE);
74 if (ctx->passphrase_cb)
76 err = _gpgme_engine_set_command_handler
77 (ctx->engine, _gpgme_passphrase_command_handler, ctx, NULL);
82 _gpgme_engine_set_status_handler (ctx->engine,
83 decrypt_verify_status_handler, ctx);
85 return _gpgme_engine_op_decrypt (ctx->engine,
88 ctx->export_session_keys,
89 ctx->override_session_key,
90 ctx->auto_key_retrieve);
94 /* Decrypt ciphertext CIPHER and make a signature verification within
95 CTX and store the resulting plaintext in PLAIN. */
97 gpgme_op_decrypt_verify_start (gpgme_ctx_t ctx, gpgme_data_t cipher,
102 TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify_start", ctx,
103 "cipher=%p, plain=%p", cipher, plain);
106 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
108 err = decrypt_verify_start (ctx, 0, GPGME_DECRYPT_VERIFY, cipher, plain);
109 return TRACE_ERR (err);
113 /* Decrypt ciphertext CIPHER and make a signature verification within
114 CTX and store the resulting plaintext in PLAIN. */
116 gpgme_op_decrypt_verify (gpgme_ctx_t ctx, gpgme_data_t cipher,
121 TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify", ctx,
122 "cipher=%p, plain=%p", cipher, plain);
125 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
127 err = decrypt_verify_start (ctx, 1, GPGME_DECRYPT_VERIFY, cipher, plain);
129 err = _gpgme_wait_one (ctx);
130 return TRACE_ERR (err);
134 /* Decrypt ciphertext CIPHER within CTX and store the resulting
135 plaintext in PLAIN. */
137 gpgme_op_decrypt_ext_start (gpgme_ctx_t ctx,
138 gpgme_decrypt_flags_t flags,
144 TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_ext_start", ctx,
145 "cipher=%p, plain=%p", cipher, plain);
148 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
150 if ((flags & GPGME_DECRYPT_VERIFY))
151 err = decrypt_verify_start (ctx, 0, flags, cipher, plain);
153 err = _gpgme_decrypt_start (ctx, 0, flags, cipher, plain);
154 return TRACE_ERR (err);
158 /* Decrypt ciphertext CIPHER within CTX and store the resulting
159 plaintext in PLAIN. */
161 gpgme_op_decrypt_ext (gpgme_ctx_t ctx,
162 gpgme_decrypt_flags_t flags,
168 TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_ext", ctx,
169 "cipher=%p, plain=%p", cipher, plain);
172 return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
174 if ((flags & GPGME_DECRYPT_VERIFY))
175 err = decrypt_verify_start (ctx, 1, flags, cipher, plain);
177 err = _gpgme_decrypt_start (ctx, 1, flags, cipher, plain);
179 err = _gpgme_wait_one (ctx);
180 return TRACE_ERR (err);