From 008c89edde34cc0e13bfdff54046d6e9392d72f7 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 8 Mar 2024 15:38:01 -0700 Subject: [PATCH] LibCrypto: Add observers for the *byte* length of UnsignedBigInteger When calling the export_data method, it's a bit of a hassle to remember that the caller's buffer needs to be the length() * Word. --- Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h b/Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h index ac817f7a93..1ec8e74882 100644 --- a/Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h +++ b/Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h @@ -99,6 +99,9 @@ public: // The "trimmed length" is the number of words after trimming leading zeroed words [[nodiscard]] size_t trimmed_length() const; + [[nodiscard]] size_t byte_length() const { return length() * sizeof(Word); } + [[nodiscard]] size_t trimmed_byte_length() const { return trimmed_length() * sizeof(Word); } + void clamp_to_trimmed_length(); void resize_with_leading_zeros(size_t num_words);