aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc/secmem.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-07 23:40:31 +0000
committerlloyd <[email protected]>2010-09-07 23:40:31 +0000
commit197f7cd4f744ae8246832343dc514296632554b2 (patch)
tree63963dfab01e29ce32be4c1d43e62506d9f0246d /src/alloc/secmem.h
parent5f83d344e49a6d62cd8989d9fb8f8ca80ed48fc1 (diff)
Big, invasive but mostly automated change, with a further attempt at
harmonising MemoryRegion with std::vector: The MemoryRegion::clear() function would zeroise the buffer, but keep the memory allocated and the size unchanged. This is very different from STL's clear(), which is basically the equivalent to what is called destroy() in MemoryRegion. So to be able to replace MemoryRegion with a std::vector, we have to rename destroy() to clear() and we have to expose the current functionality of clear() in some other way, since vector doesn't support this operation. Do so by adding a global function named zeroise() which takes a MemoryRegion which is zeroed. Remove clear() to ensure all callers are updated.
Diffstat (limited to 'src/alloc/secmem.h')
-rw-r--r--src/alloc/secmem.h46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/alloc/secmem.h b/src/alloc/secmem.h
index aae1634d3..37930b963 100644
--- a/src/alloc/secmem.h
+++ b/src/alloc/secmem.h
@@ -126,21 +126,6 @@ class MemoryRegion
{ 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) { resize(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<T>& 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
@@ -162,11 +147,6 @@ class MemoryRegion
{ append(other.begin(), other.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() { resize(0); }
@@ -206,6 +186,22 @@ class MemoryRegion
*/
void init(bool locking, u32bit length = 0)
{ alloc = Allocator::get(locking); resize(length); }
+
+ /**
+ * 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) { resize(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<T>& in) { set(in.begin(), in.size()); }
+
private:
T* allocate(u32bit n)
{
@@ -393,6 +389,16 @@ class SecureVector : public MemoryRegion<T>
{ init(true); set(in1); append(in2); }
};
+/**
+* Zeroise the values; length remains unchanged
+* @param vec the vector to zeroise
+*/
+template<typename T>
+void zeroise(MemoryRegion<T>& vec)
+ {
+ clear_mem(&vec[0], vec.size());
+ }
+
}
#endif