diff options
author | lloyd <[email protected]> | 2009-11-17 07:19:37 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-11-17 07:19:37 +0000 |
commit | e00b46cf9c1dcb364ebb7d5968d6ff9dcd600c4e (patch) | |
tree | 8ffb8d032f06bbcb7ab376c7469751a25b556dca /src/codec/hex | |
parent | a98a9ff5f95bd4dca9c1eda11e27e712c869cd66 (diff) |
Move most code that relies heavily on Filters into src/filters.
Remove support for (unused) modset settings.
Move tss, fpe, cryptobox, and aont to new dir constructs
Diffstat (limited to 'src/codec/hex')
-rw-r--r-- | src/codec/hex/hex.cpp | 193 | ||||
-rw-r--r-- | src/codec/hex/hex.h | 90 | ||||
-rw-r--r-- | src/codec/hex/hex_char.cpp | 48 | ||||
-rw-r--r-- | src/codec/hex/info.txt | 13 |
4 files changed, 0 insertions, 344 deletions
diff --git a/src/codec/hex/hex.cpp b/src/codec/hex/hex.cpp deleted file mode 100644 index 651899b73..000000000 --- a/src/codec/hex/hex.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* -* Hex Encoder/Decoder -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/hex.h> -#include <botan/parsing.h> -#include <botan/charset.h> -#include <botan/exceptn.h> -#include <algorithm> - -namespace Botan { - -const u32bit HEX_CODEC_BUFFER_SIZE = 256; - -/* -* Hex_Encoder Constructor -*/ -Hex_Encoder::Hex_Encoder(bool breaks, u32bit length, Case c) : - casing(c), line_length(breaks ? length : 0) - { - in.resize(HEX_CODEC_BUFFER_SIZE); - out.resize(2*in.size()); - counter = position = 0; - } - -/* -* Hex_Encoder Constructor -*/ -Hex_Encoder::Hex_Encoder(Case c) : casing(c), line_length(0) - { - in.resize(HEX_CODEC_BUFFER_SIZE); - out.resize(2*in.size()); - counter = position = 0; - } - -/* -* Hex Encoding Operation -*/ -void Hex_Encoder::encode(byte in, byte out[2], Hex_Encoder::Case casing) - { - const byte* BIN_TO_HEX = ((casing == Uppercase) ? BIN_TO_HEX_UPPER : - BIN_TO_HEX_LOWER); - - out[0] = BIN_TO_HEX[((in >> 4) & 0x0F)]; - out[1] = BIN_TO_HEX[((in ) & 0x0F)]; - } - -/* -* Encode and send a block -*/ -void Hex_Encoder::encode_and_send(const byte block[], u32bit length) - { - for(u32bit j = 0; j != length; ++j) - encode(block[j], out + 2*j, casing); - - if(line_length == 0) - send(out, 2*length); - else - { - u32bit remaining = 2*length, offset = 0; - while(remaining) - { - u32bit sent = std::min(line_length - counter, remaining); - send(out + offset, sent); - counter += sent; - remaining -= sent; - offset += sent; - if(counter == line_length) - { - send('\n'); - counter = 0; - } - } - } - } - -/* -* Convert some data into hex format -*/ -void Hex_Encoder::write(const byte input[], u32bit length) - { - in.copy(position, input, length); - if(position + length >= in.size()) - { - encode_and_send(in, in.size()); - input += (in.size() - position); - length -= (in.size() - position); - while(length >= in.size()) - { - encode_and_send(input, in.size()); - input += in.size(); - length -= in.size(); - } - in.copy(input, length); - position = 0; - } - position += length; - } - -/* -* Flush buffers -*/ -void Hex_Encoder::end_msg() - { - encode_and_send(in, position); - if(counter && line_length) - send('\n'); - counter = position = 0; - } - -/* -* Hex_Decoder Constructor -*/ -Hex_Decoder::Hex_Decoder(Decoder_Checking c) : checking(c) - { - in.resize(HEX_CODEC_BUFFER_SIZE); - out.resize(in.size() / 2); - position = 0; - } - -/* -* Check if a character is a valid hex char -*/ -bool Hex_Decoder::is_valid(byte in) - { - return (HEX_TO_BIN[in] != 0x80); - } - -/* -* Handle processing an invalid character -*/ -void Hex_Decoder::handle_bad_char(byte c) - { - if(checking == NONE) - return; - - if((checking == IGNORE_WS) && Charset::is_space(c)) - return; - - throw Decoding_Error("Hex_Decoder: Invalid hex character: " + - to_string(c)); - } - -/* -* Hex Decoding Operation -*/ -byte Hex_Decoder::decode(const byte hex[2]) - { - return ((HEX_TO_BIN[hex[0]] << 4) | HEX_TO_BIN[hex[1]]); - } - -/* -* Decode and send a block -*/ -void Hex_Decoder::decode_and_send(const byte block[], u32bit length) - { - for(u32bit j = 0; j != length / 2; ++j) - out[j] = decode(block + 2*j); - send(out, length / 2); - } - -/* -* Convert some data from hex format -*/ -void Hex_Decoder::write(const byte input[], u32bit length) - { - for(u32bit j = 0; j != length; ++j) - { - if(is_valid(input[j])) - in[position++] = input[j]; - else - handle_bad_char(input[j]); - if(position == in.size()) - { - decode_and_send(in, in.size()); - position = 0; - } - } - } - -/* -* Flush buffers -*/ -void Hex_Decoder::end_msg() - { - decode_and_send(in, position); - position = 0; - } - -} diff --git a/src/codec/hex/hex.h b/src/codec/hex/hex.h deleted file mode 100644 index 035bf4ef9..000000000 --- a/src/codec/hex/hex.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -* 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 diff --git a/src/codec/hex/hex_char.cpp b/src/codec/hex/hex_char.cpp deleted file mode 100644 index c28efc5f7..000000000 --- a/src/codec/hex/hex_char.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -* Hex Character Table -* (C) 1999-2008 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/hex.h> - -namespace Botan { - -/* -* Hex Encoder Lookup Tables -*/ -const byte Hex_Encoder::BIN_TO_HEX_UPPER[16] = { -0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, -0x44, 0x45, 0x46 }; - -const byte Hex_Encoder::BIN_TO_HEX_LOWER[16] = { -0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, -0x64, 0x65, 0x66 }; - -/* -* Hex Decoder Lookup Table -*/ -const byte Hex_Decoder::HEX_TO_BIN[256] = { -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, 0x02, 0x03, -0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }; - -} diff --git a/src/codec/hex/info.txt b/src/codec/hex/info.txt deleted file mode 100644 index 817ff1a00..000000000 --- a/src/codec/hex/info.txt +++ /dev/null @@ -1,13 +0,0 @@ -define HEX_CODEC - -load_on auto - -<add> -hex.cpp -hex_char.cpp -hex.h -</add> - -<requires> -filters -</requires> |