xref: /netbsd-src/crypto/external/bsd/netpgp/dist/src/lib/keyring.h (revision 7f21db1c0118155e0dd40b75182e30c589d9f63e)
1 /*-
2  * Copyright (c) 2009 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The NetBSD Foundation
6  * by Alistair Crooks (agc@NetBSD.org)
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 /*
30  * Copyright (c) 2005-2008 Nominet UK (www.nic.uk)
31  * All rights reserved.
32  * Contributors: Ben Laurie, Rachel Willmer. The Contributors have asserted
33  * their moral rights under the UK Copyright Design and Patents Act 1988 to
34  * be recorded as the authors of this copyright work.
35  *
36  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
37  * use this file except in compliance with the License.
38  *
39  * You may obtain a copy of the License at
40  *     http://www.apache.org/licenses/LICENSE-2.0
41  *
42  * Unless required by applicable law or agreed to in writing, software
43  * distributed under the License is distributed on an "AS IS" BASIS,
44  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45  *
46  * See the License for the specific language governing permissions and
47  * limitations under the License.
48  */
49 
50 /** \file
51  */
52 
53 #ifndef KEYRING_H_
54 #define KEYRING_H_
55 
56 #include "packet.h"
57 #include "packet-parse.h"
58 
59 enum {
60 	MAX_ID_LENGTH		= 128,
61 	MAX_PASSPHRASE_LENGTH	= 256
62 };
63 
64 typedef struct __ops_key_t	__ops_key_t;
65 
66 /** \struct __ops_keyring_t
67  * A keyring
68  */
69 typedef struct __ops_keyring_t {
70 	DYNARRAY(__ops_key_t,	key);
71 } __ops_keyring_t;
72 
73 const __ops_key_t *__ops_getkeybyid(__ops_io_t *,
74 					const __ops_keyring_t *,
75 					const unsigned char *,
76 					unsigned *);
77 const __ops_key_t *__ops_getkeybyname(__ops_io_t *,
78 					const __ops_keyring_t *,
79 					const char *);
80 const __ops_key_t *__ops_getnextkeybyname(__ops_io_t *,
81 					const __ops_keyring_t *,
82 					const char *,
83 					unsigned *);
84 void __ops_keydata_free(__ops_key_t *);
85 void __ops_keyring_free(__ops_keyring_t *);
86 void __ops_dump_keyring(const __ops_keyring_t *);
87 const __ops_pubkey_t *__ops_get_pubkey(const __ops_key_t *);
88 unsigned   __ops_is_key_secret(const __ops_key_t *);
89 const __ops_seckey_t *__ops_get_seckey(const __ops_key_t *);
90 __ops_seckey_t *__ops_get_writable_seckey(__ops_key_t *);
91 __ops_seckey_t *__ops_decrypt_seckey(const __ops_key_t *, void *);
92 
93 unsigned   __ops_keyring_fileread(__ops_keyring_t *, const unsigned,
94 					const char *);
95 
96 int __ops_keyring_list(__ops_io_t *, const __ops_keyring_t *);
97 
98 void __ops_set_seckey(__ops_contents_t *, const __ops_key_t *);
99 void __ops_forget(void *, unsigned);
100 
101 const unsigned char *__ops_get_key_id(const __ops_key_t *);
102 unsigned __ops_get_userid_count(const __ops_key_t *);
103 const unsigned char *__ops_get_userid(const __ops_key_t *, unsigned);
104 unsigned __ops_is_key_supported(const __ops_key_t *);
105 
106 __ops_userid_t *__ops_add_userid(__ops_key_t *, const __ops_userid_t *);
107 __ops_subpacket_t *__ops_add_subpacket(__ops_key_t *,
108 						const __ops_subpacket_t *);
109 void __ops_add_signed_userid(__ops_key_t *,
110 					const __ops_userid_t *,
111 					const __ops_subpacket_t *);
112 
113 unsigned __ops_add_selfsigned_userid(__ops_key_t *, __ops_userid_t *);
114 
115 __ops_key_t  *__ops_keydata_new(void);
116 void __ops_keydata_init(__ops_key_t *, const __ops_content_tag_t);
117 
118 int __ops_parse_and_accumulate(__ops_keyring_t *, __ops_stream_t *);
119 
120 void __ops_pkeyid(FILE *, const unsigned char *, size_t);
121 
122 int __ops_sprint_keydata(const __ops_key_t *, char **, const char *,
123 			const __ops_pubkey_t *);
124 int __ops_hkp_sprint_keydata(const __ops_key_t *, char **,
125 			const __ops_pubkey_t *);
126 void __ops_print_keydata(__ops_io_t *, const __ops_key_t *,
127 			const char *, const __ops_pubkey_t *);
128 void __ops_print_pubkey(const __ops_pubkey_t *);
129 int __ops_sprint_pubkey(const __ops_key_t *, char *, size_t);
130 
131 int __ops_list_packets(__ops_io_t *,
132 			char *,
133 			unsigned,
134 			__ops_keyring_t *,
135 			void *,
136 			__ops_cbfunc_t *);
137 
138 int __ops_export_key(const __ops_key_t *, unsigned char *);
139 
140 int __ops_add_to_pubring(__ops_keyring_t *, const __ops_pubkey_t *);
141 int __ops_add_to_secring(__ops_keyring_t *, const __ops_seckey_t *);
142 
143 int __ops_append_keyring(__ops_keyring_t *, __ops_keyring_t *);
144 
145 #endif /* KEYRING_H_ */
146