1 /*        $NetBSD: hex_code.h,v 1.5 2025/02/25 19:15:52 christos Exp $          */
2 
3 #ifndef _HEX_CODE_H_INCLUDED_
4 #define _HEX_CODE_H_INCLUDED_
5 
6 /*++
7 /* NAME
8 /*        hex_code 3h
9 /* SUMMARY
10 /*        encode/decode data, hexadecimal style
11 /* SYNOPSIS
12 /*        #include <hex_code.h>
13 /* DESCRIPTION
14 /* .nf
15 
16  /*
17   * Utility library.
18  */
19 #include <vstring.h>
20 
21  /*
22   * External interface.
23   */
24 #define HEX_ENCODE_FLAG_NONE            (0)
25 #define HEX_ENCODE_FLAG_USE_COLON       (1<<0)
26 #define HEX_ENCODE_FLAG_APPEND                    (1<<1)
27 
28 #define HEX_DECODE_FLAG_NONE  (0)
29 #define HEX_DECODE_FLAG_ALLOW_COLON     (1<<0)
30 
31 extern VSTRING *hex_encode(VSTRING *, const char *, ssize_t);
32 extern VSTRING *WARN_UNUSED_RESULT hex_decode(VSTRING *, const char *, ssize_t);
33 extern VSTRING *hex_encode_opt(VSTRING *, const char *, ssize_t, int);
34 extern VSTRING *WARN_UNUSED_RESULT hex_decode_opt(VSTRING *, const char *, ssize_t, int);
35 
36 #define hex_encode(res, in, len) \
37           hex_encode_opt((res), (in), (len), HEX_ENCODE_FLAG_NONE)
38 #define hex_decode(res, in, len) \
39           hex_decode_opt((res), (in), (len), HEX_DECODE_FLAG_NONE)
40 
41 /* LICENSE
42 /* .ad
43 /* .fi
44 /*        The Secure Mailer license must be distributed with this software.
45 /* AUTHOR(S)
46 /*        Wietse Venema
47 /*        IBM T.J. Watson Research
48 /*        P.O. Box 704
49 /*        Yorktown Heights, NY 10598, USA
50 /*
51 /*        Wietse Venema
52 /*        Google, Inc.
53 /*        111 8th Avenue
54 /*        New York, NY 10011, USA
55 /*
56 /*        Wietse Venema
57 /*        porcupine.org
58 /*--*/
59 
60 #endif
61