]> git.notmuchmail.org Git - notmuch/blob - util/crypto.h
c6fa7f4b76578b63d5f6aa1008b58cf10ec3b64c
[notmuch] / util / crypto.h
1 #ifndef _CRYPTO_H
2 #define _CRYPTO_H
3
4 #include <stdbool.h>
5 #include "gmime-extra.h"
6 #include "notmuch.h"
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 typedef struct _notmuch_crypto {
13     bool verify;
14     notmuch_decryption_policy_t decrypt;
15 } _notmuch_crypto_t;
16
17 GMimeObject *
18 _notmuch_crypto_decrypt (bool *attempted,
19                          notmuch_decryption_policy_t decrypt,
20                          notmuch_message_t *message,
21                          GMimeMultipartEncrypted *part,
22                          GMimeDecryptResult **decrypt_result,
23                          GError **err);
24
25 void
26 _notmuch_crypto_cleanup (_notmuch_crypto_t *crypto);
27
28 /* The user probably wants to know if the entire message was in the
29  * clear.  When replying, the MUA probably wants to know whether there
30  * was any part decrypted in the message.  And when displaying to the
31  * user, we probably only want to display "encrypted message" if the
32  * entire message was covered by encryption. */
33 typedef enum {
34     NOTMUCH_MESSAGE_DECRYPTED_NONE = 0,
35     NOTMUCH_MESSAGE_DECRYPTED_PARTIAL,
36     NOTMUCH_MESSAGE_DECRYPTED_FULL,
37 } _notmuch_message_decryption_status_t;
38
39 /* description of the cryptographic state of a given message overall;
40  * for use by simple user agents.
41  */
42 typedef struct _notmuch_message_crypto {
43     /* encryption status: partial, full, none */
44     _notmuch_message_decryption_status_t decryption_status;
45     /* FIXME: can we show what key(s) a fully-encrypted message was
46      * encrypted to? This data is not necessarily cryptographically
47      * reliable; even when we decrypt, we might not know which public
48      * key was used (e.g. if we're using a session key). */
49
50     /* signature status of the whole message (either the whole message
51      * is signed, or it is not) -- this means that partially-signed
52      * messages will get no signature status. */
53     GMimeSignatureList * sig_list;
54     /* if part of the message was signed, and the MUA is clever, it
55      * can determine on its own exactly which part and try to make
56      * more sense of it. */
57
58     /* mark this flag once we encounter a payload (i.e. something that
59      * is not part of the cryptographic envelope) */
60     bool payload_encountered;
61
62     /* if both signed and encrypted, was the signature encrypted? */
63     bool signature_encrypted;
64 } _notmuch_message_crypto_t;
65
66
67 /* _notmuch_message_crypto_t objects should be released with
68  * talloc_free (), or they will be released along with their parent
69  * context.
70  */
71 _notmuch_message_crypto_t *
72 _notmuch_message_crypto_new (void *ctx);
73
74 /* call potential_sig_list during a depth-first-search on a message to
75  * consider a particular signature as relevant for the message.
76  */
77 notmuch_status_t
78 _notmuch_message_crypto_potential_sig_list (_notmuch_message_crypto_t *msg_crypto, GMimeSignatureList *sigs);
79
80 /* call successful_decryption during a depth-first-search on a message
81  * to indicate that a part was successfully decrypted.
82  */
83 notmuch_status_t
84 _notmuch_message_crypto_successful_decryption (_notmuch_message_crypto_t *msg_crypto);
85
86 /* call potential_payload during a depth-first-search on a message
87  * when encountering a message part that is not part of the envelope.
88  */
89 notmuch_status_t
90 _notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto, GMimeObject *payload, GMimeObject *parent, int childnum);
91
92
93 #ifdef __cplusplus
94 }
95 #endif
96 #endif