2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * Hex encoder and hex decoder.
10 #include "wvencoder.h"
15 * The input data is transformed into a sequence of hexadecimal
21 class WvHexEncoder
: public WvEncoder
27 * Creates a hex encoder.
29 * "use_uppercase" is if true, outputs hex codes A through Z
30 * in upper case, otherwise output them in lower case
33 WvHexEncoder(bool use_uppercase
= false);
34 virtual ~WvHexEncoder() { }
37 virtual bool _encode(WvBuf
&in
, WvBuf
&out
, bool flush
);
38 virtual bool _reset(); // supported
45 * The input hex characters are paired and decoded into the
46 * corresponding byte stream. Whitespace is skipped as is the
47 * case of the hex codes A through Z. Other characters cause the
48 * encoder to flag an error.
53 class WvHexDecoder
: public WvEncoder
59 /** Creates a hex decoder. */
61 virtual ~WvHexDecoder() { }
64 virtual bool _encode(WvBuf
&in
, WvBuf
&out
, bool flush
);
65 virtual bool _reset(); // supported
69 * Hex functions for compatibility with older code
73 * Write the contents of the binary string of length 'len' pointed to by 'ibuf'
74 * into the output buffer 'obuf' in hexadecimal format.
76 * For example, if len==4, ibuf=="ABCDEF", then obuf will contain "41424344"
77 * with a terminating NULL character.
79 * This is useful to turn arbitrary binary into a simple printable format, so
80 * that it can (for example) be written to a WvConf configuration file.
82 * obuf must be a buffer with at least (len * 2) + 1 bytes available. (two
83 * digits for each byte of ibuf, plus a terminating NULL).
85 void hexify(char *obuf
, const void *ibuf
, size_t len
);
88 * Reverse the operation performed by hexify(). obuf must be a buffer large
89 * enough to contain the entire binary output string; you can calculate this
90 * size with (strlen(ibuf) / 2). obuf will NOT be automatically NULL-terminated.
92 void unhexify(void *obuf
, const char *ibuf
);