changed get_id/get_encoding API of private/public key to use new encoding framework
[strongswan.git] / src / libstrongswan / credentials / keys / private_key.h
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup private_key private_key
18 * @{ @ingroup keys
19 */
20
21 #ifndef PRIVATE_KEY_H_
22 #define PRIVATE_KEY_H_
23
24 typedef struct private_key_t private_key_t;
25
26 #include <credentials/keys/public_key.h>
27
28 /**
29 * Abstract private key interface.
30 */
31 struct private_key_t {
32
33 /**
34 * Get the key type.
35 *
36 * @return type of the key
37 */
38 key_type_t (*get_type)(private_key_t *this);
39
40 /**
41 * Create a signature over a chunk of data.
42 *
43 * @param scheme signature scheme to use
44 * @param data chunk of data to sign
45 * @param signature where to allocate created signature
46 * @return TRUE if signature created
47 */
48 bool (*sign)(private_key_t *this, signature_scheme_t scheme,
49 chunk_t data, chunk_t *signature);
50 /**
51 * Decrypt a chunk of data.
52 *
53 * @param crypto chunk containing encrypted data
54 * @param plain where to allocate decrypted data
55 * @return TRUE if data decrypted and plaintext allocated
56 */
57 bool (*decrypt)(private_key_t *this, chunk_t crypto, chunk_t *plain);
58
59 /**
60 * Get the strength of the key in bytes.
61 *
62 * @return strength of the key in bytes
63 */
64 size_t (*get_keysize) (private_key_t *this);
65
66 /**
67 * Get the public part from the private key.
68 *
69 * @return public key
70 */
71 public_key_t* (*get_public_key)(private_key_t *this);
72
73 /**
74 * Check if two private keys are equal.
75 *
76 * @param other other private key
77 * @return TRUE, if equality
78 */
79 bool (*equals) (private_key_t *this, private_key_t *other);
80
81 /**
82 * Check if a private key belongs to a public key.
83 *
84 * @param public public key
85 * @return TRUE, if keys belong together
86 */
87 bool (*belongs_to) (private_key_t *this, public_key_t *public);
88
89 /**
90 * Get the fingerprint of the key.
91 *
92 * @param type type of fingerprint, one of KEY_ID_*
93 * @param fp fingerprint, points to internal data
94 * @return TRUE if fingerprint type supported
95 */
96 bool (*get_fingerprint)(private_key_t *this, key_encoding_type_t type,
97 chunk_t *fp);
98
99 /**
100 * Get the key in an encoded form as a chunk.
101 *
102 * @param type type of the encoding, one of KEY_PRIV_*
103 * @param encoding encoding of the key, allocated
104 * @return TRUE if encoding supported
105 */
106 bool (*get_encoding)(private_key_t *this, key_encoding_type_t type,
107 chunk_t *encoding);
108
109 /**
110 * Increase the refcount to this private key.
111 *
112 * @return this, with an increased refcount
113 */
114 private_key_t* (*get_ref)(private_key_t *this);
115
116 /**
117 * Decrease refcount, destroy private_key if no more references.
118 */
119 void (*destroy)(private_key_t *this);
120 };
121
122 /**
123 * Generic private key equals() implementation, usable by implementors.
124 *
125 * @param this first key to compare
126 * @param other second key to compare
127 * @return TRUE if this is equal to other
128 */
129 bool private_key_equals(private_key_t *this, private_key_t *other);
130
131 /**
132 * Generic private key belongs_to() implementation, usable by implementors.
133 *
134 * @param this first key to compare
135 * @param other second key to compare
136 * @return TRUE if this is equal to other
137 */
138 bool private_key_belongs_to(private_key_t *private, public_key_t *public);
139
140 #endif /** PRIVATE_KEY_H_ @}*/