From 0f3705b7dbeee7174a4ad562d8f98d5b4e3839cf Mon Sep 17 00:00:00 2001 From: pasta Date: Wed, 4 Dec 2024 09:33:43 -0600 Subject: [PATCH] simplify G1Element::Serialize by using G1Element::SerializeToArray --- src/elements.cpp | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/elements.cpp b/src/elements.cpp index e032f8c99..d8d257e02 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -171,23 +171,8 @@ uint32_t G1Element::GetFingerprint(const bool fLegacy) const } std::vector G1Element::Serialize(const bool fLegacy) const { - uint8_t buffer[G1Element::SIZE + 1]; - g1_write_bin(buffer, G1Element::SIZE + 1, p, 1); - - if (buffer[0] == 0x00) { // infinity - std::vector result(G1Element::SIZE, 0); - result[0] = 0xc0; - return result; - } - - if (buffer[0] == 0x03) { // sign bit set - buffer[1] |= fLegacy ? 0x80 : 0x20; - } - - if (!fLegacy) { - buffer[1] |= 0x80; // indicate compression - } - return std::vector(buffer + 1, buffer + 1 + G1Element::SIZE); + const auto arr = G1Element::SerializeToArray(fLegacy); + return std::vector{arr.begin(), arr.end()}; } std::array G1Element::SerializeToArray(const bool fLegacy) const {