diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-09-24 21:12:04 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-09-24 21:12:04 +0800 |
commit | db844ba8309960aef490a8000adbd7820bf057dd (patch) | |
tree | 97eebf99e0518ad592893a061fb42eef23467d8b | |
parent | d78847f34ddbff49942baa894bd9d7c922c1a79d (diff) | |
download | tangerine-mcl-db844ba8309960aef490a8000adbd7820bf057dd.tar.gz tangerine-mcl-db844ba8309960aef490a8000adbd7820bf057dd.tar.zst tangerine-mcl-db844ba8309960aef490a8000adbd7820bf057dd.zip |
writeHexStr is same api of cybozu::write
-rw-r--r-- | include/mcl/conversion.hpp | 9 | ||||
-rw-r--r-- | include/mcl/ec.hpp | 2 | ||||
-rw-r--r-- | include/mcl/fp.hpp | 2 | ||||
-rw-r--r-- | test/conversion_test.cpp | 4 |
4 files changed, 9 insertions, 8 deletions
diff --git a/include/mcl/conversion.hpp b/include/mcl/conversion.hpp index 5ba7de0..798a549 100644 --- a/include/mcl/conversion.hpp +++ b/include/mcl/conversion.hpp @@ -451,17 +451,16 @@ size_t strToArray(bool *pIsMinus, UT *x, size_t xN, const char *buf, size_t bufS return true if success else flase */ template<class OutputStream> -bool writeHexStr(OutputStream& os, const void *src, size_t n) +void writeHexStr(bool *pb, OutputStream& os, const void *src, size_t n) { - bool b; const uint8_t *p = (const uint8_t *)src; for (size_t i = 0; i < n; i++) { char hex[2]; cybozu::itohex(hex, sizeof(hex), p[i], false); - cybozu::write(&b, os, hex, sizeof(hex)); - if (!b) return false; + cybozu::write(pb, os, hex, sizeof(hex)); + if (!*pb) return; } - return true; + *pb = true; } /* read hex string from is and convert it to byte array diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 9b09486..ec46602 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -713,7 +713,7 @@ public: } } if (ioMode & IoSerializeHexStr) { - *pb = mcl::fp::writeHexStr(os, buf, n + adj); + mcl::fp::writeHexStr(pb, os, buf, n + adj); } else { cybozu::write(pb, os, buf, n + adj); } diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index ca3feae..4850012 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -278,7 +278,7 @@ public: fp::Block b; getBlock(b); if (ioMode & IoSerializeHexStr) { - *pb = mcl::fp::writeHexStr(os, b.p, n); + mcl::fp::writeHexStr(pb, os, b.p, n); } else { cybozu::write(pb, os, b.p, n); } diff --git a/test/conversion_test.cpp b/test/conversion_test.cpp index 06f31af..ec11fe9 100644 --- a/test/conversion_test.cpp +++ b/test/conversion_test.cpp @@ -82,7 +82,9 @@ CYBOZU_TEST_AUTO(writeHexStr) const char *bin = tbl[i].bin; const char *hex = tbl[i].hex; size_t n = tbl[i].n; - CYBOZU_TEST_ASSERT(mcl::fp::writeHexStr(os, bin, n)); + bool b; + mcl::fp::writeHexStr(&b, os, bin, n); + CYBOZU_TEST_ASSERT(b); CYBOZU_TEST_EQUAL(os.getPos(), n * 2); CYBOZU_TEST_EQUAL_ARRAY(buf, hex, n * 2); |