-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.h
More file actions
69 lines (59 loc) · 2.07 KB
/
Copy pathcontainer.h
File metadata and controls
69 lines (59 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* SPDX-FileType: SOURCE
*
* SPDX-FileCopyrightText: 2026 Nick Kossifidis <mick@ics.forth.gr>
* SPDX-FileCopyrightText: 2026 ICS/FORTH
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _CONTAINER_H
#define _CONTAINER_H
#include <stdint.h>
#include <stddef.h>
#include "res.h"
#include "crypto_ops.h"
struct cont_ctx {
struct res_t *res;
uint8_t *buf;
size_t size; /* current write position */
size_t max_size;
struct cops_ctx *cops; /* borrowed ref; NULL if unsigned */
uint16_t version;
uint8_t part_count;
size_t hdr_end; /* offset where sep/part data begins */
int read_only;
int finalized;
};
/*
* Open an existing container for reading (max_size == 0) or create a new
* writable container pre-extended to max_size bytes (max_size > 0).
*/
struct cont_ctx *container_open(const char *file_path, size_t max_size);
/*
* Initialise a writable container. Reserves space for the global header
* section (global_hdr + pubkey + global_sig); that section is filled at
* container_finalize().
*/
int container_new(struct cont_ctx *cont, struct cops_ctx *cops,
uint16_t version);
int container_set_cops(struct cont_ctx *cont, struct cops_ctx *cops);
/*
* Add a partition. Takes ownership of res; caller must not use res after
* this returns. Internally calls part_new → part_sign → part_finalize.
*/
int container_add_partition(struct cont_ctx *cont, struct res_t *res,
uint8_t unit_id, uint8_t type, uint8_t flags);
/*
* Finalise: write global header section, patch rolling_crc fields, update
* res->size. Must be called before container_close on write containers.
*/
int container_finalize(struct cont_ctx *cont);
/*
* Walk the container buffer, verify CRC at every separator, decompress
* payloads, and cross-check signatures with the built-in and OpenSSL
* implementations. do_dump != 0 writes decompressed parts to
* /tmp/partN.bin.
*/
int container_verify(struct cont_ctx *cont, int do_dump);
void container_close(struct cont_ctx *cont);
#endif /* _CONTAINER_H */