libpcp  0.2.1
vault.h
1 /*
2  This file is part of Pretty Curved Privacy (pcp1).
3 
4  Copyright (C) 2013-2014 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 
95 struct _vault_t {
96  char *filename;
97  FILE *fd;
98  uint8_t unsafed;
99  uint8_t isnew;
100  uint32_t size;
101  time_t modified;
102  mode_t mode;
103  uint32_t version;
104  byte checksum[32];
105 };
106 
108 typedef struct _vault_t vault_t;
109 
113  uint8_t fileid;
114  uint32_t version;
115  byte checksum[32];
116 };
117 
120 
124  uint8_t type;
125  uint32_t size;
126  uint32_t version;
127  byte checksum[32];
128 };
129 
132 
140 vault_t *pcpvault_init(char *filename);
141 
142 
143 /* Creates a new vault file. Called internally only.
144  If is_tmp If set to 1, create a temporary vault file.
145  */
146 vault_t *pcpvault_new(char *filename, int is_tmp);
147 
148 
149 /* Writes the initial vault header to the vault.
150  Called internally only. */
151 int pcpvault_create(vault_t *vault);
152 
153 
171 int pcpvault_additem(vault_t *vault, void *item, size_t itemsize, uint8_t type);
172 
173 
192 int pcpvault_addkey(vault_t *vault, void *item, uint8_t type);
193 
194 
209 int pcpvault_close(vault_t *vault);
210 
211 
230 int pcpvault_fetchall(vault_t *vault);
231 
232 
233 /* Write everything back to disk. */
234 int pcpvault_writeall(vault_t *vault);
235 
236 /* copy a vault to another file */
237 int pcpvault_copy(vault_t *tmp, vault_t *vault);
238 
239 /* delete a vault file */
240 void pcpvault_unlink(vault_t *tmp);
241 
242 /* calculate the vault checksum */
243 unsigned char *pcpvault_create_checksum(vault_t *vault);
244 
245 /* write the new checksum to the header of the current vault */
246 void pcpvault_update_checksum(vault_t *vault);
247 
248 /* bigendian converters */
249 vault_header_t * vh2be(vault_header_t *h);
250 vault_header_t * vh2native(vault_header_t *h);
253 
254 #endif /* _HAVE_PCP_VAULT */
255