aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_bigint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_bigint.cpp')
-rw-r--r--src/tests/test_bigint.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp
index 6f3d603db..cee7b5b8b 100644
--- a/src/tests/test_bigint.cpp
+++ b/src/tests/test_bigint.cpp
@@ -30,6 +30,7 @@ class BigInt_Unit_Tests : public Test
results.push_back(test_bigint_sizes());
results.push_back(test_random_integer());
+ results.push_back(test_encode());
return results;
}
@@ -143,6 +144,32 @@ class BigInt_Unit_Tests : public Test
return result;
}
+
+ Test::Result test_encode()
+ {
+ Test::Result result("BigInt encoding functions");
+
+ const BigInt n1(0xffff);
+ const BigInt n2(1023);
+
+ Botan::secure_vector<byte> encoded_n1 = BigInt::encode_1363(n1, 256);
+ Botan::secure_vector<byte> encoded_n2 = BigInt::encode_1363(n2, 256);
+ Botan::secure_vector<byte> expected = encoded_n1;
+ expected += encoded_n2;
+
+ Botan::secure_vector<byte> encoded_n1_n2 = BigInt::encode_fixed_length_int_pair(n1, n2, 256);
+ result.test_eq("encode_fixed_length_int_pair", encoded_n1_n2, expected);
+
+ for (size_t i = 0; i < 256 - n1.bytes(); ++i)
+ {
+ if ( encoded_n1[i] != 0 )
+ {
+ result.test_failure("encode_1363", "no zero byte");
+ }
+ }
+
+ return result;
+ }
};
BOTAN_REGISTER_TEST("bigint_unit", BigInt_Unit_Tests);