2 * marshal.h - SKS compatible marshalling routines
4 * Copyright 2011 Jonathan McDowell <noodles@earth.li>
11 #include "keystructs.h"
14 * marshal_publickey - Output an OpenPGP key as a byte stream
15 * @putchar_func: The function to put the next character to the stream
16 * @ctx: A pointer to the context structure for putchar_func.
17 * @key: The key to output.
19 * Takes an OpenPGP key and marshals it to a byte stream - writes
20 * a 32 bit size of the forthcoming data in network byte order and
21 * then the flattened byte representation of the key.
23 void marshal_publickey(int (*putchar_func)(void *ctx, size_t count,
26 const struct openpgp_publickey *key);
29 * unmarshal_publickey - Turn a byte stream into an OpenPGP key
30 * @getchar_func: The function to get the next character from the stream
31 * @ctx: A pointer to the context structure for getchar_func.
33 * Returns an OpenPGP structure which is the unmarshalled result of
34 * the input byte stream - ie the inverse of marshal_publickey.
36 struct openpgp_publickey *unmarshal_publickey(int (*getchar_func)(void *ctx,
42 * marshal_skshash - Output an SKS hash as a byte stream
43 * @putchar_func: The function to put the next character to the stream
44 * @ctx: A pointer to the context structure for putchar_func.
45 * @hash: The hash to output.
47 * Takes an SKS hash and marshals it to a byte stream - writes
48 * a 32 bit size of the forthcoming data (16 bytes) in network byte order
49 * and then the byte representation of the hash.
51 void marshal_skshash(int (*putchar_func)(void *ctx, size_t count,
54 const struct skshash *hash);
57 * unmarshal_skshash - Turn a byte stream into an SKS hash structure
58 * @getchar_func: The function to get the next character from the stream
59 * @ctx: A pointer to the context structure for getchar_func.
61 * Returns an SKS hash structure which is the unmarshalled result of
62 * the input byte stream - ie the inverse of marshal_skshash.
64 struct skshash *unmarshal_skshash(int (*getchar_func)(void *ctx, size_t count,
69 * marshal_string - Output a string as a byte stream
70 * @putchar_func: The function to put the next character to the stream
71 * @ctx: A pointer to the context structure for putchar_func.
72 * @string: The string to output.
74 * Takes a string and marshals it to a byte stream - writes a 32 bit size
75 * of the forthcoming data in network byte order and then the string.
77 void marshal_string(int (*putchar_func)(void *ctx, size_t count,
83 * unmarshal_string - Turn a byte stream into a string
84 * @getchar_func: The function to get the next character from the stream
85 * @ctx: A pointer to the context structure for getchar_func.
87 * Returns a string which is the unmarshalled result of the input byte
88 * stream - ie the inverse of marshal_string.
90 char *unmarshal_string(int (*getchar_func)(void *ctx, size_t count,
95 * marshal_array - Outputs an array as a byte stream
96 * @putchar_func: The function to put the next character to the stream
97 * @ctx: A pointer to the context structure for putchar_func.
98 * @marshal_func: The function to use to marshal each array element.
99 * @array: A pointer to the array to marshal
100 * @size:: The number of elements in the array.
102 * Takes an array and marshals it into a byte stream. Outputs a 32 bit
103 * count of the elements in the array in network byte order and then
104 * calls marshal_func for each element in the array to provide the
105 * marshalled contents.
107 void marshal_array(int (*putchar_func)(void *ctx, size_t count,
110 void (*marshal_func)(int
111 (*putchar_func)(void *ctx,
112 size_t count, void *c),
113 void *ctx, const void *item),
118 * unmarshal_array - Turn a byte stream into an array of elements
119 * @getchar_func: The function to get the next character from the stream
120 * @ctx: A pointer to the context structure for getchar_func.
121 * @unmarshal_func: The function to use to unmarshal each array element.
122 * @size: A pointer to where to store the number of elements unmarshalled
124 * Takes a byte stream and unmarshals it into an array of elements,
125 * as determined by the supplied unmarshal_func function. ie the reverse
128 void **unmarshal_array(int (*getchar_func)(void *ctx, size_t count,
131 void *(*unmarshal_func)(int
132 (*getchar_func)(void *ctx,
133 size_t count, void *c),
137 #endif /* __MARSHAL_H__ */