summaryrefslogtreecommitdiffstats
path: root/botan/src/codec/hex/hex.h
diff options
context:
space:
mode:
authorKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
committerKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
commit9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch)
tree63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/src/codec/hex/hex.h
parent619d92cfef29e653bfdf852e83888e50cfc4348f (diff)
parent65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff)
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/src/codec/hex/hex.h')
-rw-r--r--botan/src/codec/hex/hex.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/botan/src/codec/hex/hex.h b/botan/src/codec/hex/hex.h
new file mode 100644
index 0000000..035bf4e
--- /dev/null
+++ b/botan/src/codec/hex/hex.h
@@ -0,0 +1,90 @@
+/*
+* Hex Encoder/Decoder
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_HEX_H__
+#define BOTAN_HEX_H__
+
+#include <botan/filter.h>
+
+namespace Botan {
+
+/**
+* This class represents a hex encoder. It encodes byte arrays to hex strings.
+*/
+class BOTAN_DLL Hex_Encoder : public Filter
+ {
+ public:
+ /**
+ * Whether to use uppercase or lowercase letters for the encoded string.
+ */
+ enum Case { Uppercase, Lowercase };
+
+ /**
+ Encode a single byte into two hex characters
+ */
+ static void encode(byte in, byte out[2], Case the_case = Uppercase);
+
+ void write(const byte in[], u32bit length);
+ void end_msg();
+
+ /**
+ * Create a hex encoder.
+ * @param the_case the case to use in the encoded strings.
+ */
+ Hex_Encoder(Case the_case);
+
+ /**
+ * Create a hex encoder.
+ * @param newlines should newlines be used
+ * @param line_length if newlines are used, how long are lines
+ * @param the_case the case to use in the encoded strings
+ */
+ Hex_Encoder(bool newlines = false,
+ u32bit line_length = 72,
+ Case the_case = Uppercase);
+ private:
+ void encode_and_send(const byte[], u32bit);
+ static const byte BIN_TO_HEX_UPPER[16];
+ static const byte BIN_TO_HEX_LOWER[16];
+
+ const Case casing;
+ const u32bit line_length;
+ SecureVector<byte> in, out;
+ u32bit position, counter;
+ };
+
+/**
+* This class represents a hex decoder. It converts hex strings to byte arrays.
+*/
+class BOTAN_DLL Hex_Decoder : public Filter
+ {
+ public:
+ static byte decode(const byte[2]);
+ static bool is_valid(byte);
+
+ void write(const byte[], u32bit);
+ void end_msg();
+
+ /**
+ * Construct a Hex Decoder using the specified
+ * character checking.
+ * @param checking the checking to use during decoding.
+ */
+ Hex_Decoder(Decoder_Checking checking = NONE);
+ private:
+ void decode_and_send(const byte[], u32bit);
+ void handle_bad_char(byte);
+ static const byte HEX_TO_BIN[256];
+
+ const Decoder_Checking checking;
+ SecureVector<byte> in, out;
+ u32bit position;
+ };
+
+}
+
+#endif