Keep "gpg_homedir" and list file settings across SIGHUP.
[libpwmd.git] / src / crypto.h
blob9bb86a1c8ecded1cf0794eb29f0ba0e8525f1d64
1 /*
2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
3 2016
4 Ben Kibbey <bjk@luxsci.net>
6 This file is part of pwmd.
8 Pwmd is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 Pwmd is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef CRYPTO_H
22 #define CRYPTO_H
24 #include <assuan.h>
25 #include <gpg-error.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <gpgme.h>
29 #include <time.h>
31 #ifdef HAVE_STDINT_H
32 #include <stdint.h>
33 #elif defined (HAVE_INTTYPES_H)
34 #include <inttypes.h>
35 #endif
37 #include "common.h"
39 #define CRYPTO_FLAG_NEWFILE 0x0001
40 #define CRYPTO_FLAG_KEYFILE 0x0002 // --passphrase-file with --import
41 #define CRYPTO_FLAG_SYMMETRIC 0x0004
42 #define CRYPTO_FLAG_PASSWD 0x0008
43 #define CRYPTO_FLAG_PASSWD_NEW 0x0010
44 #define CRYPTO_FLAG_PASSWD_SIGN 0x0020
46 struct save_s
48 char **pubkey; /* SAVE --keyid */
49 char **sigkey; /* SAVE --sign-keyid */
52 struct crypto_s
54 assuan_context_t client_ctx;
55 gpgme_ctx_t ctx;
56 unsigned char *plaintext;
57 size_t plaintext_size;
58 gpgme_data_t cipher;
59 char **pubkey;
60 char **sigkey;
61 char *filename; /* the currently opened data file */
62 struct save_s save;
63 gpg_error_t progress_rc;
64 time_t status_timeout;
65 uint32_t flags;
66 char *keyfile;
69 gpgme_error_t crypto_init (struct crypto_s **, void *, const char *, int,
70 char *passphrase_file);
71 gpgme_error_t crypto_init_ctx (struct crypto_s *, int, char *passphrase_file);
72 gpgme_error_t crypto_genkey (struct client_s *, struct crypto_s *,
73 const unsigned char *);
74 gpgme_error_t crypto_encrypt (struct client_s *, struct crypto_s *);
75 gpgme_error_t crypto_decrypt (struct client_s *, struct crypto_s *);
76 gpgme_error_t crypto_passwd (struct client_s *, struct crypto_s *);
77 void crypto_free (struct crypto_s *);
78 void crypto_free_save (struct save_s *);
79 void crypto_free_non_keys (struct crypto_s *);
80 gpgme_error_t crypto_data_to_buf (const gpgme_data_t, unsigned char **,
81 size_t *);
82 char *crypto_default_key_params ();
83 gpg_error_t crypto_write_file (struct crypto_s *);
84 gpgme_error_t crypto_list_keys (struct crypto_s *, char **, int secret,
85 gpgme_key_t **);
86 char *crypto_key_info (const gpgme_key_t);
87 void crypto_free_key_list (gpgme_key_t *);
88 gpg_error_t crypto_try_decrypt (struct client_s *, int);
89 void crypto_set_keepalive ();
90 gpg_error_t crypto_is_symmetric (const char *filename);
91 gpg_error_t crypto_keyid_to_16b (char **keys);
93 #endif