[Pettycoin-dev] [raw_decode_base_n PATCH 3/3] Add a test for raw_decode_base_n with n=16
Nelson Castillo
nelsoneci at gmail.com
Thu Aug 14 20:28:55 EST 2014
This is the first time that we test raw_decode_base_* with a BIGNUM that
is allocated with BN_new. This function was leaking before and it doesn not
leak now that raw_decode_base_n does not call BN_init (Fixed in previous patch).
In other workds, this call sequence works well now:
bn_priv = BN_new();
assert(raw_decode_base_n(bn_priv, priv_b16, strlen(priv_b16), 16));
Signed-off-by: Nelson Castillo <nelsoneci at gmail.com>
---
test/run-01-base16.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
create mode 100644 test/run-01-base16.c
diff --git a/test/run-01-base16.c b/test/run-01-base16.c
new file mode 100644
index 0000000..dec3272
--- /dev/null
+++ b/test/run-01-base16.c
@@ -0,0 +1,28 @@
+#include "../base58.c"
+
+int main(void)
+{
+ /* Address: 1PtcjakvZBeggokcAGb1KbVvMRi3NT6LMk. */
+ const char priv_b16[] =
+ "4e111544df178877C7e8483e92b7ef1b40cE7dc4e944261f4f32e2ed13340c0A";
+ const char priv_b10[] =
+ "35310585383039988783548932038956396952442822145226977502125905800903068486666";
+
+ BIGNUM *bn_priv;
+ BIGNUM *bn_priv_from_dec = NULL;
+ BIGNUM *bn_priv_from_hex = NULL;
+
+ bn_priv = BN_new();
+ assert(raw_decode_base_n(bn_priv, priv_b16, strlen(priv_b16), 16));
+ assert(BN_dec2bn(&bn_priv_from_dec, priv_b10) == strlen(priv_b10));
+ assert(BN_hex2bn(&bn_priv_from_hex, priv_b16) == strlen(priv_b16));
+
+ assert(BN_cmp(bn_priv, bn_priv_from_dec) == 0);
+ assert(BN_cmp(bn_priv, bn_priv_from_hex) == 0);
+
+ BN_free(bn_priv_from_hex);
+ BN_free(bn_priv_from_dec);
+ BN_free(bn_priv);
+
+ return 0;
+}
More information about the Pettycoin-dev
mailing list