From d8b46948459e94c5664afaae63eeca489f13e7b0 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sun, 6 May 2018 14:57:06 +0900 Subject: [PATCH] add test of ecdsa::serializer --- test/ecdsa_c_test.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/ecdsa_c_test.cpp b/test/ecdsa_c_test.cpp index d3b360f..e0af381 100644 --- a/test/ecdsa_c_test.cpp +++ b/test/ecdsa_c_test.cpp @@ -2,6 +2,18 @@ #include #include +template +void serializeTest(const T& x, const Serializer& serialize, const Deserializer& deserialize) +{ + char buf[128]; + size_t n = serialize(buf, sizeof(buf), &x); + CYBOZU_TEST_ASSERT(n > 0); + T y; + size_t m = deserialize(&y, buf, n); + CYBOZU_TEST_EQUAL(m, n); + CYBOZU_TEST_ASSERT(memcmp(&x, &y, n) == 0); +} + CYBOZU_TEST_AUTO(ecdsa) { int ret; @@ -16,9 +28,12 @@ CYBOZU_TEST_AUTO(ecdsa) ret = ecdsaSecretKeySetByCSPRNG(&sec); CYBOZU_TEST_EQUAL(ret, 0); + serializeTest(sec, ecdsaSecretKeySerialize, ecdsaSecretKeyDeserialize); ecdsaGetPublicKey(&pub, &sec); + serializeTest(pub, ecdsaPublicKeySerialize, ecdsaPublicKeyDeserialize); ecdsaSign(&sig, &sec, msg, msgSize); + serializeTest(sig, ecdsaSignatureSerialize, ecdsaSignatureDeserialize); CYBOZU_TEST_ASSERT(ecdsaVerify(&sig, &pub, msg, msgSize)); ppub = ecdsaPrecomputedPublicKeyCreate();