aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-08-01 14:38:54 +0000
committerlloyd <[email protected]>2012-08-01 14:38:54 +0000
commit10e7da367713352975c684d18d1377559c71ea24 (patch)
tree453a37d5e5202f56cc4afaea3149cf47784b1b1b
parentcbefe4dd95982006e4d8391aea645e40baa17496 (diff)
Remove all support for octal BigInt conversions.
-rw-r--r--doc/relnotes/1_11_1.rst10
-rw-r--r--src/math/bigint/big_code.cpp39
-rw-r--r--src/math/bigint/big_io.cpp2
-rw-r--r--src/math/bigint/bigint.cpp16
-rw-r--r--src/math/bigint/bigint.h7
5 files changed, 35 insertions, 39 deletions
diff --git a/doc/relnotes/1_11_1.rst b/doc/relnotes/1_11_1.rst
index 07b1fc62e..f0fd0a84e 100644
--- a/doc/relnotes/1_11_1.rst
+++ b/doc/relnotes/1_11_1.rst
@@ -11,3 +11,13 @@ A new :cpp:class:`Path_Validation_Result` code has been added
below 80 bits of strength (as estimated by ``estimated_strength``) are
rejected. This level can be modified using a parameter to the
:cpp:class:`Path_Validation_Restrictions` constructor.
+
+
+BigInt Modifications
+""""""""""""""""""""""""""""""""""""""""
+
+Several :cpp:class:`BigInt` functions have been removed, including
+``operator[]``, ``get_reg``, and ``grow_reg``. The version of ``data``
+that returns a mutable pointer has been renamed ``mutable_data``.
+Support for octal conversions has been removed.
+
diff --git a/src/math/bigint/big_code.cpp b/src/math/bigint/big_code.cpp
index d5b1e98ae..972312cdb 100644
--- a/src/math/bigint/big_code.cpp
+++ b/src/math/bigint/big_code.cpp
@@ -1,6 +1,6 @@
/*
* BigInt Encoding/Decoding
-* (C) 1999-2010 Jack Lloyd
+* (C) 1999-2010,2012 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -18,7 +18,9 @@ namespace Botan {
void BigInt::encode(byte output[], const BigInt& n, Base base)
{
if(base == Binary)
+ {
n.binary_encode(output);
+ }
else if(base == Hexadecimal)
{
secure_vector<byte> binary(n.encoded_size(Binary));
@@ -27,18 +29,6 @@ void BigInt::encode(byte output[], const BigInt& n, Base base)
hex_encode(reinterpret_cast<char*>(output),
&binary[0], binary.size());
}
- else if(base == Octal)
- {
- BigInt copy = n;
- const size_t output_size = n.encoded_size(Octal);
- for(size_t j = 0; j != output_size; ++j)
- {
- output[output_size - 1 - j] =
- Charset::digit2char(static_cast<byte>(copy % 8));
-
- copy /= 8;
- }
- }
else if(base == Decimal)
{
BigInt copy = n;
@@ -132,28 +122,23 @@ BigInt BigInt::decode(const byte buf[], size_t length, Base base)
r.binary_decode(&binary[0], binary.size());
}
- else if(base == Decimal || base == Octal)
+ else if(base == Decimal)
{
- const size_t RADIX = ((base == Decimal) ? 10 : 8);
- for(size_t j = 0; j != length; ++j)
+ for(size_t i = 0; i != length; ++i)
{
- if(Charset::is_space(buf[j]))
+ if(Charset::is_space(buf[i]))
continue;
- if(!Charset::is_digit(buf[j]))
+ if(!Charset::is_digit(buf[i]))
throw Invalid_Argument("BigInt::decode: "
"Invalid character in decimal input");
- byte x = Charset::char2digit(buf[j]);
- if(x >= RADIX)
- {
- if(RADIX == 10)
- throw Invalid_Argument("BigInt: Invalid decimal string");
- else
- throw Invalid_Argument("BigInt: Invalid octal string");
- }
+ const byte x = Charset::char2digit(buf[i]);
+
+ if(x >= 10)
+ throw Invalid_Argument("BigInt: Invalid decimal string");
- r *= RADIX;
+ r *= 10;
r += x;
}
}
diff --git a/src/math/bigint/big_io.cpp b/src/math/bigint/big_io.cpp
index 130a98a3b..095d56510 100644
--- a/src/math/bigint/big_io.cpp
+++ b/src/math/bigint/big_io.cpp
@@ -19,7 +19,7 @@ std::ostream& operator<<(std::ostream& stream, const BigInt& n)
if(stream.flags() & std::ios::hex)
base = BigInt::Hexadecimal;
else if(stream.flags() & std::ios::oct)
- base = BigInt::Octal;
+ throw std::runtime_error("Octal output of BigInt not supported");
if(n == 0)
stream.write("0", 1);
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp
index e28f71df5..7ff1183a3 100644
--- a/src/math/bigint/bigint.cpp
+++ b/src/math/bigint/bigint.cpp
@@ -56,13 +56,19 @@ BigInt::BigInt(const std::string& str)
Base base = Decimal;
size_t markers = 0;
bool negative = false;
- if(str.length() > 0 && str[0] == '-') { markers += 1; negative = true; }
+
+ if(str.length() > 0 && str[0] == '-')
+ {
+ markers += 1;
+ negative = true;
+ }
if(str.length() > markers + 2 && str[markers ] == '0' &&
str[markers + 1] == 'x')
- { markers += 2; base = Hexadecimal; }
- else if(str.length() > markers + 1 && str[markers] == '0')
- { markers += 1; base = Octal; }
+ {
+ markers += 2;
+ base = Hexadecimal;
+ }
*this = decode(reinterpret_cast<const byte*>(str.data()) + markers,
str.length() - markers, base);
@@ -248,8 +254,6 @@ size_t BigInt::encoded_size(Base base) const
return bytes();
else if(base == Hexadecimal)
return 2*bytes();
- else if(base == Octal)
- return ((bits() + 2) / 3);
else if(base == Decimal)
return static_cast<size_t>((bits() * LOG_2_BASE_10) + 1);
else
diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h
index 81217d0bd..a4918509f 100644
--- a/src/math/bigint/bigint.h
+++ b/src/math/bigint/bigint.h
@@ -25,7 +25,7 @@ class BOTAN_DLL BigInt
/**
* Base enumerator for encoding and decoding
*/
- enum Base { Octal = 8, Decimal = 10, Hexadecimal = 16, Binary = 256 };
+ enum Base { Decimal = 10, Hexadecimal = 16, Binary = 256 };
/**
* Sign symbol definitions for positive and negative numbers
@@ -466,10 +466,7 @@ class BOTAN_DLL BigInt
/**
* Create BigInt from a string. If the string starts with 0x the
* rest of the string will be interpreted as hexadecimal digits.
- * If the string starts with 0 and the second character is NOT an
- * 'x' the string will be interpreted as octal digits. If the
- * string starts with non-zero digit, it will be interpreted as a
- * decimal number.
+ * Otherwise, it will be interpreted as a decimal number.
*
* @param str the string to parse for an integer value
*/