aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-18 20:32:36 +0000
committerlloyd <[email protected]>2012-05-18 20:32:36 +0000
commitc691561f3198f481c13457433efbccc1c9fcd898 (patch)
treea45ea2c5a30e0cb009fbcb68a61ef39332ff790c /src/utils
parentd76700f01c7ecac5633edf75f8d7408b46c5dbac (diff)
Fairly huge update that replaces the old secmem types with std::vector
using a custom allocator. Currently our allocator just does new/delete with a memset before deletion, and the mmap and mlock allocators have been removed.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/datastor/datastor.cpp15
-rw-r--r--src/utils/datastor/datastor.h5
-rw-r--r--src/utils/xor_buf.h26
3 files changed, 39 insertions, 7 deletions
diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp
index 363136c69..d65b3f1ac 100644
--- a/src/utils/datastor/datastor.cpp
+++ b/src/utils/datastor/datastor.cpp
@@ -72,21 +72,21 @@ std::string Data_Store::get1(const std::string& key) const
}
/*
-* Get a single MemoryVector atom
+* Get a single std::vector atom
*/
-MemoryVector<byte>
+std::vector<byte>
Data_Store::get1_memvec(const std::string& key) const
{
std::vector<std::string> vals = get(key);
if(vals.empty())
- return MemoryVector<byte>();
+ return std::vector<byte>();
if(vals.size() > 1)
throw Invalid_State("Data_Store::get1_memvec: Multiple values for " +
key);
- return hex_decode(vals[0]);
+ return unlock(hex_decode(vals[0]));
}
/*
@@ -125,7 +125,12 @@ void Data_Store::add(const std::string& key, u32bit val)
/*
* Insert a single key and value
*/
-void Data_Store::add(const std::string& key, const MemoryRegion<byte>& val)
+void Data_Store::add(const std::string& key, const secure_vector<byte>& val)
+ {
+ add(key, hex_encode(&val[0], val.size()));
+ }
+
+void Data_Store::add(const std::string& key, const std::vector<byte>& val)
{
add(key, hex_encode(&val[0], val.size()));
}
diff --git a/src/utils/datastor/datastor.h b/src/utils/datastor/datastor.h
index 26a0d418c..b471f85e1 100644
--- a/src/utils/datastor/datastor.h
+++ b/src/utils/datastor/datastor.h
@@ -35,7 +35,7 @@ class BOTAN_DLL Data_Store
std::string get1(const std::string&) const;
- MemoryVector<byte> get1_memvec(const std::string&) const;
+ std::vector<byte> get1_memvec(const std::string&) const;
u32bit get1_u32bit(const std::string&, u32bit = 0) const;
bool has_value(const std::string&) const;
@@ -43,7 +43,8 @@ class BOTAN_DLL Data_Store
void add(const std::multimap<std::string, std::string>&);
void add(const std::string&, const std::string&);
void add(const std::string&, u32bit);
- void add(const std::string&, const MemoryRegion<byte>&);
+ void add(const std::string&, const secure_vector<byte>&);
+ void add(const std::string&, const std::vector<byte>&);
private:
std::multimap<std::string, std::string> contents;
};
diff --git a/src/utils/xor_buf.h b/src/utils/xor_buf.h
index 3c96dea70..b67d84c50 100644
--- a/src/utils/xor_buf.h
+++ b/src/utils/xor_buf.h
@@ -9,6 +9,7 @@
#define BOTAN_XOR_BUF_H__
#include <botan/types.h>
+#include <vector>
namespace Botan {
@@ -70,6 +71,31 @@ inline void xor_buf(byte out[],
out[i] = in[i] ^ in2[i];
}
+template<typename Alloc, typename Alloc2>
+void xor_buf(std::vector<byte, Alloc>& out,
+ const std::vector<byte, Alloc2>& in,
+ size_t n)
+ {
+ xor_buf(&out[0], &in[0], n);
+ }
+
+template<typename Alloc>
+void xor_buf(std::vector<byte, Alloc>& out,
+ const byte* in,
+ size_t n)
+ {
+ xor_buf(&out[0], in, n);
+ }
+
+template<typename Alloc, typename Alloc2>
+void xor_buf(std::vector<byte, Alloc>& out,
+ const byte* in,
+ const std::vector<byte, Alloc2>& in2,
+ size_t n)
+ {
+ xor_buf(&out[0], &in[0], &in2[0], n);
+ }
+
}
#endif