Merge pull request #115 from hfmanson/master
[tlspool] / src / pgp.h
1
2 #include <stdint.h>
3 #include <stdbool.h>
4
5
6 /* The PGP header structure walks through PGP data.
7  */
8 typedef struct {
9         uint8_t *ptr;
10         uint32_t ofs;
11         uint32_t end;
12         uint32_t r64ofs;        // Set to PGP64_NA for binary data
13 } pgpcursor_st, *pgpcursor_t;
14
15 #define PGP64_NA (~(uint32_t) 0)
16
17
18 /* Setup a cursor on binary PGP data; always returns success. */
19 bool pgp_initcursor_binary (pgpcursor_t crs, uint8_t *data, uint32_t len);
20
21 /* Setup a cursor on radix64 PGP data; return success. */
22 bool pgp_initcursor_radix64 (pgpcursor_t crs, char *data, uint32_t len);
23
24 /* Fetch a byte from a pgpcursor; this may look either into binary data,
25  * or into radix64-encoded data.  In the latter case, r64ofs is set to a
26  * value different from PGP64_NA and indicates an additional byte offset.
27  * In both cases, ptr points to the start of a fragment, and ofs and len
28  * deal with the binary number of bytes.
29  * This function returns 1 on success, 0 on failure.
30  */
31 bool pgp_getbyte (pgpcursor_t crs, uint8_t *output);
32
33 /* Parse a PGP header pointed to by a given cursor.  Deliver a tag and an
34  * inner PGP cursor, while advancing the original PGP cursor beyond the
35  * tag.  The function returns a success value or zero for failure.
36  * When sub is provided as NULL, it will not be entered.
37  */
38 bool pgp_enter (pgpcursor_t seq, uint8_t *tag, pgpcursor_t sub);
39