gpgme/
[gpgme.git] / gpgme / decrypt-verify.c
1 /* decrypt-verify.c -  decrypt and verify functions
2  *      Copyright (C) 2000 Werner Koch (dd9jn)
3  *      Copyright (C) 2001 g10 Code GmbH
4  *
5  * This file is part of GPGME.
6  *
7  * GPGME is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * GPGME is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20  */
21
22 #include <config.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <assert.h>
27
28 #include "util.h"
29 #include "context.h"
30 #include "ops.h"
31
32 static void
33 decrypt_verify_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
34 {
35   _gpgme_decrypt_status_handler (ctx, code, args);
36   _gpgme_verify_status_handler (ctx, code, args);
37 }
38
39 GpgmeError
40 gpgme_op_decrypt_verify_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain)
41 {
42   return _gpgme_decrypt_start (ctx, ciph, plain,
43                                decrypt_verify_status_handler);
44 }
45
46 /**
47  * gpgme_op_decrypt_verify:
48  * @ctx: The context
49  * @in: ciphertext input
50  * @out: plaintext output
51  * 
52  * This function decrypts @in to @out and performs a signature check.
53  * Other parameters are take from the context @c.
54  * The function does wait for the result.
55  * 
56  * Return value:  0 on success or an errorcode. 
57  **/
58 GpgmeError
59 gpgme_op_decrypt_verify (GpgmeCtx ctx,
60                          GpgmeData in, GpgmeData out,
61                          GpgmeSigStat *r_stat)
62 {
63   GpgmeError err = gpgme_op_decrypt_verify_start (ctx, in, out);
64   if (!err)
65     {
66       gpgme_wait (ctx, 1);
67       if (!ctx->result.decrypt || !ctx->result.verify)
68         err = mk_error (General_Error);
69       else if (ctx->out_of_core)
70         err = mk_error (Out_Of_Core);
71       else
72         {
73           err = _gpgme_decrypt_result (ctx);
74           if (! err)
75             *r_stat = _gpgme_intersect_stati (ctx->result.verify);
76         }
77       ctx->pending = 0;
78     }
79   return err;
80 }