From e707fdbbdee0e001b89db3eab21600b14c56a1d4 Mon Sep 17 00:00:00 2001 From: Rene Meusel Date: Fri, 22 Dec 2023 16:30:58 +0100 Subject: [PATCH] std::span for BigInt constructors --- src/lib/math/bigint/bigint.cpp | 11 ++++++----- src/lib/math/bigint/bigint.h | 13 ++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp index 3ab1e3d49fd..6817d9736b4 100644 --- a/src/lib/math/bigint/bigint.cpp +++ b/src/lib/math/bigint/bigint.cpp @@ -79,7 +79,8 @@ BigInt::BigInt(std::string_view str) { base = Hexadecimal; } - *this = decode(cast_char_ptr_to_uint8(str.data()) + markers, str.length() - markers, base); + std::span strdata(cast_char_ptr_to_uint8(str.data()), str.length()); + *this = decode(strdata.subspan(markers), base); if(negative) { set_sign(Negative); @@ -88,15 +89,15 @@ BigInt::BigInt(std::string_view str) { } } -BigInt::BigInt(const uint8_t input[], size_t length) { - binary_decode(input, length); +BigInt::BigInt(std::span input) { + binary_decode(input); } /* * Construct a BigInt from an encoded BigInt */ -BigInt::BigInt(const uint8_t input[], size_t length, Base base) { - *this = decode(input, length, base); +BigInt::BigInt(std::span input, Base base) { + *this = decode(input.data(), input.size(), base); } //static diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h index 83ace2e27ff..68e194beec6 100644 --- a/src/lib/math/bigint/bigint.h +++ b/src/lib/math/bigint/bigint.h @@ -94,13 +94,13 @@ class BOTAN_PUBLIC_API(2, 0) BigInt final { * @param buf the byte array holding the value * @param length size of buf */ - BigInt(const uint8_t buf[], size_t length); + BigInt(const uint8_t buf[], size_t length) : BigInt(std::span{buf, length}) {} /** * Create a BigInt from an integer in a byte array * @param vec the byte vector holding the value */ - explicit BigInt(std::span vec) : BigInt(vec.data(), vec.size()) {} + explicit BigInt(std::span vec); /** * Create a BigInt from an integer in a byte array @@ -108,7 +108,14 @@ class BOTAN_PUBLIC_API(2, 0) BigInt final { * @param length size of buf * @param base is the number base of the integer in buf */ - BigInt(const uint8_t buf[], size_t length, Base base); + BigInt(const uint8_t buf[], size_t length, Base base) : BigInt(std::span{buf, length}, base) {} + + /** + * Create a BigInt from an integer in a byte array + * @param buf the byte array holding the value + * @param base is the number base of the integer in buf + */ + BigInt(std::span buf, Base base); /** * Create a BigInt from an integer in a byte array