caf7e6b064b3913f0be330cdc8dbd5f7bab412fe
[strongswan.git] / Source / charon / encoding / payloads / encryption_payload.h
1 /**
2 * @file encryption_payload.h
3 *
4 * @brief Interface of encryption_payload_t.
5 */
6
7 /*
8 * Copyright (C) 2005 Jan Hutter, Martin Willi
9 * Hochschule fuer Technik Rapperswil
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 */
21
22 #ifndef ENCRYPTION_PAYLOAD_H_
23 #define ENCRYPTION_PAYLOAD_H_
24
25 #include <types.h>
26 #include <transforms/crypters/crypter.h>
27 #include <transforms/signers/signer.h>
28 #include <encoding/payloads/payload.h>
29 #include <utils/linked_list.h>
30
31 /**
32 * Encrpytion payload length in bytes without IV and following data.
33 */
34 #define ENCRYPTION_PAYLOAD_HEADER_LENGTH 4
35
36
37 typedef struct encryption_payload_t encryption_payload_t;
38
39 /**
40 * @brief The encryption payload as described in RFC section 3.14.
41 *
42 * @ingroup payloads
43 */
44 struct encryption_payload_t {
45 /**
46 * Implements payload_t interface.
47 */
48 payload_t payload_interface;
49
50 /**
51 * @brief Creates an iterator for all contained payloads.
52 *
53 * @warning iterator_t object has to get destroyed by the caller.
54 *
55 * @param this calling encryption_payload_t object
56 * @param[in] forward iterator direction (TRUE: front to end)
57 * return created iterator_t object
58 */
59 iterator_t *(*create_payload_iterator) (encryption_payload_t *this, bool forward);
60
61 /**
62 * @brief Adds a payload to this encryption payload.
63 *
64 * @param this calling encryption_payload_t object
65 * @param payload payload_t object to add
66 */
67 void (*add_payload) (encryption_payload_t *this, payload_t *payload);
68
69 /**
70 * @brief Decrypt and return contained data.
71 *
72 * Decrypt the contained data (encoded payloads) using supplied crypter.
73 *
74 * @param this calling encryption_payload_t
75 * @param crypter crypter_t to use for data decryption
76 * @param[out]data resulting data in decrypted and unpadded form
77 * @return
78 * - SUCCESS, or
79 * - FAILED if crypter does not match data
80 */
81
82 void (*set_signer) (encryption_payload_t *this, signer_t *signer);
83
84 status_t (*encrypt) (encryption_payload_t *this, crypter_t *crypter);
85 status_t (*decrypt) (encryption_payload_t *this, crypter_t *crypter);
86
87 status_t (*build_signature) (encryption_payload_t *this, chunk_t data);
88 status_t (*verify_signature) (encryption_payload_t *this, chunk_t data);
89
90 /**
91 * @brief Destroys an encryption_payload_t object.
92 *
93 * @param this encryption_payload_t object to destroy
94 */
95 void (*destroy) (encryption_payload_t *this);
96 };
97
98 /**
99 * @brief Creates an empty encryption_payload_t object.
100 *
101 * @return created encryption_payload_t object
102 *
103 * @ingroup payloads
104 */
105
106 encryption_payload_t *encryption_payload_create();
107
108 #endif /*ENCRYPTION_PAYLOAD_H_*/