]> git.notmuchmail.org Git - notmuch/blob - util/crypto.h
util/crypto: add information about the payload part
[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     /* the value of any "Subject:" header in the cryptographic payload
63      * (the top level part within the crypto envelope), converted to
64      * UTF-8 */
65     char * payload_subject;
66
67     /* if both signed and encrypted, was the signature encrypted? */
68     bool signature_encrypted;
69 } _notmuch_message_crypto_t;
70
71
72 /* _notmuch_message_crypto_t objects should be released with
73  * talloc_free (), or they will be released along with their parent
74  * context.
75  */
76 _notmuch_message_crypto_t *
77 _notmuch_message_crypto_new (void *ctx);
78
79 /* call potential_sig_list during a depth-first-search on a message to
80  * consider a particular signature as relevant for the message.
81  */
82 notmuch_status_t
83 _notmuch_message_crypto_potential_sig_list (_notmuch_message_crypto_t *msg_crypto, GMimeSignatureList *sigs);
84
85 /* call successful_decryption during a depth-first-search on a message
86  * to indicate that a part was successfully decrypted.
87  */
88 notmuch_status_t
89 _notmuch_message_crypto_successful_decryption (_notmuch_message_crypto_t *msg_crypto);
90
91 /* call potential_payload during a depth-first-search on a message
92  * when encountering a message part that is not part of the envelope.
93  */
94 notmuch_status_t
95 _notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto, GMimeObject *payload, GMimeObject *parent, int childnum);
96
97
98 #ifdef __cplusplus
99 }
100 #endif
101 #endif