diff options
author | lloyd <[email protected]> | 2010-09-07 22:58:45 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-09-07 22:58:45 +0000 |
commit | 23eb8c4250d9dc763978e5fbddc1c7e784839078 (patch) | |
tree | 707c83ac6e03fe8f35a2b2cbee944430166d280b /src/math/bigint/bigint.cpp | |
parent | 3c43fb5878bcf585dd32b1a74ae4dd733a89ac05 (diff) |
Realization while thinking about the recently added truncate: in a STL
container like vector, truncate is simply resize, but what
MemoryRegion called resize will zap the entire contents, and then what
was resize was called grow_to. This is really problematic in terms of
the goal of replacing MemoryRegion with a vector with a custom
allocator.
In this checkin:
- Remove MemoryRegion::grow_to and MemoryRegion::truncate
- Change the semantics of MemoryRegion::resize to change the size
while keeping any current contents intact (up to the new size),
zero initializing any new values.
Unrelated, just noticed the lack while I was in there, add a version
of CryptoBox::decrypt taking a std::string for the input.
Diffstat (limited to 'src/math/bigint/bigint.cpp')
-rw-r--r-- | src/math/bigint/bigint.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp index 7feec4d59..1ae8be130 100644 --- a/src/math/bigint/bigint.cpp +++ b/src/math/bigint/bigint.cpp @@ -114,7 +114,7 @@ void BigInt::swap(BigInt& other) */ void BigInt::grow_reg(u32bit n) { - reg.grow_to(round_up<u32bit>(size() + n, 8)); + reg.resize(round_up<u32bit>(size() + n, 8)); } /* @@ -123,7 +123,7 @@ void BigInt::grow_reg(u32bit n) void BigInt::grow_to(u32bit n) { if(n > size()) - reg.grow_to(round_up<u32bit>(n, 8)); + reg.resize(round_up<u32bit>(n, 8)); } /* @@ -348,6 +348,7 @@ void BigInt::binary_decode(const byte buf[], u32bit length) { const u32bit WORD_BYTES = sizeof(word); + reg.clear(); reg.resize(round_up<u32bit>((length / WORD_BYTES) + 1, 8)); for(u32bit j = 0; j != length / WORD_BYTES; ++j) |