2 * marshal.h - SKS compatible marshalling routines
4 * Copyright 2011 Jonathan McDowell <noodles@earth.li>
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "keystructs.h"
27 * marshal_publickey - Output an OpenPGP key as a byte stream
28 * @putchar_func: The function to put the next character to the stream
29 * @ctx: A pointer to the context structure for putchar_func.
30 * @key: The key to output.
32 * Takes an OpenPGP key and marshals it to a byte stream - writes
33 * a 32 bit size of the forthcoming data in network byte order and
34 * then the flattened byte representation of the key.
36 void marshal_publickey(int (*putchar_func)(void *ctx, size_t count,
39 const struct openpgp_publickey *key);
42 * unmarshal_publickey - Turn a byte stream into an OpenPGP key
43 * @getchar_func: The function to get the next character from the stream
44 * @ctx: A pointer to the context structure for getchar_func.
46 * Returns an OpenPGP structure which is the unmarshalled result of
47 * the input byte stream - ie the inverse of marshal_publickey.
49 struct openpgp_publickey *unmarshal_publickey(int (*getchar_func)(void *ctx,
55 * marshal_skshash - Output an SKS hash as a byte stream
56 * @putchar_func: The function to put the next character to the stream
57 * @ctx: A pointer to the context structure for putchar_func.
58 * @hash: The hash to output.
60 * Takes an SKS hash and marshals it to a byte stream - writes
61 * a 32 bit size of the forthcoming data (16 bytes) in network byte order
62 * and then the byte representation of the hash.
64 void marshal_skshash(int (*putchar_func)(void *ctx, size_t count,
67 const struct skshash *hash);
70 * unmarshal_skshash - Turn a byte stream into an SKS hash structure
71 * @getchar_func: The function to get the next character from the stream
72 * @ctx: A pointer to the context structure for getchar_func.
74 * Returns an SKS hash structure which is the unmarshalled result of
75 * the input byte stream - ie the inverse of marshal_skshash.
77 struct skshash *unmarshal_skshash(int (*getchar_func)(void *ctx, size_t count,
82 * marshal_string - Output a string as a byte stream
83 * @putchar_func: The function to put the next character to the stream
84 * @ctx: A pointer to the context structure for putchar_func.
85 * @string: The string to output.
87 * Takes a string and marshals it to a byte stream - writes a 32 bit size
88 * of the forthcoming data in network byte order and then the string.
90 void marshal_string(int (*putchar_func)(void *ctx, size_t count,
96 * unmarshal_string - Turn a byte stream into a string
97 * @getchar_func: The function to get the next character from the stream
98 * @ctx: A pointer to the context structure for getchar_func.
100 * Returns a string which is the unmarshalled result of the input byte
101 * stream - ie the inverse of marshal_string.
103 char *unmarshal_string(int (*getchar_func)(void *ctx, size_t count,
108 * marshal_array - Outputs an array as a byte stream
109 * @putchar_func: The function to put the next character to the stream
110 * @ctx: A pointer to the context structure for putchar_func.
111 * @marshal_func: The function to use to marshal each array element.
112 * @array: A pointer to the array to marshal
113 * @size:: The number of elements in the array.
115 * Takes an array and marshals it into a byte stream. Outputs a 32 bit
116 * count of the elements in the array in network byte order and then
117 * calls marshal_func for each element in the array to provide the
118 * marshalled contents.
120 void marshal_array(int (*putchar_func)(void *ctx, size_t count,
123 void (*marshal_func)(int
124 (*putchar_func)(void *ctx,
125 size_t count, void *c),
126 void *ctx, const void *item),
131 * unmarshal_array - Turn a byte stream into an array of elements
132 * @getchar_func: The function to get the next character from the stream
133 * @ctx: A pointer to the context structure for getchar_func.
134 * @unmarshal_func: The function to use to unmarshal each array element.
135 * @size: A pointer to where to store the number of elements unmarshalled
137 * Takes a byte stream and unmarshals it into an array of elements,
138 * as determined by the supplied unmarshal_func function. ie the reverse
141 void **unmarshal_array(int (*getchar_func)(void *ctx, size_t count,
144 void *(*unmarshal_func)(int
145 (*getchar_func)(void *ctx,
146 size_t count, void *c),
150 #endif /* __MARSHAL_H__ */