projects/libpws

view include/pws.h @ 13:2bb1bbac1d0a

Added tag version-1.0.0 for changeset 1926dfc9feb0
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Sun Aug 04 21:37:56 2019 +0200 (2019-08-04)
parents d541e748cfd8
children
line source
1 /*
2 * Copyright (C) 2015 Guido Berhoerster <guido+libpws@berhoerster.name>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
24 #ifndef PWS_H
25 #define PWS_H
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
31 #include <stdint.h>
32 #include <sys/types.h>
33 #include <stdio.h>
35 #define LIBPWS_VERSION_MAJOR 1
36 #define LIBPWS_VERSION_MINOR 0
37 #define LIBPWS_VERSION_MICRO 0
39 #define PWS3_VERSION 0x030E
41 #define PWS3_MAX_FIELD_SIZE (16 * 1024)
42 #define PWS3_MAX_PASSWORD_LEN 1023
43 #define PWS3_UUID_SIZE 16
45 struct pws3_field;
46 struct pws3_record;
47 struct pws3_file;
49 enum pws_error_code {
50 PWS_ERR_GENERIC_ERROR,
51 PWS_ERR_NO_MEMORY,
52 PWS_ERR_IO_ERROR,
53 PWS_ERR_TRUNCATED_FILE,
54 PWS_ERR_INVALID_CHECKSUM,
55 PWS_ERR_INVALID_RECORD,
56 PWS_ERR_INVALID_HEADER,
57 PWS_ERR_UNSUPPORTED_VERSION
58 };
60 enum pws_data_type {
61 PWS_DATA_TYPE_BYTES,
62 PWS_DATA_TYPE_UUID,
63 PWS_DATA_TYPE_TEXT,
64 PWS_DATA_TYPE_TIME,
65 PWS_DATA_TYPE_UINT8,
66 PWS_DATA_TYPE_UINT16,
67 PWS_DATA_TYPE_UINT32
68 };
70 enum pws3_header_field_type {
71 PWS3_HEADER_FIELD_VERSION, /* 0x00 */
72 PWS3_HEADER_FIELD_UUID, /* 0x01 */
73 PWS3_HEADER_FIELD_NON_DEFAULT_PREFERENCES, /* 0x02 */
74 PWS3_HEADER_FIELD_TREE_DISPLAY_STATUS, /* 0x03 */
75 PWS3_HEADER_FIELD_SAVE_TIMESTAMP, /* 0x04 */
76 PWS3_HEADER_FIELD_SAVE_USER_HOST, /* 0x05 */
77 PWS3_HEADER_FIELD_SAVE_APPLICATION, /* 0x06 */
78 PWS3_HEADER_FIELD_SAVE_USER, /* 0x07 */
79 PWS3_HEADER_FIELD_SAVE_HOST, /* 0x08 */
80 PWS3_HEADER_FIELD_DATABASE_NAME, /* 0x09 */
81 PWS3_HEADER_FIELD_DATABASE_DESCRIPTION, /* 0x0a */
82 PWS3_HEADER_FIELD_DATABASE_FILTERS, /* 0x0b */
83 PWS3_HEADER_FIELD_RESERVED_1, /* 0x0c */
84 PWS3_HEADER_FIELD_RESERVED_2, /* 0x0d */
85 PWS3_HEADER_FIELD_RESERVED_3, /* 0x0e */
86 PWS3_HEADER_FIELD_RECENTLY_USED_ENTRIES, /* 0x0f */
87 PWS3_HEADER_FIELD_NAMED_PASSWORD_POLICIES, /* 0x10 */
88 PWS3_HEADER_FIELD_EMPTY_GROUPS, /* 0x11 */
89 PWS3_HEADER_FIELD_YUBICO, /* 0x12 */
90 PWS3_HEADER_FIELD_PASSWORD_TIMESTAMP, /* 0x13 */
91 PWS3_HEADER_FIELD_END = 0xff
92 };
94 enum pws3_record_field_type {
95 PWS3_RECORD_FIELD_UUID = 0x01,
96 PWS3_RECORD_FIELD_GROUP, /* 0x02 */
97 PWS3_RECORD_FIELD_TITLE, /* 0x03 */
98 PWS3_RECORD_FIELD_USERNAME, /* 0x04 */
99 PWS3_RECORD_FIELD_NOTES, /* 0x05 */
100 PWS3_RECORD_FIELD_PASSWORD, /* 0x06 */
101 PWS3_RECORD_FIELD_CREATION_TIME, /* 0x07 */
102 PWS3_RECORD_FIELD_PASSWORD_MODIFICATION_TIME, /* 0x08 */
103 PWS3_RECORD_FIELD_ACCESS_TIME, /* 0x09 */
104 PWS3_RECORD_FIELD_PASSWORD_EXPIRY_TIME, /* 0x0a */
105 PWS3_RECORD_FIELD_RESERVED_1, /* 0x0b */
106 PWS3_RECORD_FIELD_MODIFICATION_TIME, /* 0x0c */
107 PWS3_RECORD_FIELD_URL, /* 0x0d */
108 PWS3_RECORD_FIELD_AUTOTYPE, /* 0x0e */
109 PWS3_RECORD_FIELD_PASSWORD_HISTORY, /* 0x0f */
110 PWS3_RECORD_FIELD_PASSWORD_POLICY, /* 0x10 */
111 PWS3_RECORD_FIELD_PASSWORD_EXPIRY_INTERVAL, /* 0x11 */
112 PWS3_RECORD_FIELD_RUN_COMMAND, /* 0x12 */
113 PWS3_RECORD_FIELD_DOUBLE_CLICK_ACTION, /* 0x13 */
114 PWS3_RECORD_FIELD_EMAIL_ADDRESS, /* 0x14 */
115 PWS3_RECORD_FIELD_PROTECTED, /* 0x15 */
116 PWS3_RECORD_FIELD_ALLOWED_PASSWORD_SYMBOLS, /* 0x16 */
117 PWS3_RECORD_FIELD_SHIFT_DOUBLE_CLICK_ACTION, /* 0x17 */
118 PWS3_RECORD_FIELD_PASSWORD_POLICY_NAME, /* 0x18 */
119 PWS3_RECORD_FIELD_KEYBOARD_SHORTCUT, /* 0x19 */
120 PWS3_RECORD_FIELD_RESERVED_2, /* 0x1a */
121 PWS3_RECORD_FIELD_TWO_FACTOR_KEY, /* 0x1b */
122 PWS3_RECORD_FIELD_CREDIT_CARD_NUMBER, /* 0x1c */
123 PWS3_RECORD_FIELD_CREDIT_CARD_EXPIRATION, /* 0x1d */
124 PWS3_RECORD_FIELD_CREDIT_CARD_VERIFICATION_VALUE, /* 0x1e */
125 PWS3_RECORD_FIELD_CREDIT_CARD_PIN, /* 0x1f */
126 PWS3_RECORD_FIELD_QR_CODE, /* 0x20 */
127 PWS3_RECORD_FIELD_TESTING_1, /* 0xdf */
128 PWS3_RECORD_FIELD_END = 0xff
129 };
131 int pws_init(void);
132 void pws_finalize(void);
133 void pws_set_alloc_functions(void *(*)(size_t),
134 void *(*)(void *, size_t), void (*)(void *, size_t), void *(*)(size_t),
135 void *(*)(void *, size_t), void (*)(void *, size_t));
136 int pws_generate_uuid(unsigned char [static PWS3_UUID_SIZE]);
138 struct pws3_field * pws3_field_create(int, uint8_t);
139 void pws3_field_destroy(struct pws3_field *);
140 int pws3_field_is_header(struct pws3_field *);
141 uint8_t pws3_field_get_type(struct pws3_field *);
142 enum pws_data_type pws3_field_get_data_type(struct pws3_field *);
143 int pws3_field_set_uuid(struct pws3_field *,
144 const unsigned char [static PWS3_UUID_SIZE]);
145 int pws3_field_set_text(struct pws3_field *, const char [static 1]);
146 int pws3_field_set_time(struct pws3_field *, time_t);
147 int pws3_field_set_uint8(struct pws3_field *, uint8_t);
148 int pws3_field_set_uint16(struct pws3_field *, uint16_t);
149 int pws3_field_set_uint32(struct pws3_field *, uint32_t);
150 int pws3_field_set_bytes(struct pws3_field *,
151 const unsigned char [static 1], size_t);
152 const unsigned char * pws3_field_get_uuid(struct pws3_field *);
153 const char * pws3_field_get_text(struct pws3_field *);
154 time_t pws3_field_get_time(struct pws3_field *);
155 uint8_t pws3_field_get_uint8(struct pws3_field *);
156 uint16_t pws3_field_get_uint16(struct pws3_field *);
157 uint32_t pws3_field_get_uint32(struct pws3_field *);
158 void pws3_field_get_bytes(struct pws3_field *,
159 const unsigned char **, size_t *);
161 void pws3_record_destroy(struct pws3_record *);
162 struct pws3_record * pws3_record_create(void);
163 void pws3_record_set_field(struct pws3_record *,
164 struct pws3_field *);
165 struct pws3_field * pws3_record_get_field(struct pws3_record *, uint8_t);
166 struct pws3_field * pws3_record_remove_field(struct pws3_record *, uint8_t);
168 void pws3_file_destroy(struct pws3_file *);
169 struct pws3_file * pws3_file_create(void);
170 enum pws_error_code pws3_file_get_error_code(struct pws3_file *);
171 const char * pws3_file_get_error_message(struct pws3_file *);
172 int pws3_file_read_mem(struct pws3_file *, const char *,
173 unsigned char *, size_t);
174 int pws3_file_read_stream(struct pws3_file *, const char *, FILE *);
175 int pws3_file_write_mem(struct pws3_file *, const char *, uint32_t,
176 unsigned char **, size_t *);
177 int pws3_file_write_stream(struct pws3_file *, const char *,
178 uint32_t, FILE *);
180 void pws3_file_set_header_field(struct pws3_file *,
181 struct pws3_field *);
182 struct pws3_field * pws3_file_get_header_field(struct pws3_file *, uint8_t);
183 struct pws3_field * pws3_file_remove_header_field(struct pws3_file *, uint8_t);
185 void pws3_file_insert_empty_group(struct pws3_file *,
186 struct pws3_field *);
187 struct pws3_field * pws3_file_get_empty_group(struct pws3_file *, const char *);
188 struct pws3_field * pws3_file_remove_empty_group(struct pws3_file *,
189 const char *);
190 struct pws3_field * pws3_file_first_empty_group(struct pws3_file *);
191 struct pws3_field * pws3_file_last_empty_group(struct pws3_file *);
192 struct pws3_field * pws3_file_next_empty_group(struct pws3_file *,
193 struct pws3_field *);
194 struct pws3_field * pws3_file_prev_empty_group(struct pws3_file *,
195 struct pws3_field *);
197 void pws3_file_insert_record(struct pws3_file *,
198 struct pws3_record *);
199 struct pws3_record * pws3_file_get_record(struct pws3_file *,
200 const unsigned char [static PWS3_UUID_SIZE]);
201 struct pws3_record * pws3_file_remove_record(struct pws3_file *,
202 const unsigned char [static PWS3_UUID_SIZE]);
203 struct pws3_record * pws3_file_first_record(struct pws3_file *);
204 struct pws3_record * pws3_file_last_record(struct pws3_file *);
205 struct pws3_record * pws3_file_next_record(struct pws3_file *,
206 struct pws3_record *);
207 struct pws3_record * pws3_file_prev_record(struct pws3_file *,
208 struct pws3_record *);
210 #ifdef __cplusplus
211 }
212 #endif /* __cplusplus */
214 #endif /* !PWS_H */