Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: apply cpp linting and formatting to ncrypto #55362

Merged
merged 4 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,8 @@ LINT_CPP_EXCLUDE += $(LINT_CPP_ADDON_DOC_FILES)
# These files were copied more or less verbatim from V8.
LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h

# deps/ncrypto is included in this list, as it lives in
# this repository, and therefore is linted.
RedYetiDev marked this conversation as resolved.
Show resolved Hide resolved
LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
benchmark/napi/*/*.cc \
src/*.c \
Expand All @@ -1438,6 +1440,8 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
tools/code_cache/*.h \
tools/snapshot/*.cc \
tools/snapshot/*.h \
deps/ncrypto/*.cc \
deps/ncrypto/*.h \
RedYetiDev marked this conversation as resolved.
Show resolved Hide resolved
RedYetiDev marked this conversation as resolved.
Show resolved Hide resolved
))

FORMAT_CPP_FILES ?=
Expand Down
35 changes: 21 additions & 14 deletions deps/ncrypto/dh-primes.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@
* ([email protected]). This product includes software written by Tim
* Hudson ([email protected]). */

#ifndef DEPS_NCRYPTO_DH_PRIMES_H_
#define DEPS_NCRYPTO_DH_PRIMES_H_

#include <openssl/dh.h>

#include <openssl/bn.h>
#include <openssl/err.h>
#include <openssl/mem.h>

extern "C" int bn_set_words(BIGNUM *bn, const BN_ULONG *words, size_t num);
extern "C" int bn_set_words(BIGNUM* bn, const BN_ULONG* words, size_t num);

// Backporting primes that may not be supported in earlier boringssl versions. Intentionally
// keeping the existing C-style formatting.
// Backporting primes that may not be supported in earlier boringssl versions.
// Intentionally keeping the existing C-style formatting.

#define OPENSSL_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))

Expand All @@ -71,25 +74,27 @@ extern "C" int bn_set_words(BIGNUM *bn, const BN_ULONG *words, size_t num);
#error "Must define either OPENSSL_32_BIT or OPENSSL_64_BIT"
#endif

static BIGNUM *get_params(BIGNUM *ret, const BN_ULONG *words, size_t num_words) {
BIGNUM *alloc = NULL;
if (ret == NULL) {
static BIGNUM* get_params(BIGNUM* ret,
const BN_ULONG* words,
size_t num_words) {
BIGNUM* alloc = nullptr;
if (ret == nullptr) {
alloc = BN_new();
if (alloc == NULL) {
return NULL;
if (alloc == nullptr) {
return nullptr;
}
ret = alloc;
}

if (!bn_set_words(ret, words, num_words)) {
BN_free(alloc);
return NULL;
return nullptr;
}

return ret;
}

BIGNUM *BN_get_rfc3526_prime_2048(BIGNUM *ret) {
BIGNUM* BN_get_rfc3526_prime_2048(BIGNUM* ret) {
static const BN_ULONG kWords[] = {
TOBN(0xffffffff, 0xffffffff), TOBN(0x15728e5a, 0x8aacaa68),
TOBN(0x15d22618, 0x98fa0510), TOBN(0x3995497c, 0xea956ae5),
Expand All @@ -111,7 +116,7 @@ BIGNUM *BN_get_rfc3526_prime_2048(BIGNUM *ret) {
return get_params(ret, kWords, OPENSSL_ARRAY_SIZE(kWords));
}

BIGNUM *BN_get_rfc3526_prime_3072(BIGNUM *ret) {
BIGNUM* BN_get_rfc3526_prime_3072(BIGNUM* ret) {
static const BN_ULONG kWords[] = {
TOBN(0xffffffff, 0xffffffff), TOBN(0x4b82d120, 0xa93ad2ca),
TOBN(0x43db5bfc, 0xe0fd108e), TOBN(0x08e24fa0, 0x74e5ab31),
Expand Down Expand Up @@ -141,7 +146,7 @@ BIGNUM *BN_get_rfc3526_prime_3072(BIGNUM *ret) {
return get_params(ret, kWords, OPENSSL_ARRAY_SIZE(kWords));
}

BIGNUM *BN_get_rfc3526_prime_4096(BIGNUM *ret) {
BIGNUM* BN_get_rfc3526_prime_4096(BIGNUM* ret) {
static const BN_ULONG kWords[] = {
TOBN(0xffffffff, 0xffffffff), TOBN(0x4df435c9, 0x34063199),
TOBN(0x86ffb7dc, 0x90a6c08f), TOBN(0x93b4ea98, 0x8d8fddc1),
Expand Down Expand Up @@ -179,7 +184,7 @@ BIGNUM *BN_get_rfc3526_prime_4096(BIGNUM *ret) {
return get_params(ret, kWords, OPENSSL_ARRAY_SIZE(kWords));
}

BIGNUM *BN_get_rfc3526_prime_6144(BIGNUM *ret) {
BIGNUM* BN_get_rfc3526_prime_6144(BIGNUM* ret) {
static const BN_ULONG kWords[] = {
TOBN(0xffffffff, 0xffffffff), TOBN(0xe694f91e, 0x6dcc4024),
TOBN(0x12bf2d5b, 0x0b7474d6), TOBN(0x043e8f66, 0x3f4860ee),
Expand Down Expand Up @@ -233,7 +238,7 @@ BIGNUM *BN_get_rfc3526_prime_6144(BIGNUM *ret) {
return get_params(ret, kWords, OPENSSL_ARRAY_SIZE(kWords));
}

BIGNUM *BN_get_rfc3526_prime_8192(BIGNUM *ret) {
BIGNUM* BN_get_rfc3526_prime_8192(BIGNUM* ret) {
static const BN_ULONG kWords[] = {
TOBN(0xffffffff, 0xffffffff), TOBN(0x60c980dd, 0x98edd3df),
TOBN(0xc81f56e8, 0x80b96e71), TOBN(0x9e3050e2, 0x765694df),
Expand Down Expand Up @@ -302,3 +307,5 @@ BIGNUM *BN_get_rfc3526_prime_8192(BIGNUM *ret) {
};
return get_params(ret, kWords, OPENSSL_ARRAY_SIZE(kWords));
}

#endif // DEPS_NCRYPTO_DH_PRIMES_H_
13 changes: 7 additions & 6 deletions deps/ncrypto/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ namespace ncrypto {

#ifndef OPENSSL_NO_ENGINE
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
: engine(engine_),
finish_on_exit(finish_on_exit_) {}
: engine(engine_), finish_on_exit(finish_on_exit_) {}

EnginePointer::EnginePointer(EnginePointer&& other) noexcept
: engine(other.engine),
finish_on_exit(other.finish_on_exit) {
: engine(other.engine), finish_on_exit(other.finish_on_exit) {
other.release();
}

EnginePointer::~EnginePointer() { reset(); }
EnginePointer::~EnginePointer() {
reset();
}

EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
if (this == &other) return *this;
Expand Down Expand Up @@ -75,7 +75,8 @@ bool EnginePointer::init(bool finish_on_exit) {

EVPKeyPointer EnginePointer::loadPrivateKey(const std::string_view key_name) {
if (engine == nullptr) return EVPKeyPointer();
return EVPKeyPointer(ENGINE_load_private_key(engine, key_name.data(), nullptr, nullptr));
return EVPKeyPointer(
ENGINE_load_private_key(engine, key_name.data(), nullptr, nullptr));
}

void EnginePointer::initEnginesOnce() {
Expand Down
Loading
Loading