xref: /minix3/external/bsd/bind/dist/lib/isc/include/isc/hex.h (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1 /*	$NetBSD: hex.h,v 1.4 2014/12/10 04:38:00 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004-2008  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 2000, 2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: hex.h,v 1.13 2008/09/25 04:02:39 tbox Exp  */
21 
22 #ifndef ISC_HEX_H
23 #define ISC_HEX_H 1
24 
25 /*! \file isc/hex.h */
26 
27 #include <isc/lang.h>
28 #include <isc/types.h>
29 
30 ISC_LANG_BEGINDECLS
31 
32 /***
33  *** Functions
34  ***/
35 
36 isc_result_t
37 isc_hex_totext(isc_region_t *source, int wordlength,
38 	       const char *wordbreak, isc_buffer_t *target);
39 /*!<
40  * \brief Convert data into hex encoded text.
41  *
42  * Notes:
43  *\li	The hex encoded text in 'target' will be divided into
44  *	words of at most 'wordlength' characters, separated by
45  * 	the 'wordbreak' string.  No parentheses will surround
46  *	the text.
47  *
48  * Requires:
49  *\li	'source' is a region containing binary data
50  *\li	'target' is a text buffer containing available space
51  *\li	'wordbreak' points to a null-terminated string of
52  *		zero or more whitespace characters
53  *
54  * Ensures:
55  *\li	target will contain the hex encoded version of the data
56  *	in source.  The 'used' pointer in target will be advanced as
57  *	necessary.
58  */
59 
60 isc_result_t
61 isc_hex_decodestring(const char *cstr, isc_buffer_t *target);
62 /*!<
63  * \brief Decode a null-terminated hex string.
64  *
65  * Requires:
66  *\li	'cstr' is non-null.
67  *\li	'target' is a valid buffer.
68  *
69  * Returns:
70  *\li	#ISC_R_SUCCESS	-- the entire decoded representation of 'cstring'
71  *			   fit in 'target'.
72  *\li	#ISC_R_BADHEX -- 'cstr' is not a valid hex encoding.
73  *
74  * 	Other error returns are any possible error code from:
75  *		isc_lex_create(),
76  *		isc_lex_openbuffer(),
77  *		isc_hex_tobuffer().
78  */
79 
80 isc_result_t
81 isc_hex_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
82 /*!<
83  * \brief Convert hex encoded text from a lexer context into data.
84  *
85  * Requires:
86  *\li	'lex' is a valid lexer context
87  *\li	'target' is a buffer containing binary data
88  *\li	'length' is an integer
89  *
90  * Ensures:
91  *\li	target will contain the data represented by the hex encoded
92  *	string parsed by the lexer.  No more than length bytes will be read,
93  *	if length is positive.  The 'used' pointer in target will be
94  *	advanced as necessary.
95  */
96 
97 
98 ISC_LANG_ENDDECLS
99 
100 #endif /* ISC_HEX_H */
101