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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*
* marshal.h - SKS compatible marshalling routines
*
* Copyright 2011 Jonathan McDowell <noodles@earth.li>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __MARSHAL_H__
#define __MARSHAL_H__
#include "keyid.h"
#include "keystructs.h"
/**
* marshal_publickey - Output an OpenPGP key as a byte stream
* @putchar_func: The function to put the next character to the stream
* @ctx: A pointer to the context structure for putchar_func.
* @key: The key to output.
*
* Takes an OpenPGP key and marshals it to a byte stream - writes
* a 32 bit size of the forthcoming data in network byte order and
* then the flattened byte representation of the key.
*/
void marshal_publickey(int (*putchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
const struct openpgp_publickey *key);
/**
* unmarshal_publickey - Turn a byte stream into an OpenPGP key
* @getchar_func: The function to get the next character from the stream
* @ctx: A pointer to the context structure for getchar_func.
*
* Returns an OpenPGP structure which is the unmarshalled result of
* the input byte stream - ie the inverse of marshal_publickey.
*/
struct openpgp_publickey *unmarshal_publickey(int (*getchar_func)(void *ctx,
size_t count,
void *c),
void *ctx);
/**
* marshal_skshash - Output an SKS hash as a byte stream
* @putchar_func: The function to put the next character to the stream
* @ctx: A pointer to the context structure for putchar_func.
* @hash: The hash to output.
*
* Takes an SKS hash and marshals it to a byte stream - writes
* a 32 bit size of the forthcoming data (16 bytes) in network byte order
* and then the byte representation of the hash.
*/
void marshal_skshash(int (*putchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
const struct skshash *hash);
/**
* unmarshal_skshash - Turn a byte stream into an SKS hash structure
* @getchar_func: The function to get the next character from the stream
* @ctx: A pointer to the context structure for getchar_func.
*
* Returns an SKS hash structure which is the unmarshalled result of
* the input byte stream - ie the inverse of marshal_skshash.
*/
struct skshash *unmarshal_skshash(int (*getchar_func)(void *ctx, size_t count,
void *c),
void *ctx);
/**
* marshal_string - Output a string as a byte stream
* @putchar_func: The function to put the next character to the stream
* @ctx: A pointer to the context structure for putchar_func.
* @string: The string to output.
*
* Takes a string and marshals it to a byte stream - writes a 32 bit size
* of the forthcoming data in network byte order and then the string.
*/
void marshal_string(int (*putchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
const char *string);
/**
* unmarshal_string - Turn a byte stream into a string
* @getchar_func: The function to get the next character from the stream
* @ctx: A pointer to the context structure for getchar_func.
*
* Returns a string which is the unmarshalled result of the input byte
* stream - ie the inverse of marshal_string.
*/
char *unmarshal_string(int (*getchar_func)(void *ctx, size_t count,
void *c),
void *ctx);
/**
* marshal_array - Outputs an array as a byte stream
* @putchar_func: The function to put the next character to the stream
* @ctx: A pointer to the context structure for putchar_func.
* @marshal_func: The function to use to marshal each array element.
* @array: A pointer to the array to marshal
* @size:: The number of elements in the array.
*
* Takes an array and marshals it into a byte stream. Outputs a 32 bit
* count of the elements in the array in network byte order and then
* calls marshal_func for each element in the array to provide the
* marshalled contents.
*/
void marshal_array(int (*putchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
void (*marshal_func)(int
(*putchar_func)(void *ctx,
size_t count, void *c),
void *ctx, const void *item),
void **array,
int size);
/**
* unmarshal_array - Turn a byte stream into an array of elements
* @getchar_func: The function to get the next character from the stream
* @ctx: A pointer to the context structure for getchar_func.
* @unmarshal_func: The function to use to unmarshal each array element.
* @size: A pointer to where to store the number of elements unmarshalled
*
* Takes a byte stream and unmarshals it into an array of elements,
* as determined by the supplied unmarshal_func function. ie the reverse
* of marshal_array.
*/
void **unmarshal_array(int (*getchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
void *(*unmarshal_func)(int
(*getchar_func)(void *ctx,
size_t count, void *c),
void *ctx),
int *size);
#endif /* __MARSHAL_H__ */
|