chiark / gitweb /
Headers: Guard inclusion of mLib headers.
[mLib] / hex.h
CommitLineData
ee393574 1/* -*-c-*-
ee393574 2 *
3 * Hexadecimal encoding and decoding
4 *
5 * (c) 2001 Straylight/Edgeware
6 */
7
d4efbcd9 8/*----- Licensing notice --------------------------------------------------*
ee393574 9 *
10 * This file is part of the mLib utilities library.
11 *
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
d4efbcd9 16 *
ee393574 17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
d4efbcd9 21 *
ee393574 22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
ee393574 28#ifndef MLIB_HEX_H
29#define MLIB_HEX_H
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35/*----- Header files ------------------------------------------------------*/
36
dd3c57bc
MW
37#ifndef MLIB_DSTR_H
38# include "dstr.h"
39#endif
ee393574 40
41/*----- Data structures ---------------------------------------------------*/
42
43typedef struct hex_ctx {
44 unsigned long acc; /* Accumulator for output data */
45 unsigned qsz; /* Length of data queued */
46 unsigned lnlen; /* Length of the current line */
47 const char *indent; /* Newline-and-indent string */
48 unsigned maxline; /* Maximum permitted line length */
49} hex_ctx;
50
51/*----- Functions provided ------------------------------------------------*/
52
53/* --- @hex_encode@ --- *
54 *
55 * Arguments: @hex_ctx *ctx@ = pointer to a context block
56 * @const void *p@ = pointer to a source buffer
57 * @size_t sz@ = size of the source buffer
58 * @dstr *d@ = pointer to destination string
59 *
60 * Returns: ---
61 *
62 * Use: Encodes a binary string in hex.
63 */
64
65extern void hex_encode(hex_ctx */*ctx*/, const void */*p*/, size_t /*sz*/,
66 dstr */*d*/);
67
68/* --- @hex_decode@ --- *
69 *
70 * Arguments: @hex_ctx *ctx@ = pointer to a context block
71 * @const void *p@ = pointer to a source buffer
72 * @size_t sz@ = size of the source buffer
73 * @dstr *d@ = pointer to destination string
74 *
75 * Returns: ---
76 *
77 * Use: Decodes a binary string in hex. Pass in a null source
78 * pointer when you thing you've finished.
79 */
80
81extern void hex_decode(hex_ctx */*ctx*/, const void */*p*/, size_t /*sz*/,
82 dstr */*d*/);
83
84/* --- @hex_init@ --- *
85 *
86 * Arguments: @hex_ctx *ctx@ = pointer to context block to initialize
87 *
88 * Returns: ---
89 *
90 * Use: Initializes a hex context properly.
91 */
92
93extern void hex_init(hex_ctx */*ctx*/);
94
95/*----- That's all, folks -------------------------------------------------*/
96
97#ifdef __cplusplus
98 }
99#endif
100
101#endif