Skip to content

Commit dab814e

Browse files
LucasCholletbgianfo
authored andcommitted
LibCrypto: Add the [[nodiscard]] qualifier in both BigInteger classes
1 parent 303be38 commit dab814e

File tree

2 files changed

+71
-71
lines changed

2 files changed

+71
-71
lines changed

Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ class SignedBigInteger {
4040
{
4141
}
4242

43-
static SignedBigInteger create_invalid()
43+
[[nodiscard]] static SignedBigInteger create_invalid()
4444
{
4545
return { UnsignedBigInteger::create_invalid(), false };
4646
}
4747

48-
static SignedBigInteger import_data(StringView data) { return import_data((u8 const*)data.characters_without_null_termination(), data.length()); }
49-
static SignedBigInteger import_data(u8 const* ptr, size_t length);
48+
[[nodiscard]] static SignedBigInteger import_data(StringView data) { return import_data((u8 const*)data.characters_without_null_termination(), data.length()); }
49+
[[nodiscard]] static SignedBigInteger import_data(u8 const* ptr, size_t length);
5050

51-
static SignedBigInteger create_from(i64 value)
51+
[[nodiscard]] static SignedBigInteger create_from(i64 value)
5252
{
5353
auto sign = false;
5454
u64 unsigned_value;
@@ -63,15 +63,15 @@ class SignedBigInteger {
6363

6464
size_t export_data(Bytes, bool remove_leading_zeros = false) const;
6565

66-
static SignedBigInteger from_base(u16 N, StringView str);
67-
String to_base(u16 N) const;
66+
[[nodiscard]] static SignedBigInteger from_base(u16 N, StringView str);
67+
[[nodiscard]] String to_base(u16 N) const;
6868

69-
u64 to_u64() const;
70-
double to_double() const;
69+
[[nodiscard]] u64 to_u64() const;
70+
[[nodiscard]] double to_double() const;
7171

72-
UnsignedBigInteger const& unsigned_value() const { return m_unsigned_data; }
73-
Vector<u32, STARTING_WORD_SIZE> const words() const { return m_unsigned_data.words(); }
74-
bool is_negative() const { return m_sign; }
72+
[[nodiscard]] UnsignedBigInteger const& unsigned_value() const { return m_unsigned_data; }
73+
[[nodiscard]] Vector<u32, STARTING_WORD_SIZE> const words() const { return m_unsigned_data.words(); }
74+
[[nodiscard]] bool is_negative() const { return m_sign; }
7575

7676
void negate()
7777
{
@@ -101,42 +101,42 @@ class SignedBigInteger {
101101
m_unsigned_data.invalidate();
102102
}
103103

104-
bool is_invalid() const { return m_unsigned_data.is_invalid(); }
104+
[[nodiscard]] bool is_invalid() const { return m_unsigned_data.is_invalid(); }
105105

106106
// These get + 1 byte for the sign.
107-
size_t length() const { return m_unsigned_data.length() + 1; }
108-
size_t trimmed_length() const { return m_unsigned_data.trimmed_length() + 1; };
109-
110-
SignedBigInteger plus(SignedBigInteger const& other) const;
111-
SignedBigInteger minus(SignedBigInteger const& other) const;
112-
SignedBigInteger bitwise_or(SignedBigInteger const& other) const;
113-
SignedBigInteger bitwise_and(SignedBigInteger const& other) const;
114-
SignedBigInteger bitwise_xor(SignedBigInteger const& other) const;
115-
SignedBigInteger bitwise_not() const;
116-
SignedBigInteger shift_left(size_t num_bits) const;
117-
SignedBigInteger multiplied_by(SignedBigInteger const& other) const;
118-
SignedDivisionResult divided_by(SignedBigInteger const& divisor) const;
119-
120-
SignedBigInteger plus(UnsignedBigInteger const& other) const;
121-
SignedBigInteger minus(UnsignedBigInteger const& other) const;
122-
SignedBigInteger multiplied_by(UnsignedBigInteger const& other) const;
123-
SignedDivisionResult divided_by(UnsignedBigInteger const& divisor) const;
124-
125-
u32 hash() const;
107+
[[nodiscard]] size_t length() const { return m_unsigned_data.length() + 1; }
108+
[[nodiscard]] size_t trimmed_length() const { return m_unsigned_data.trimmed_length() + 1; };
109+
110+
[[nodiscard]] SignedBigInteger plus(SignedBigInteger const& other) const;
111+
[[nodiscard]] SignedBigInteger minus(SignedBigInteger const& other) const;
112+
[[nodiscard]] SignedBigInteger bitwise_or(SignedBigInteger const& other) const;
113+
[[nodiscard]] SignedBigInteger bitwise_and(SignedBigInteger const& other) const;
114+
[[nodiscard]] SignedBigInteger bitwise_xor(SignedBigInteger const& other) const;
115+
[[nodiscard]] SignedBigInteger bitwise_not() const;
116+
[[nodiscard]] SignedBigInteger shift_left(size_t num_bits) const;
117+
[[nodiscard]] SignedBigInteger multiplied_by(SignedBigInteger const& other) const;
118+
[[nodiscard]] SignedDivisionResult divided_by(SignedBigInteger const& divisor) const;
119+
120+
[[nodiscard]] SignedBigInteger plus(UnsignedBigInteger const& other) const;
121+
[[nodiscard]] SignedBigInteger minus(UnsignedBigInteger const& other) const;
122+
[[nodiscard]] SignedBigInteger multiplied_by(UnsignedBigInteger const& other) const;
123+
[[nodiscard]] SignedDivisionResult divided_by(UnsignedBigInteger const& divisor) const;
124+
125+
[[nodiscard]] u32 hash() const;
126126

127127
void set_bit_inplace(size_t bit_index);
128128

129-
bool operator==(SignedBigInteger const& other) const;
130-
bool operator!=(SignedBigInteger const& other) const;
131-
bool operator<(SignedBigInteger const& other) const;
132-
bool operator<=(SignedBigInteger const& other) const;
133-
bool operator>(SignedBigInteger const& other) const;
134-
bool operator>=(SignedBigInteger const& other) const;
135-
136-
bool operator==(UnsignedBigInteger const& other) const;
137-
bool operator!=(UnsignedBigInteger const& other) const;
138-
bool operator<(UnsignedBigInteger const& other) const;
139-
bool operator>(UnsignedBigInteger const& other) const;
129+
[[nodiscard]] bool operator==(SignedBigInteger const& other) const;
130+
[[nodiscard]] bool operator!=(SignedBigInteger const& other) const;
131+
[[nodiscard]] bool operator<(SignedBigInteger const& other) const;
132+
[[nodiscard]] bool operator<=(SignedBigInteger const& other) const;
133+
[[nodiscard]] bool operator>(SignedBigInteger const& other) const;
134+
[[nodiscard]] bool operator>=(SignedBigInteger const& other) const;
135+
136+
[[nodiscard]] bool operator==(UnsignedBigInteger const& other) const;
137+
[[nodiscard]] bool operator!=(UnsignedBigInteger const& other) const;
138+
[[nodiscard]] bool operator<(UnsignedBigInteger const& other) const;
139+
[[nodiscard]] bool operator>(UnsignedBigInteger const& other) const;
140140

141141
private:
142142
void ensure_sign_is_valid()

Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class UnsignedBigInteger {
3434

3535
UnsignedBigInteger() = default;
3636

37-
static UnsignedBigInteger create_invalid();
37+
[[nodiscard]] static UnsignedBigInteger create_invalid();
3838

39-
static UnsignedBigInteger import_data(StringView data) { return import_data((u8 const*)data.characters_without_null_termination(), data.length()); }
40-
static UnsignedBigInteger import_data(u8 const* ptr, size_t length)
39+
[[nodiscard]] static UnsignedBigInteger import_data(StringView data) { return import_data((u8 const*)data.characters_without_null_termination(), data.length()); }
40+
[[nodiscard]] static UnsignedBigInteger import_data(u8 const* ptr, size_t length)
4141
{
4242
return UnsignedBigInteger(ptr, length);
4343
}
4444

45-
static UnsignedBigInteger create_from(u64 value)
45+
[[nodiscard]] static UnsignedBigInteger create_from(u64 value)
4646
{
4747
VERIFY(sizeof(Word) == 4);
4848
UnsignedBigInteger integer;
@@ -54,13 +54,13 @@ class UnsignedBigInteger {
5454

5555
size_t export_data(Bytes, bool remove_leading_zeros = false) const;
5656

57-
static UnsignedBigInteger from_base(u16 N, StringView str);
58-
String to_base(u16 N) const;
57+
[[nodiscard]] static UnsignedBigInteger from_base(u16 N, StringView str);
58+
[[nodiscard]] String to_base(u16 N) const;
5959

60-
u64 to_u64() const;
61-
double to_double() const;
60+
[[nodiscard]] u64 to_u64() const;
61+
[[nodiscard]] double to_double() const;
6262

63-
Vector<Word, STARTING_WORD_SIZE> const& words() const { return m_words; }
63+
[[nodiscard]] Vector<Word, STARTING_WORD_SIZE> const& words() const { return m_words; }
6464

6565
void set_to_0();
6666
void set_to(Word other);
@@ -73,38 +73,38 @@ class UnsignedBigInteger {
7373
m_cached_hash = 0;
7474
}
7575

76-
bool is_zero() const;
77-
bool is_odd() const { return m_words.size() && (m_words[0] & 1); }
78-
bool is_invalid() const { return m_is_invalid; }
76+
[[nodiscard]] bool is_zero() const;
77+
[[nodiscard]] bool is_odd() const { return m_words.size() && (m_words[0] & 1); }
78+
[[nodiscard]] bool is_invalid() const { return m_is_invalid; }
7979

80-
size_t length() const { return m_words.size(); }
80+
[[nodiscard]] size_t length() const { return m_words.size(); }
8181
// The "trimmed length" is the number of words after trimming leading zeroed words
82-
size_t trimmed_length() const;
82+
[[nodiscard]] size_t trimmed_length() const;
8383

8484
void clamp_to_trimmed_length();
8585
void resize_with_leading_zeros(size_t num_words);
8686

8787
size_t one_based_index_of_highest_set_bit() const;
8888

89-
UnsignedBigInteger plus(UnsignedBigInteger const& other) const;
90-
UnsignedBigInteger minus(UnsignedBigInteger const& other) const;
91-
UnsignedBigInteger bitwise_or(UnsignedBigInteger const& other) const;
92-
UnsignedBigInteger bitwise_and(UnsignedBigInteger const& other) const;
93-
UnsignedBigInteger bitwise_xor(UnsignedBigInteger const& other) const;
94-
UnsignedBigInteger bitwise_not_fill_to_one_based_index(size_t) const;
95-
UnsignedBigInteger shift_left(size_t num_bits) const;
96-
UnsignedBigInteger multiplied_by(UnsignedBigInteger const& other) const;
97-
UnsignedDivisionResult divided_by(UnsignedBigInteger const& divisor) const;
89+
[[nodiscard]] UnsignedBigInteger plus(UnsignedBigInteger const& other) const;
90+
[[nodiscard]] UnsignedBigInteger minus(UnsignedBigInteger const& other) const;
91+
[[nodiscard]] UnsignedBigInteger bitwise_or(UnsignedBigInteger const& other) const;
92+
[[nodiscard]] UnsignedBigInteger bitwise_and(UnsignedBigInteger const& other) const;
93+
[[nodiscard]] UnsignedBigInteger bitwise_xor(UnsignedBigInteger const& other) const;
94+
[[nodiscard]] UnsignedBigInteger bitwise_not_fill_to_one_based_index(size_t) const;
95+
[[nodiscard]] UnsignedBigInteger shift_left(size_t num_bits) const;
96+
[[nodiscard]] UnsignedBigInteger multiplied_by(UnsignedBigInteger const& other) const;
97+
[[nodiscard]] UnsignedDivisionResult divided_by(UnsignedBigInteger const& divisor) const;
9898

99-
u32 hash() const;
99+
[[nodiscard]] u32 hash() const;
100100

101101
void set_bit_inplace(size_t bit_index);
102102

103-
bool operator==(UnsignedBigInteger const& other) const;
104-
bool operator!=(UnsignedBigInteger const& other) const;
105-
bool operator<(UnsignedBigInteger const& other) const;
106-
bool operator>(UnsignedBigInteger const& other) const;
107-
bool operator>=(UnsignedBigInteger const& other) const;
103+
[[nodiscard]] bool operator==(UnsignedBigInteger const& other) const;
104+
[[nodiscard]] bool operator!=(UnsignedBigInteger const& other) const;
105+
[[nodiscard]] bool operator<(UnsignedBigInteger const& other) const;
106+
[[nodiscard]] bool operator>(UnsignedBigInteger const& other) const;
107+
[[nodiscard]] bool operator>=(UnsignedBigInteger const& other) const;
108108

109109
private:
110110
friend class UnsignedBigIntegerAlgorithms;

0 commit comments

Comments
 (0)