vault.h
1 /*
2  This file is part of Pretty Curved Privacy (pcp1).
3 
4  Copyright (C) 2013-2015 T.v.Dein.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19  You can contact me by mail: <tom AT vondein DOT org>.
20 */
21 
22 
23 #ifndef _HAVE_PCP_VAULT
24 #define _HAVE_PCP_VAULT
25 
79 #include <sys/types.h>
80 #include <sys/stat.h>
81 #include <stdio.h>
82 #include <sodium.h>
83 #include <unistd.h>
84 
85 #include "defines.h"
86 #include "platform.h"
87 #include "mem.h"
88 #include "key.h"
89 #include "uthash.h"
90 #include "buffer.h"
91 #include "keysig.h"
92 #include "structs.h"
93 #include "context.h"
94 
95 
104 vault_t *pcpvault_init(PCPCTX *ptx, char *filename);
105 
106 
107 /* Creates a new vault file. Called internally only.
108  If is_tmp If set to 1, create a temporary vault file.
109  */
110 vault_t *pcpvault_new(PCPCTX *ptx, char *filename, int is_tmp);
111 
112 
113 /* Writes the initial vault header to the vault.
114  Called internally only. */
115 int pcpvault_create(PCPCTX *ptx, vault_t *vault);
116 
117 
136 int pcpvault_additem(PCPCTX *ptx, vault_t *vault, void *item, size_t itemsize, uint8_t type);
137 
138 
158 int pcpvault_addkey(PCPCTX *ptx, vault_t *vault, void *item, uint8_t type);
159 
160 
176 int pcpvault_close(PCPCTX *ptx, vault_t *vault);
177 
182 void pcpvault_free(vault_t *vault);
183 
203 int pcpvault_fetchall(PCPCTX *ptx, vault_t *vault);
204 
205 
206 /* Write everything back to disk. */
207 int pcpvault_writeall(PCPCTX *ptx, vault_t *vault);
208 
209 /* copy a vault to another file */
210 int pcpvault_copy(PCPCTX *ptx, vault_t *tmp, vault_t *vault);
211 
212 /* delete a vault file */
213 void pcpvault_unlink(vault_t *tmp);
214 
215 /* calculate the checksum of the current vault (that is, from the
216  list of keys in the current context */
217 byte *pcpvault_create_checksum(PCPCTX *ptx);
218 
219 /* write the new checksum to the header of the current vault */
220 void pcpvault_update_checksum(PCPCTX *ptx, vault_t *vault);
221 
222 /* bigendian converters */
223 vault_header_t * vh2be(vault_header_t *h);
224 vault_header_t * vh2native(vault_header_t *h);
227 
228 #endif /* _HAVE_PCP_VAULT */
229