From bd58db8eb1384fe26222d021325382f57f178cc7 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 16 Jul 2009 15:07:59 +0000 Subject: Move some files around to break up dependencies between directories --- src/utils/buf_comp.h | 126 ------------ src/utils/buf_comp/buf_comp.h | 126 ++++++++++++ src/utils/data_src.cpp | 207 ------------------- src/utils/data_src.h | 150 -------------- src/utils/datastor.cpp | 172 ---------------- src/utils/datastor.h | 61 ------ src/utils/datastor/datastor.cpp | 172 ++++++++++++++++ src/utils/datastor/datastor.h | 61 ++++++ src/utils/info.txt | 12 -- src/utils/scan_name.cpp | 74 ------- src/utils/scan_name.h | 77 ------- src/utils/secmem.h | 438 ---------------------------------------- 12 files changed, 359 insertions(+), 1317 deletions(-) delete mode 100644 src/utils/buf_comp.h create mode 100644 src/utils/buf_comp/buf_comp.h delete mode 100644 src/utils/data_src.cpp delete mode 100644 src/utils/data_src.h delete mode 100644 src/utils/datastor.cpp delete mode 100644 src/utils/datastor.h create mode 100644 src/utils/datastor/datastor.cpp create mode 100644 src/utils/datastor/datastor.h delete mode 100644 src/utils/scan_name.cpp delete mode 100644 src/utils/scan_name.h delete mode 100644 src/utils/secmem.h (limited to 'src/utils') diff --git a/src/utils/buf_comp.h b/src/utils/buf_comp.h deleted file mode 100644 index 3f1e90bad..000000000 --- a/src/utils/buf_comp.h +++ /dev/null @@ -1,126 +0,0 @@ -/** -* BufferedComputation -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_BUFFERED_COMPUTATION_H__ -#define BOTAN_BUFFERED_COMPUTATION_H__ - -#include - -namespace Botan { - -/** -* This class represents any kind of computation which -* uses an internal state, -* such as hash functions. -*/ -class BOTAN_DLL BufferedComputation - { - public: - - /** - * The length of the output of this function in bytes. - */ - const u32bit OUTPUT_LENGTH; - - /** - * Add new input to process. - * @param in the input to process as a byte array - * @param the length of the byte array - */ - void update(const byte in[], u32bit length) { add_data(in, length); } - - /** - * Add new input to process. - * @param in the input to process as a MemoryRegion - */ - void update(const MemoryRegion& in) { add_data(in, in.size()); } - - /** - * Add new input to process. - * @param str the input to process as a std::string. Will be interpreted - * as a byte array based on - * the strings encoding. - */ - void update(const std::string& str) - { - add_data(reinterpret_cast(str.data()), str.size()); - } - - /** - * Process a single byte. - * @param in the byte to process - */ - void update(byte in) { add_data(&in, 1); } - - /** - * Complete the computation and retrieve the - * final result. - * @param out The byte array to be filled with the result. - * Must be of length OUTPUT_LENGTH. - */ - void final(byte out[]) { final_result(out); } - - /** - * Complete the computation and retrieve the - * final result. - * @return a SecureVector holding the result - */ - SecureVector final() - { - SecureVector output(OUTPUT_LENGTH); - final_result(output); - return output; - } - - /** - * Update and finalize computation. Does the same as calling update() - * and final() consecutively. - * @param in the input to process as a byte array - * @param length the length of the byte array - * @result the result of the call to final() - */ - SecureVector process(const byte in[], u32bit length) - { - add_data(in, length); - return final(); - } - - /** - * Update and finalize computation. Does the same as calling update() - * and final() consecutively. - * @param in the input to process - * @result the result of the call to final() - */ - SecureVector process(const MemoryRegion& in) - { - add_data(in, in.size()); - return final(); - } - - /** - * Update and finalize computation. Does the same as calling update() - * and final() consecutively. - * @param in the input to process as a string - * @result the result of the call to final() - */ - SecureVector process(const std::string& in) - { - update(in); - return final(); - } - - BufferedComputation(u32bit out_len) : OUTPUT_LENGTH(out_len) {} - virtual ~BufferedComputation() {} - private: - BufferedComputation& operator=(const BufferedComputation&); - virtual void add_data(const byte[], u32bit) = 0; - virtual void final_result(byte[]) = 0; - }; - -} - -#endif diff --git a/src/utils/buf_comp/buf_comp.h b/src/utils/buf_comp/buf_comp.h new file mode 100644 index 000000000..3f1e90bad --- /dev/null +++ b/src/utils/buf_comp/buf_comp.h @@ -0,0 +1,126 @@ +/** +* BufferedComputation +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BUFFERED_COMPUTATION_H__ +#define BOTAN_BUFFERED_COMPUTATION_H__ + +#include + +namespace Botan { + +/** +* This class represents any kind of computation which +* uses an internal state, +* such as hash functions. +*/ +class BOTAN_DLL BufferedComputation + { + public: + + /** + * The length of the output of this function in bytes. + */ + const u32bit OUTPUT_LENGTH; + + /** + * Add new input to process. + * @param in the input to process as a byte array + * @param the length of the byte array + */ + void update(const byte in[], u32bit length) { add_data(in, length); } + + /** + * Add new input to process. + * @param in the input to process as a MemoryRegion + */ + void update(const MemoryRegion& in) { add_data(in, in.size()); } + + /** + * Add new input to process. + * @param str the input to process as a std::string. Will be interpreted + * as a byte array based on + * the strings encoding. + */ + void update(const std::string& str) + { + add_data(reinterpret_cast(str.data()), str.size()); + } + + /** + * Process a single byte. + * @param in the byte to process + */ + void update(byte in) { add_data(&in, 1); } + + /** + * Complete the computation and retrieve the + * final result. + * @param out The byte array to be filled with the result. + * Must be of length OUTPUT_LENGTH. + */ + void final(byte out[]) { final_result(out); } + + /** + * Complete the computation and retrieve the + * final result. + * @return a SecureVector holding the result + */ + SecureVector final() + { + SecureVector output(OUTPUT_LENGTH); + final_result(output); + return output; + } + + /** + * Update and finalize computation. Does the same as calling update() + * and final() consecutively. + * @param in the input to process as a byte array + * @param length the length of the byte array + * @result the result of the call to final() + */ + SecureVector process(const byte in[], u32bit length) + { + add_data(in, length); + return final(); + } + + /** + * Update and finalize computation. Does the same as calling update() + * and final() consecutively. + * @param in the input to process + * @result the result of the call to final() + */ + SecureVector process(const MemoryRegion& in) + { + add_data(in, in.size()); + return final(); + } + + /** + * Update and finalize computation. Does the same as calling update() + * and final() consecutively. + * @param in the input to process as a string + * @result the result of the call to final() + */ + SecureVector process(const std::string& in) + { + update(in); + return final(); + } + + BufferedComputation(u32bit out_len) : OUTPUT_LENGTH(out_len) {} + virtual ~BufferedComputation() {} + private: + BufferedComputation& operator=(const BufferedComputation&); + virtual void add_data(const byte[], u32bit) = 0; + virtual void final_result(byte[]) = 0; + }; + +} + +#endif diff --git a/src/utils/data_src.cpp b/src/utils/data_src.cpp deleted file mode 100644 index e6387c4ba..000000000 --- a/src/utils/data_src.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* -* DataSource -* (C) 1999-2007 Jack Lloyd -* 2005 Matthew Gregan -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -#include -#include - -namespace Botan { - -/* -* Read a single byte from the DataSource -*/ -u32bit DataSource::read_byte(byte& out) - { - return read(&out, 1); - } - -/* -* Peek a single byte from the DataSource -*/ -u32bit DataSource::peek_byte(byte& out) const - { - return peek(&out, 1, 0); - } - -/* -* Discard the next N bytes of the data -*/ -u32bit DataSource::discard_next(u32bit n) - { - u32bit discarded = 0; - byte dummy; - for(u32bit j = 0; j != n; ++j) - discarded += read_byte(dummy); - return discarded; - } - -/* -* Read from a memory buffer -*/ -u32bit DataSource_Memory::read(byte out[], u32bit length) - { - u32bit got = std::min(source.size() - offset, length); - copy_mem(out, source + offset, got); - offset += got; - return got; - } - -/* -* Peek into a memory buffer -*/ -u32bit DataSource_Memory::peek(byte out[], u32bit length, - u32bit peek_offset) const - { - const u32bit bytes_left = source.size() - offset; - if(peek_offset >= bytes_left) return 0; - - u32bit got = std::min(bytes_left - peek_offset, length); - copy_mem(out, source + offset + peek_offset, got); - return got; - } - -/* -* Check if the memory buffer is empty -*/ -bool DataSource_Memory::end_of_data() const - { - return (offset == source.size()); - } - -/* -* DataSource_Memory Constructor -*/ -DataSource_Memory::DataSource_Memory(const byte in[], u32bit length) - { - source.set(in, length); - offset = 0; - } - -/* -* DataSource_Memory Constructor -*/ -DataSource_Memory::DataSource_Memory(const MemoryRegion& in) - { - source = in; - offset = 0; - } - -/* -* DataSource_Memory Constructor -*/ -DataSource_Memory::DataSource_Memory(const std::string& in) - { - source.set(reinterpret_cast(in.data()), in.length()); - offset = 0; - } - -/* -* Read from a stream -*/ -u32bit DataSource_Stream::read(byte out[], u32bit length) - { - source->read(reinterpret_cast(out), length); - if(source->bad()) - throw Stream_IO_Error("DataSource_Stream::read: Source failure"); - - u32bit got = source->gcount(); - total_read += got; - return got; - } - -/* -* Peek into a stream -*/ -u32bit DataSource_Stream::peek(byte out[], u32bit length, u32bit offset) const - { - if(end_of_data()) - throw Invalid_State("DataSource_Stream: Cannot peek when out of data"); - - u32bit got = 0; - - if(offset) - { - SecureVector buf(offset); - source->read(reinterpret_cast(buf.begin()), buf.size()); - if(source->bad()) - throw Stream_IO_Error("DataSource_Stream::peek: Source failure"); - got = source->gcount(); - } - - if(got == offset) - { - source->read(reinterpret_cast(out), length); - if(source->bad()) - throw Stream_IO_Error("DataSource_Stream::peek: Source failure"); - got = source->gcount(); - } - - if(source->eof()) - source->clear(); - source->seekg(total_read, std::ios::beg); - - return got; - } - -/* -* Check if the stream is empty or in error -*/ -bool DataSource_Stream::end_of_data() const - { - return (!source->good()); - } - -/* -* Return a human-readable ID for this stream -*/ -std::string DataSource_Stream::id() const - { - return identifier; - } - -/* -* DataSource_Stream Constructor -*/ -DataSource_Stream::DataSource_Stream(const std::string& path, - bool use_binary) : - identifier(path), owner(true) - { - if(use_binary) - source = new std::ifstream(path.c_str(), std::ios::binary); - else - source = new std::ifstream(path.c_str()); - - if(!source->good()) - throw Stream_IO_Error("DataSource: Failure opening file " + path); - - total_read = 0; - } - -/* -* DataSource_Stream Constructor -*/ -DataSource_Stream::DataSource_Stream(std::istream& in, - const std::string& name) : - identifier(name), owner(false) - { - source = ∈ - total_read = 0; - } - -/* -* DataSource_Stream Destructor -*/ -DataSource_Stream::~DataSource_Stream() - { - if(owner) - delete source; - } - -} diff --git a/src/utils/data_src.h b/src/utils/data_src.h deleted file mode 100644 index e16217e0f..000000000 --- a/src/utils/data_src.h +++ /dev/null @@ -1,150 +0,0 @@ -/* -* DataSource -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_DATA_SRC_H__ -#define BOTAN_DATA_SRC_H__ - -#include -#include -#include - -namespace Botan { - -/** -* This class represents an abstract data source object. -*/ -class BOTAN_DLL DataSource - { - public: - /** - * Read from the source. Moves the internal offset so that - * every call to read will return a new portion of the source. - * @param out the byte array to write the result to - * @param length the length of the byte array out - * @return the length in bytes that was actually read and put - * into out - */ - virtual u32bit read(byte out[], u32bit length) = 0; - - /** - * Read from the source but do not modify the internal offset. Consecutive - * calls to peek() will return portions of the source starting at the same - * position. - * @param out the byte array to write the output to - * @param length the length of the byte array out - * @return the length in bytes that was actually read and put - * into out - */ - virtual u32bit peek(byte out[], u32bit length, - u32bit peek_offset) const = 0; - - /** - * Test whether the source still has data that can be read. - * @return true if there is still data to read, false otherwise - */ - virtual bool end_of_data() const = 0; - /** - * return the id of this data source - * @return the std::string representing the id of this data source - */ - virtual std::string id() const { return ""; } - - /** - * Read one byte. - * @param the byte to read to - * @return the length in bytes that was actually read and put - * into out - */ - u32bit read_byte(byte& out); - - /** - * Peek at one byte. - * @param the byte to read to - * @return the length in bytes that was actually read and put - * into out - */ - u32bit peek_byte(byte& out) const; - - /** - * Discard the next N bytes of the data - * @param N the number of bytes to discard - * @return the number of bytes actually discarded - */ - u32bit discard_next(u32bit N); - - DataSource() {} - virtual ~DataSource() {} - private: - DataSource& operator=(const DataSource&) { return (*this); } - DataSource(const DataSource&); - }; - -/** -* This class represents a Memory-Based DataSource -*/ -class BOTAN_DLL DataSource_Memory : public DataSource - { - public: - u32bit read(byte[], u32bit); - u32bit peek(byte[], u32bit, u32bit) const; - bool end_of_data() const; - - /** - * Construct a memory source that reads from a string - * @param in the string to read from - */ - DataSource_Memory(const std::string& in); - - /** - * Construct a memory source that reads from a byte array - * @param in the byte array to read from - * @param length the length of the byte array - */ - DataSource_Memory(const byte in[], u32bit length); - - /** - * Construct a memory source that reads from a MemoryRegion - * @param in the MemoryRegion to read from - */ - DataSource_Memory(const MemoryRegion& in); - private: - SecureVector source; - u32bit offset; - }; - -/** -* This class represents a Stream-Based DataSource. -*/ -class BOTAN_DLL DataSource_Stream : public DataSource - { - public: - u32bit read(byte[], u32bit); - u32bit peek(byte[], u32bit, u32bit) const; - bool end_of_data() const; - std::string id() const; - - DataSource_Stream(std::istream&, const std::string& id = ""); - - /** - * Construct a Stream-Based DataSource from file - * @param file the name of the file - * @param use_binary whether to treat the file as binary or not - */ - DataSource_Stream(const std::string& file, bool use_binary = false); - - ~DataSource_Stream(); - private: - const std::string identifier; - const bool owner; - - std::istream* source; - u32bit total_read; - }; - -} - -#endif diff --git a/src/utils/datastor.cpp b/src/utils/datastor.cpp deleted file mode 100644 index 129dad9bf..000000000 --- a/src/utils/datastor.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* -* Data Store -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include -#include -#include -#include - -namespace Botan { - -/* -* Default Matcher transform operation (identity) -*/ -std::pair -Data_Store::Matcher::transform(const std::string& key, - const std::string& value) const - { - return std::make_pair(key, value); - } - -/* -* Data_Store Equality Comparison -*/ -bool Data_Store::operator==(const Data_Store& other) const - { - return (contents == other.contents); - } - -/* -* Check if this key has at least one value -*/ -bool Data_Store::has_value(const std::string& key) const - { - return (contents.lower_bound(key) != contents.end()); - } - -/* -* Search based on an arbitrary predicate -*/ -std::multimap -Data_Store::search_with(const Matcher& matcher) const - { - std::multimap out; - - std::multimap::const_iterator i = - contents.begin(); - - while(i != contents.end()) - { - if(matcher(i->first, i->second)) - out.insert(matcher.transform(i->first, i->second)); - ++i; - } - - return out; - } - -/* -* Search based on key equality -*/ -std::vector Data_Store::get(const std::string& looking_for) const - { - typedef std::multimap::const_iterator iter; - - std::pair range = contents.equal_range(looking_for); - - std::vector out; - for(iter i = range.first; i != range.second; ++i) - out.push_back(i->second); - return out; - } - -/* -* Get a single atom -*/ -std::string Data_Store::get1(const std::string& key) const - { - std::vector vals = get(key); - - if(vals.empty()) - throw Invalid_State("Data_Store::get1: Not values for " + key); - if(vals.size() > 1) - throw Invalid_State("Data_Store::get1: More than one value for " + key); - - return vals[0]; - } - -/* -* Get a single MemoryVector atom -*/ -MemoryVector -Data_Store::get1_memvec(const std::string& key) const - { - std::vector vals = get(key); - - if(vals.size() > 1) - throw Invalid_State("Data_Store::get1_memvec: Multiple values for " + - key); - - if(vals.empty()) - return MemoryVector(); - - Pipe pipe(new Hex_Decoder(FULL_CHECK)); - pipe.start_msg(); - if(vals.size()) - pipe.write(vals[0]); - pipe.end_msg(); - return pipe.read_all(); - } - -/* -* Get a single u32bit atom -*/ -u32bit Data_Store::get1_u32bit(const std::string& key, - u32bit default_val) const - { - std::vector vals = get(key); - - if(vals.empty()) - return default_val; - else if(vals.size() > 1) - throw Invalid_State("Data_Store::get1_u32bit: Multiple values for " + - key); - - return to_u32bit(vals[0]); - } - -/* -* Insert a single key and value -*/ -void Data_Store::add(const std::string& key, const std::string& val) - { - multimap_insert(contents, key, val); - } - -/* -* Insert a single key and value -*/ -void Data_Store::add(const std::string& key, u32bit val) - { - add(key, to_string(val)); - } - -/* -* Insert a single key and value -*/ -void Data_Store::add(const std::string& key, const MemoryRegion& val) - { - Pipe pipe(new Hex_Encoder); - pipe.process_msg(val); - add(key, pipe.read_all_as_string()); - } - -/* -* Insert a mapping of key/value pairs -*/ -void Data_Store::add(const std::multimap& in) - { - std::multimap::const_iterator i = in.begin(); - while(i != in.end()) - { - contents.insert(*i); - ++i; - } - } - -} diff --git a/src/utils/datastor.h b/src/utils/datastor.h deleted file mode 100644 index 7ee626fda..000000000 --- a/src/utils/datastor.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -* Data Store -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_DATA_STORE_H__ -#define BOTAN_DATA_STORE_H__ - -#include -#include -#include -#include -#include - -namespace Botan { - -/** -* Data Store -*/ -class BOTAN_DLL Data_Store - { - public: - class BOTAN_DLL Matcher - { - public: - virtual bool operator()(const std::string&, - const std::string&) const = 0; - - virtual std::pair - transform(const std::string&, const std::string&) const; - - virtual ~Matcher() {} - }; - - bool operator==(const Data_Store&) const; - - std::multimap - search_with(const Matcher&) const; - - std::vector get(const std::string&) const; - - std::string get1(const std::string&) const; - - MemoryVector get1_memvec(const std::string&) const; - u32bit get1_u32bit(const std::string&, u32bit = 0) const; - - bool has_value(const std::string&) const; - - void add(const std::multimap&); - void add(const std::string&, const std::string&); - void add(const std::string&, u32bit); - void add(const std::string&, const MemoryRegion&); - private: - std::multimap contents; - }; - -} - -#endif diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp new file mode 100644 index 000000000..129dad9bf --- /dev/null +++ b/src/utils/datastor/datastor.cpp @@ -0,0 +1,172 @@ +/* +* Data Store +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include +#include +#include +#include +#include + +namespace Botan { + +/* +* Default Matcher transform operation (identity) +*/ +std::pair +Data_Store::Matcher::transform(const std::string& key, + const std::string& value) const + { + return std::make_pair(key, value); + } + +/* +* Data_Store Equality Comparison +*/ +bool Data_Store::operator==(const Data_Store& other) const + { + return (contents == other.contents); + } + +/* +* Check if this key has at least one value +*/ +bool Data_Store::has_value(const std::string& key) const + { + return (contents.lower_bound(key) != contents.end()); + } + +/* +* Search based on an arbitrary predicate +*/ +std::multimap +Data_Store::search_with(const Matcher& matcher) const + { + std::multimap out; + + std::multimap::const_iterator i = + contents.begin(); + + while(i != contents.end()) + { + if(matcher(i->first, i->second)) + out.insert(matcher.transform(i->first, i->second)); + ++i; + } + + return out; + } + +/* +* Search based on key equality +*/ +std::vector Data_Store::get(const std::string& looking_for) const + { + typedef std::multimap::const_iterator iter; + + std::pair range = contents.equal_range(looking_for); + + std::vector out; + for(iter i = range.first; i != range.second; ++i) + out.push_back(i->second); + return out; + } + +/* +* Get a single atom +*/ +std::string Data_Store::get1(const std::string& key) const + { + std::vector vals = get(key); + + if(vals.empty()) + throw Invalid_State("Data_Store::get1: Not values for " + key); + if(vals.size() > 1) + throw Invalid_State("Data_Store::get1: More than one value for " + key); + + return vals[0]; + } + +/* +* Get a single MemoryVector atom +*/ +MemoryVector +Data_Store::get1_memvec(const std::string& key) const + { + std::vector vals = get(key); + + if(vals.size() > 1) + throw Invalid_State("Data_Store::get1_memvec: Multiple values for " + + key); + + if(vals.empty()) + return MemoryVector(); + + Pipe pipe(new Hex_Decoder(FULL_CHECK)); + pipe.start_msg(); + if(vals.size()) + pipe.write(vals[0]); + pipe.end_msg(); + return pipe.read_all(); + } + +/* +* Get a single u32bit atom +*/ +u32bit Data_Store::get1_u32bit(const std::string& key, + u32bit default_val) const + { + std::vector vals = get(key); + + if(vals.empty()) + return default_val; + else if(vals.size() > 1) + throw Invalid_State("Data_Store::get1_u32bit: Multiple values for " + + key); + + return to_u32bit(vals[0]); + } + +/* +* Insert a single key and value +*/ +void Data_Store::add(const std::string& key, const std::string& val) + { + multimap_insert(contents, key, val); + } + +/* +* Insert a single key and value +*/ +void Data_Store::add(const std::string& key, u32bit val) + { + add(key, to_string(val)); + } + +/* +* Insert a single key and value +*/ +void Data_Store::add(const std::string& key, const MemoryRegion& val) + { + Pipe pipe(new Hex_Encoder); + pipe.process_msg(val); + add(key, pipe.read_all_as_string()); + } + +/* +* Insert a mapping of key/value pairs +*/ +void Data_Store::add(const std::multimap& in) + { + std::multimap::const_iterator i = in.begin(); + while(i != in.end()) + { + contents.insert(*i); + ++i; + } + } + +} diff --git a/src/utils/datastor/datastor.h b/src/utils/datastor/datastor.h new file mode 100644 index 000000000..7ee626fda --- /dev/null +++ b/src/utils/datastor/datastor.h @@ -0,0 +1,61 @@ +/* +* Data Store +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DATA_STORE_H__ +#define BOTAN_DATA_STORE_H__ + +#include +#include +#include +#include +#include + +namespace Botan { + +/** +* Data Store +*/ +class BOTAN_DLL Data_Store + { + public: + class BOTAN_DLL Matcher + { + public: + virtual bool operator()(const std::string&, + const std::string&) const = 0; + + virtual std::pair + transform(const std::string&, const std::string&) const; + + virtual ~Matcher() {} + }; + + bool operator==(const Data_Store&) const; + + std::multimap + search_with(const Matcher&) const; + + std::vector get(const std::string&) const; + + std::string get1(const std::string&) const; + + MemoryVector get1_memvec(const std::string&) const; + u32bit get1_u32bit(const std::string&, u32bit = 0) const; + + bool has_value(const std::string&) const; + + void add(const std::multimap&); + void add(const std::string&, const std::string&); + void add(const std::string&, u32bit); + void add(const std::string&, const MemoryRegion&); + private: + std::multimap contents; + }; + +} + +#endif diff --git a/src/utils/info.txt b/src/utils/info.txt index dcf4b9288..36b10df76 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -11,13 +11,10 @@ tru64 -> rt bit_ops.h bswap.h -buf_comp.h charset.cpp charset.h data_src.cpp data_src.h -datastor.cpp -datastor.h exceptn.cpp exceptn.h loadstor.h @@ -26,9 +23,6 @@ mlock.cpp parsing.cpp parsing.h rotate.h -scan_name.cpp -scan_name.h -secmem.h stl_util.h types.h ui.cpp @@ -39,9 +33,3 @@ version.cpp version.h xor_buf.h - - -alloc -filters -libstate - diff --git a/src/utils/scan_name.cpp b/src/utils/scan_name.cpp deleted file mode 100644 index ef771871d..000000000 --- a/src/utils/scan_name.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/** -SCAN Name Abstraction -(C) 2008 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include -#include -#include - -namespace Botan { - -namespace { - -std::vector -parse_and_deref_aliases(const std::string& algo_spec) - { - std::vector parts = parse_algorithm_name(algo_spec); - std::vector out; - - for(size_t i = 0; i != parts.size(); ++i) - { - std::string part_i = global_state().deref_alias(parts[i]); - - if(i == 0 && part_i.find_first_of(",()") != std::string::npos) - { - std::vector parts_i = parse_and_deref_aliases(part_i); - - for(size_t j = 0; j != parts_i.size(); ++j) - out.push_back(parts_i[j]); - } - else - out.push_back(part_i); - } - - return out; - } - -} - -SCAN_Name::SCAN_Name(const std::string& algo_spec) - { - orig_algo_spec = algo_spec; - - name = parse_and_deref_aliases(algo_spec); - - if(name.size() == 0) - throw Decoding_Error("Bad SCAN name " + algo_spec); - } - -std::string SCAN_Name::arg(u32bit i) const - { - if(i >= arg_count()) - throw std::range_error("SCAN_Name::argument"); - return name[i+1]; - } - -std::string SCAN_Name::arg(u32bit i, const std::string& def_value) const - { - if(i >= arg_count()) - return def_value; - return name[i+1]; - } - -u32bit SCAN_Name::arg_as_u32bit(u32bit i, u32bit def_value) const - { - if(i >= arg_count()) - return def_value; - return to_u32bit(name[i+1]); - } - -} diff --git a/src/utils/scan_name.h b/src/utils/scan_name.h deleted file mode 100644 index 9e7af40d6..000000000 --- a/src/utils/scan_name.h +++ /dev/null @@ -1,77 +0,0 @@ -/** -SCAN Name Abstraction -(C) 2008 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_SCAN_NAME_H__ -#define BOTAN_SCAN_NAME_H__ - -#include -#include -#include -#include - -namespace Botan { - -/** -A class encapsulating a SCAN name (similar to JCE conventions) -http://www.users.zetnet.co.uk/hopwood/crypto/scan/ -*/ -class SCAN_Name - { - public: - /** - @param algo_spec A SCAN name - */ - SCAN_Name(const std::string& algo_spec); - - /** - @return the original input string - */ - std::string as_string() const { return orig_algo_spec; } - - /** - @return the algorithm name - */ - std::string algo_name() const { return name[0]; } - - /** - @return the number of arguments - */ - u32bit arg_count() const { return name.size() - 1; } - - /** - @return if the number of arguments is between lower and upper - */ - bool arg_count_between(u32bit lower, u32bit upper) const - { return ((arg_count() >= lower) && (arg_count() <= upper)); } - - /** - @param i which argument - @return the ith argument - */ - std::string arg(u32bit i) const; - - /** - @param i which argument - @param def_value the default value - @return the ith argument or the default value - */ - std::string arg(u32bit i, const std::string& def_value) const; - - /** - @param i which argument - @param def_value the default value - @return the ith argument as a u32bit, or the default value - */ - u32bit arg_as_u32bit(u32bit i, u32bit def_value) const; - private: - std::string orig_algo_spec; - std::vector name; - }; - -} - -#endif diff --git a/src/utils/secmem.h b/src/utils/secmem.h deleted file mode 100644 index d64a376ca..000000000 --- a/src/utils/secmem.h +++ /dev/null @@ -1,438 +0,0 @@ -/* -* Secure Memory Buffers -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_SECURE_MEMORY_BUFFERS_H__ -#define BOTAN_SECURE_MEMORY_BUFFERS_H__ - -#include -#include -#include - -namespace Botan { - -/** -* This class represents variable length memory buffers. -*/ -template -class MemoryRegion - { - public: - /** - * Find out the size of the buffer, i.e. how many objects of type T it - * contains. - * @return the size of the buffer - */ - u32bit size() const { return used; } - - /** - * Find out whether this buffer is empty. - * @return true if the buffer is empty, false otherwise - */ - bool is_empty() const { return (used == 0); } - - /** - * Find out whether this buffer is non-empty - * @return true if the buffer is non-empty, false otherwise - */ - bool has_items() const { return (used != 0); } - - /** - * Get a pointer to the first element in the buffer. - * @return a pointer to the first element in the buffer - */ - operator T* () { return buf; } - - /** - * Get a constant pointer to the first element in the buffer. - * @return a constant pointer to the first element in the buffer - */ - operator const T* () const { return buf; } - - /** - * Get a pointer to the first element in the buffer. - * @return a pointer to the first element in the buffer - */ - T* begin() { return buf; } - - /** - * Get a constant pointer to the first element in the buffer. - * @return a constant pointer to the first element in the buffer - */ - const T* begin() const { return buf; } - - /** - * Get a pointer to the last element in the buffer. - * @return a pointer to the last element in the buffer - */ - T* end() { return (buf + size()); } - - /** - * Get a constant pointer to the last element in the buffer. - * @return a constant pointer to the last element in the buffer - */ - const T* end() const { return (buf + size()); } - - /** - * Check two buffers for equality. - * @return true iff the content of both buffers is byte-wise equal - */ - bool operator==(const MemoryRegion& other) const - { - return (size() == other.size() && - same_mem(buf, other.buf, size())); - } - - /** - * Compare two buffers lexicographically. - * @return true if this buffer is lexicographically smaller than other. - */ - bool operator<(const MemoryRegion& other) const; - - /** - * Check two buffers for inequality. - * @return false if the content of both buffers is byte-wise equal, true - * otherwise. - */ - bool operator!=(const MemoryRegion& in) const - { return (!(*this == in)); } - - /** - * Copy the contents of another buffer into this buffer. - * The former contents of *this are discarded. - * @param in the buffer to copy the contents from. - * @return a reference to *this - */ - MemoryRegion& operator=(const MemoryRegion& in) - { if(this != &in) set(in); return (*this); } - - /** - * The use of this function is discouraged because of the risk of memory - * errors. Use MemoryRegion::set() - * instead. - * Copy the contents of an array of objects of type T into this buffer. - * The former contents of *this are discarded. - * The length of *this must be at least n, otherwise memory errors occur. - * @param in the array to copy the contents from - * @param n the length of in - */ - void copy(const T in[], u32bit n) - { copy(0, in, n); } - - /** - * The use of this function is discouraged because of the risk of memory - * errors. Use MemoryRegion::set() - * instead. - * Copy the contents of an array of objects of type T into this buffer. - * The former contents of *this are discarded. - * The length of *this must be at least n, otherwise memory errors occur. - * @param off the offset position inside this buffer to start inserting - * the copied bytes - * @param in the array to copy the contents from - * @param n the length of in - */ - void copy(u32bit off, const T in[], u32bit n) - { copy_mem(buf + off, in, (n > size() - off) ? (size() - off) : n); } - - /** - * Set the contents of this according to the argument. The size of - * *this is increased if necessary. - * @param in the array of objects of type T to copy the contents from - * @param n the size of array in - */ - void set(const T in[], u32bit n) { create(n); copy(in, n); } - - /** - * Set the contents of this according to the argument. The size of - * *this is increased if necessary. - * @param in the buffer to copy the contents from - */ - void set(const MemoryRegion& in) { set(in.begin(), in.size()); } - - /** - * Append data to the end of this buffer. - * @param data the array containing the data to append - * @param n the size of the array data - */ - void append(const T data[], u32bit n) - { grow_to(size()+n); copy(size() - n, data, n); } - - /** - * Append a single element. - * @param x the element to append - */ - void append(T x) { append(&x, 1); } - - /** - * Append data to the end of this buffer. - * @param data the buffer containing the data to append - */ - void append(const MemoryRegion& x) { append(x.begin(), x.size()); } - - /** - * Zeroise the bytes of this buffer. The length remains unchanged. - */ - void clear() { clear_mem(buf, allocated); } - - /** - * Reset this buffer to an empty buffer with size zero. - */ - void destroy() { create(0); } - - /** - * Reset this buffer to a buffer of specified length. The content will be - * initialized to zero bytes. - * @param n the new length of the buffer - */ - void create(u32bit n); - - /** - * Preallocate memory, so that this buffer can grow up to size n without - * having to perform any actual memory allocations. (This is - * the same principle as for std::vector::reserve().) - */ - void grow_to(u32bit N); - - /** - * Swap this buffer with another object. - */ - void swap(MemoryRegion& other); - - ~MemoryRegion() { deallocate(buf, allocated); } - protected: - MemoryRegion() { buf = 0; alloc = 0; used = allocated = 0; } - MemoryRegion(const MemoryRegion& other) - { - buf = 0; - used = allocated = 0; - alloc = other.alloc; - set(other.buf, other.used); - } - - void init(bool locking, u32bit length = 0) - { alloc = Allocator::get(locking); create(length); } - private: - T* allocate(u32bit n) - { - return static_cast(alloc->allocate(sizeof(T)*n)); - } - - void deallocate(T* p, u32bit n) - { alloc->deallocate(p, sizeof(T)*n); } - - T* buf; - u32bit used; - u32bit allocated; - Allocator* alloc; - }; - -/* -* Create a new buffer -*/ -template -void MemoryRegion::create(u32bit n) - { - if(n <= allocated) { clear(); used = n; return; } - deallocate(buf, allocated); - buf = allocate(n); - allocated = used = n; - } - -/* -* Increase the size of the buffer -*/ -template -void MemoryRegion::grow_to(u32bit n) - { - if(n > used && n <= allocated) - { - clear_mem(buf + used, n - used); - used = n; - return; - } - else if(n > allocated) - { - T* new_buf = allocate(n); - copy_mem(new_buf, buf, used); - deallocate(buf, allocated); - buf = new_buf; - allocated = used = n; - } - } - -/* -* Compare this buffer with another one -*/ -template -bool MemoryRegion::operator<(const MemoryRegion& in) const - { - if(size() < in.size()) return true; - if(size() > in.size()) return false; - - for(u32bit j = 0; j != size(); j++) - { - if(buf[j] < in[j]) return true; - if(buf[j] > in[j]) return false; - } - - return false; - } - -/* -* Swap this buffer with another one -*/ -template -void MemoryRegion::swap(MemoryRegion& x) - { - std::swap(buf, x.buf); - std::swap(used, x.used); - std::swap(allocated, x.allocated); - std::swap(alloc, x.alloc); - } - -/** -* This class represents variable length buffers that do not -* make use of memory locking. -*/ -template -class MemoryVector : public MemoryRegion - { - public: - /** - * Copy the contents of another buffer into this buffer. - * @param in the buffer to copy the contents from - * @return a reference to *this - */ - MemoryVector& operator=(const MemoryRegion& in) - { if(this != &in) set(in); return (*this); } - - /** - * Create a buffer of the specified length. - * @param n the length of the buffer to create. - - */ - MemoryVector(u32bit n = 0) { MemoryRegion::init(false, n); } - - /** - * Create a buffer with the specified contents. - * @param in the array containing the data to be initially copied - * into the newly created buffer - * @param n the size of the arry in - */ - MemoryVector(const T in[], u32bit n) - { MemoryRegion::init(false); set(in, n); } - - /** - * Copy constructor. - */ - MemoryVector(const MemoryRegion& in) - { MemoryRegion::init(false); set(in); } - - /** - * Create a buffer whose content is the concatenation of two other - * buffers. - * @param in1 the first part of the new contents - * @param in2 the contents to be appended to in1 - */ - MemoryVector(const MemoryRegion& in1, const MemoryRegion& in2) - { MemoryRegion::init(false); set(in1); append(in2); } - }; - -/** -* This class represents variable length buffers using the operating -* systems capability to lock memory, i.e. keeping it from being -* swapped out to disk. In this way, a security hole allowing attackers -* to find swapped out secret keys is closed. Please refer to -* Botan::InitializerOptions::secure_memory() for restrictions and -* further details. -*/ -template -class SecureVector : public MemoryRegion - { - public: - /** - * Copy the contents of another buffer into this buffer. - * @param in the buffer to copy the contents from - * @return a reference to *this - */ - SecureVector& operator=(const MemoryRegion& in) - { if(this != &in) set(in); return (*this); } - - /** - * Create a buffer of the specified length. - * @param n the length of the buffer to create. - - */ - SecureVector(u32bit n = 0) { MemoryRegion::init(true, n); } - - /** - * Create a buffer with the specified contents. - * @param in the array containing the data to be initially copied - * into the newly created buffer - * @param n the size of the array in - */ - SecureVector(const T in[], u32bit n) - { MemoryRegion::init(true); set(in, n); } - - /** - * Create a buffer with contents specified contents. - * @param in the buffer holding the contents that will be - * copied into the newly created buffer. - */ - SecureVector(const MemoryRegion& in) - { MemoryRegion::init(true); set(in); } - - /** - * Create a buffer whose content is the concatenation of two other - * buffers. - * @param in1 the first part of the new contents - * @param in2 the contents to be appended to in1 - */ - SecureVector(const MemoryRegion& in1, const MemoryRegion& in2) - { MemoryRegion::init(true); set(in1); append(in2); } - }; - -/** -* This class represents fixed length buffers using the operating -* systems capability to lock memory, i.e. keeping it from being -* swapped out to disk. In this way, a security hole allowing attackers -* to find swapped out secret keys is closed. Please refer to -* Botan::InitializerOptions::secure_memory() for restrictions and -* further details. -*/ -template -class SecureBuffer : public MemoryRegion - { - public: - /** - * Copy the contents of another buffer into this buffer. - * @param in the buffer to copy the contents from - * @return a reference to *this - */ - SecureBuffer& operator=(const SecureBuffer& in) - { if(this != &in) set(in); return (*this); } - - /** - * Create a buffer of the length L. - */ - SecureBuffer() { MemoryRegion::init(true, L); } - - /** - * Create a buffer of size L with the specified contents. - * @param in the array containing the data to be initially copied - * into the newly created buffer - * @param n the size of the array in - */ - SecureBuffer(const T in[], u32bit n) - { MemoryRegion::init(true, L); copy(in, n); } - private: - SecureBuffer& operator=(const MemoryRegion& in) - { if(this != &in) set(in); return (*this); } - }; - -} - -#endif -- cgit v1.2.3