Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions deps/ncrypto/ncrypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,16 @@ bool BignumPointer::setWord(unsigned long w) { // NOLINT(runtime/int)
return BN_set_word(bn_.get(), w) == 1;
}

unsigned long BignumPointer::GetWord(const BIGNUM* bn) { // NOLINT(runtime/int)
return BN_get_word(bn);
std::optional<unsigned long> BignumPointer::GetWord( // NOLINT(runtime/int)
const BIGNUM* bn) {
BN_ULONG ret = BN_get_word(bn);
if (ret == static_cast<BN_ULONG>(-1)) return std::nullopt;
return ret;
}

unsigned long BignumPointer::getWord() const { // NOLINT(runtime/int)
if (!bn_) return 0;
std::optional<unsigned long> BignumPointer::getWord() // NOLINT(runtime/int)
const {
if (!bn_) return std::nullopt;
return GetWord(bn_.get());
}

Expand Down
5 changes: 3 additions & 2 deletions deps/ncrypto/ncrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ class BignumPointer final {
bool isOne() const;

bool setWord(unsigned long w); // NOLINT(runtime/int)
unsigned long getWord() const; // NOLINT(runtime/int)
std::optional<unsigned long> getWord() const; // NOLINT(runtime/int)

size_t byteLength() const;

Expand Down Expand Up @@ -782,7 +782,8 @@ class BignumPointer final {
size_t size);
static int GetBitCount(const BIGNUM* bn);
static int GetByteCount(const BIGNUM* bn);
static unsigned long GetWord(const BIGNUM* bn); // NOLINT(runtime/int)
static std::optional<unsigned long> GetWord( // NOLINT(runtime/int)
const BIGNUM* bn);
static const BIGNUM* One();

BignumPointer clone();
Expand Down
4 changes: 3 additions & 1 deletion src/crypto/crypto_aes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ WebCryptoCipherStatus AES_CTR_Cipher(Environment* env,
return status;
}

BN_ULONG input_size_part1 = remaining_until_reset.getWord() * kAesBlockSize;
std::optional<BN_ULONG> remaining_blocks = remaining_until_reset.getWord();
CHECK(remaining_blocks.has_value());
BN_ULONG input_size_part1 = remaining_blocks.value() * kAesBlockSize;

// Encrypt the first part...
auto status =
Expand Down
6 changes: 4 additions & 2 deletions src/crypto/crypto_x509.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using v8::Local;
using v8::LocalVector;
using v8::MaybeLocal;
using v8::NewStringType;
using v8::Null;
using v8::Object;
using v8::String;
using v8::Uint32;
Expand Down Expand Up @@ -688,11 +689,12 @@ MaybeLocal<Value> GetModulusString(Environment* env, const BIGNUM* n) {
}

MaybeLocal<Value> GetExponentString(Environment* env, const BIGNUM* e) {
uint64_t exponent_word = static_cast<uint64_t>(BignumPointer::GetWord(e));
auto exponent_word = BignumPointer::GetWord(e);
if (!exponent_word) return Null(env->isolate());
auto bio = BIOPointer::NewMem();
if (!bio) [[unlikely]]
return {};
BIO_printf(bio.get(), "0x%" PRIx64, exponent_word);
BIO_printf(bio.get(), "0x%" PRIx64, static_cast<uint64_t>(*exponent_word));
return ToV8Value(env->context(), bio);
}

Expand Down
Loading