316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi#ifndef ISTREAM_DECRYPT_H
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi#define ISTREAM_DECRYPT_H
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomistruct dcrypt_private_key;
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomistruct dcrypt_context_symmetric;
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvienum decrypt_istream_format {
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvi DECRYPT_FORMAT_V1,
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvi DECRYPT_FORMAT_V2
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvi};
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi/* Look for a private key for a specified public key digest and set it to
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi priv_key_r. Returns 1 if ok, 0 if key doesn't exist, -1 on internal error. */
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomitypedef int
269a38b5e60ad8698d6ea56e4a500be2f2486795Aki Tuomii_stream_decrypt_get_key_callback_t(const char *pubkey_digest,
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi struct dcrypt_private_key **priv_key_r,
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi const char **error_r, void *context);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomistruct istream *
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomii_stream_create_decrypt(struct istream *input, struct dcrypt_private_key *priv_key);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi/* create stream for reading plain encrypted data with no header or MAC.
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi do not call dcrypt_ctx_sym_init
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi */
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomistruct istream *
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomii_stream_create_sym_decrypt(struct istream *input, struct dcrypt_context_symmetric *ctx);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi/* Decrypt the istream. When a private key is needed, the callback will be
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi called. This allows using multiple private keys for different mails. */
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomistruct istream *
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomii_stream_create_decrypt_callback(struct istream *input,
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi i_stream_decrypt_get_key_callback_t *callback,
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi void *context);
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvi
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvienum decrypt_istream_format i_stream_encrypt_get_format(const struct istream *input);
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvienum io_stream_encrypt_flags i_stream_encrypt_get_flags(const struct istream *input);
ebd1c50bc43e08ee0a05ad68c7d48497a1563fabMartti Rannanjärvi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi#endif