From 0f77b4efb162995d108d8fd78afd798cf417f000 Mon Sep 17 00:00:00 2001 From: rnburn Date: Fri, 18 Oct 2024 09:50:42 -0700 Subject: [PATCH] add file io test --- cbindings/BUILD | 1 + cbindings/fixed_pedersen.t.cc | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cbindings/BUILD b/cbindings/BUILD index 2e9459df..3ee04e29 100644 --- a/cbindings/BUILD +++ b/cbindings/BUILD @@ -168,6 +168,7 @@ sxt_cc_component( ], test_deps = [ ":backend", + "//sxt/base/test:temp_file", "//sxt/base/test:unit_test", "//sxt/curve21/operation:add", "//sxt/curve21/operation:double", diff --git a/cbindings/fixed_pedersen.t.cc b/cbindings/fixed_pedersen.t.cc index f28b898a..cf736156 100644 --- a/cbindings/fixed_pedersen.t.cc +++ b/cbindings/fixed_pedersen.t.cc @@ -19,6 +19,7 @@ #include #include "cbindings/backend.h" +#include "sxt/base/test/temp_file.h" #include "sxt/base/test/unit_test.h" #include "sxt/curve21/operation/add.h" #include "sxt/curve21/operation/double.h" @@ -75,6 +76,25 @@ TEST_CASE("we can compute multi-exponentiations with a fixed set of generators") REQUIRE(res == generators[0] + 2 * 256 * generators[1]); } + SECTION("we can read and write a handle to a file") { + bastst::temp_file temp_file{std::ios::binary}; + temp_file.stream().close(); + + wrapped_handle h{generators.data(), 2}; + REQUIRE(h.h != nullptr); + + sxt_multiexp_handle_write_to_file(h.h, temp_file.name().c_str()); + + auto hp = sxt_multiexp_handle_new_from_file(SXT_CURVE_RISTRETTO255, temp_file.name().c_str()); + + uint8_t scalars[] = {1, 0, 0, 2}; + c21t::element_p3 res; + sxt_fixed_multiexponentiation(&res, hp, 2, 1, 2, scalars); + REQUIRE(res == generators[0] + 2 * 256 * generators[1]); + + sxt_multiexp_handle_free(hp); + } + SECTION("we can compute a multiexponentiation in packed form") { cbn::reset_backend_for_testing(); const sxt_config config = {SXT_GPU_BACKEND, 0};