Skip to content

Commit 99eaa44

Browse files
committed
Add BignumPointer::bigLength
1 parent c39be88 commit 99eaa44

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/ncrypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ class BignumPointer final {
526526
unsigned long getWord() const; // NOLINT(runtime/int)
527527

528528
size_t byteLength() const;
529+
size_t bitLength() const;
529530

530531
DataPointer toHex() const;
531532
DataPointer encode() const;

src/ncrypto.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,15 @@ void BignumPointer::reset(const unsigned char* data, size_t len) {
242242
BIGNUM* BignumPointer::release() { return bn_.release(); }
243243

244244
size_t BignumPointer::byteLength() const {
245-
if (bn_ == nullptr) return 0;
245+
if (!bn_) return 0;
246246
return BN_num_bytes(bn_.get());
247247
}
248248

249+
size_t BignumPointer::bitLength() const {
250+
if (!bn_) return 0;
251+
return BN_num_bits(bn_.get());
252+
}
253+
249254
DataPointer BignumPointer::encode() const {
250255
return EncodePadded(bn_.get(), byteLength());
251256
}

0 commit comments

Comments
 (0)