Skip to content

Commit 5e8f4dd

Browse files
committed
Use same clang-format rules as node, reformat code
1 parent 134ac40 commit 5e8f4dd

File tree

5 files changed

+651
-241
lines changed

5 files changed

+651
-241
lines changed

.clang-format

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,111 @@
1-
BasedOnStyle: Google
2-
SortIncludes: Never
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: Google
4+
AccessModifierOffset: -1
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: Right
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllParametersOfDeclarationOnNextLine: true
12+
AllowShortBlocksOnASingleLine: false
13+
AllowShortCaseLabelsOnASingleLine: false
14+
AllowShortFunctionsOnASingleLine: Inline
15+
AllowShortIfStatementsOnASingleLine: true
16+
AllowShortLoopsOnASingleLine: true
17+
AlwaysBreakAfterDefinitionReturnType: None
18+
AlwaysBreakAfterReturnType: None
19+
AlwaysBreakBeforeMultilineStrings: false
20+
AlwaysBreakTemplateDeclarations: true
21+
BinPackArguments: false
22+
BinPackParameters: false
23+
BraceWrapping:
24+
AfterClass: false
25+
AfterControlStatement: false
26+
AfterEnum: false
27+
AfterFunction: false
28+
AfterNamespace: false
29+
AfterObjCDeclaration: false
30+
AfterStruct: false
31+
AfterUnion: false
32+
AfterExternBlock: false
33+
BeforeCatch: false
34+
BeforeElse: false
35+
IndentBraces: false
36+
SplitEmptyFunction: true
37+
SplitEmptyRecord: true
38+
SplitEmptyNamespace: true
39+
BreakBeforeBinaryOperators: None
40+
BreakBeforeBraces: Attach
41+
BreakBeforeInheritanceComma: false
42+
BreakBeforeTernaryOperators: true
43+
BreakConstructorInitializersBeforeComma: false
44+
BreakConstructorInitializers: BeforeColon
45+
BreakAfterJavaFieldAnnotations: false
46+
BreakStringLiterals: true
47+
ColumnLimit: 80
48+
CommentPragmas: '^ IWYU pragma:'
49+
CompactNamespaces: false
50+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
51+
ConstructorInitializerIndentWidth: 4
52+
ContinuationIndentWidth: 4
53+
Cpp11BracedListStyle: true
54+
DerivePointerAlignment: false
55+
DisableFormat: false
56+
ExperimentalAutoDetectBinPacking: false
57+
FixNamespaceComments: true
58+
ForEachMacros:
59+
- foreach
60+
- Q_FOREACH
61+
- BOOST_FOREACH
62+
IncludeBlocks: Preserve
63+
IncludeCategories:
64+
- Regex: '^<ext/.*\.h>'
65+
Priority: 2
66+
- Regex: '^<.*\.h>'
67+
Priority: 1
68+
- Regex: '^<.*'
69+
Priority: 2
70+
- Regex: '.*'
71+
Priority: 3
72+
IncludeIsMainRegex: '([-_](test|unittest))?$'
73+
IndentCaseLabels: true
74+
IndentPPDirectives: None
75+
IndentWidth: 2
76+
IndentWrappedFunctionNames: false
77+
JavaScriptQuotes: Leave
78+
JavaScriptWrapImports: true
79+
KeepEmptyLinesAtTheStartOfBlocks: false
80+
MacroBlockBegin: ''
81+
MacroBlockEnd: ''
82+
MaxEmptyLinesToKeep: 1
83+
NamespaceIndentation: None
84+
ObjCBlockIndentWidth: 2
85+
ObjCSpaceAfterProperty: false
86+
ObjCSpaceBeforeProtocolList: false
87+
PenaltyBreakAssignment: 2
88+
PenaltyBreakBeforeFirstCallParameter: 1
89+
PenaltyBreakComment: 300
90+
PenaltyBreakFirstLessLess: 120
91+
PenaltyBreakString: 1000
92+
PenaltyExcessCharacter: 1000000
93+
PenaltyReturnTypeOnItsOwnLine: 200
94+
PointerAlignment: Left
95+
ReflowComments: true
96+
SortIncludes: true
97+
SortUsingDeclarations: true
98+
SpaceAfterCStyleCast: false
99+
SpaceAfterTemplateKeyword: true
100+
SpaceBeforeAssignmentOperators: true
101+
SpaceBeforeParens: ControlStatements
102+
SpaceInEmptyParentheses: false
103+
SpacesBeforeTrailingComments: 2
104+
SpacesInAngles: false
105+
SpacesInContainerLiterals: true
106+
SpacesInCStyleCastParentheses: false
107+
SpacesInParentheses: false
108+
SpacesInSquareBrackets: false
109+
Standard: Auto
110+
TabWidth: 8
111+
UseTab: Never

include/ncrypto.h

Lines changed: 76 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ namespace ncrypto {
6161

6262
#if NCRYPTO_DEVELOPMENT_CHECKS
6363
#define NCRYPTO_STR(x) #x
64-
#define NCRYPTO_REQUIRE(EXPR) \
65-
{ \
64+
#define NCRYPTO_REQUIRE(EXPR) \
65+
{ \
6666
if (!(EXPR) { abort(); }) }
6767

68-
#define NCRYPTO_FAIL(MESSAGE) \
69-
do { \
70-
std::cerr << "FAIL: " << (MESSAGE) << std::endl; \
71-
abort(); \
68+
#define NCRYPTO_FAIL(MESSAGE) \
69+
do { \
70+
std::cerr << "FAIL: " << (MESSAGE) << std::endl; \
71+
abort(); \
7272
} while (0);
7373
#define NCRYPTO_ASSERT_EQUAL(LHS, RHS, MESSAGE) \
7474
do { \
@@ -77,31 +77,31 @@ namespace ncrypto {
7777
NCRYPTO_FAIL(MESSAGE); \
7878
} \
7979
} while (0);
80-
#define NCRYPTO_ASSERT_TRUE(COND) \
81-
do { \
82-
if (!(COND)) { \
83-
std::cerr << "Assert at line " << __LINE__ << " of file " << __FILE__ \
84-
<< std::endl; \
85-
NCRYPTO_FAIL(NCRYPTO_STR(COND)); \
86-
} \
80+
#define NCRYPTO_ASSERT_TRUE(COND) \
81+
do { \
82+
if (!(COND)) { \
83+
std::cerr << "Assert at line " << __LINE__ << " of file " << __FILE__ \
84+
<< std::endl; \
85+
NCRYPTO_FAIL(NCRYPTO_STR(COND)); \
86+
} \
8787
} while (0);
8888
#else
8989
#define NCRYPTO_FAIL(MESSAGE)
9090
#define NCRYPTO_ASSERT_EQUAL(LHS, RHS, MESSAGE)
9191
#define NCRYPTO_ASSERT_TRUE(COND)
9292
#endif
9393

94-
#define NCRYPTO_DISALLOW_COPY(Name) \
95-
Name(const Name&) = delete; \
94+
#define NCRYPTO_DISALLOW_COPY(Name) \
95+
Name(const Name&) = delete; \
9696
Name& operator=(const Name&) = delete;
97-
#define NCRYPTO_DISALLOW_MOVE(Name) \
98-
Name(Name&&) = delete; \
97+
#define NCRYPTO_DISALLOW_MOVE(Name) \
98+
Name(Name&&) = delete; \
9999
Name& operator=(Name&&) = delete;
100-
#define NCRYPTO_DISALLOW_COPY_AND_MOVE(Name) \
101-
NCRYPTO_DISALLOW_COPY(Name) \
100+
#define NCRYPTO_DISALLOW_COPY_AND_MOVE(Name) \
101+
NCRYPTO_DISALLOW_COPY(Name) \
102102
NCRYPTO_DISALLOW_MOVE(Name)
103-
#define NCRYPTO_DISALLOW_NEW_DELETE() \
104-
void* operator new(size_t) = delete; \
103+
#define NCRYPTO_DISALLOW_NEW_DELETE() \
104+
void* operator new(size_t) = delete; \
105105
void operator delete(void*) = delete;
106106

107107
[[noreturn]] inline void unreachable() {
@@ -299,7 +299,8 @@ class Cipher final {
299299
const CipherParams& params,
300300
const Buffer<const void> in);
301301

302-
static DataPointer sign(const EVPKeyPointer& key, const CipherParams& params,
302+
static DataPointer sign(const EVPKeyPointer& key,
303+
const CipherParams& params,
303304
const Buffer<const void> in);
304305

305306
static DataPointer recover(const EVPKeyPointer& key,
@@ -392,7 +393,8 @@ class BignumPointer final {
392393

393394
static DataPointer Encode(const BIGNUM* bn);
394395
static DataPointer EncodePadded(const BIGNUM* bn, size_t size);
395-
static size_t EncodePaddedInto(const BIGNUM* bn, unsigned char* out,
396+
static size_t EncodePaddedInto(const BIGNUM* bn,
397+
unsigned char* out,
396398
size_t size);
397399
static int GetBitCount(const BIGNUM* bn);
398400
static int GetByteCount(const BIGNUM* bn);
@@ -439,8 +441,11 @@ class Rsa final {
439441
const std::optional<PssParams> getPssParams() const;
440442

441443
bool setPublicKey(BignumPointer&& n, BignumPointer&& e);
442-
bool setPrivateKey(BignumPointer&& d, BignumPointer&& q, BignumPointer&& p,
443-
BignumPointer&& dp, BignumPointer&& dq,
444+
bool setPrivateKey(BignumPointer&& d,
445+
BignumPointer&& q,
446+
BignumPointer&& p,
447+
BignumPointer&& dp,
448+
BignumPointer&& dq,
444449
BignumPointer&& qi);
445450

446451
using CipherParams = Cipher::CipherParams;
@@ -613,16 +618,19 @@ class CipherCtxPointer final {
613618
bool setAeadTag(const Buffer<const char>& tag);
614619
bool setAeadTagLength(size_t length);
615620
bool setPadding(bool padding);
616-
bool init(const Cipher& cipher, bool encrypt,
621+
bool init(const Cipher& cipher,
622+
bool encrypt,
617623
const unsigned char* key = nullptr,
618624
const unsigned char* iv = nullptr);
619625

620626
int getBlockSize() const;
621627
int getMode() const;
622628
int getNid() const;
623629

624-
bool update(const Buffer<const unsigned char>& in, unsigned char* out,
625-
int* out_len, bool finalize = false);
630+
bool update(const Buffer<const unsigned char>& in,
631+
unsigned char* out,
632+
int* out_len,
633+
bool finalize = false);
626634
bool getAeadTag(size_t len, unsigned char* out);
627635

628636
private:
@@ -678,7 +686,8 @@ class EVPKeyCtxPointer final {
678686

679687
static constexpr int kDefaultRsaExponent = 0x10001;
680688

681-
static bool setRsaPadding(EVP_PKEY_CTX* ctx, int padding,
689+
static bool setRsaPadding(EVP_PKEY_CTX* ctx,
690+
int padding,
682691
std::optional<int> salt_len = std::nullopt);
683692

684693
EVPKeyPointer paramgen() const;
@@ -731,7 +740,8 @@ class EVPKeyPointer final {
731740
PKFormatType format = PKFormatType::DER;
732741
PKEncodingType type = PKEncodingType::PKCS8;
733742
AsymmetricKeyEncodingConfig() = default;
734-
AsymmetricKeyEncodingConfig(bool output_key_object, PKFormatType format,
743+
AsymmetricKeyEncodingConfig(bool output_key_object,
744+
PKFormatType format,
735745
PKEncodingType type);
736746
AsymmetricKeyEncodingConfig(const AsymmetricKeyEncodingConfig&) = default;
737747
AsymmetricKeyEncodingConfig& operator=(const AsymmetricKeyEncodingConfig&) =
@@ -743,7 +753,8 @@ class EVPKeyPointer final {
743753
const EVP_CIPHER* cipher = nullptr;
744754
std::optional<DataPointer> passphrase = std::nullopt;
745755
PrivateKeyEncodingConfig() = default;
746-
PrivateKeyEncodingConfig(bool output_key_object, PKFormatType format,
756+
PrivateKeyEncodingConfig(bool output_key_object,
757+
PKFormatType format,
747758
PKEncodingType type)
748759
: AsymmetricKeyEncodingConfig(output_key_object, format, type) {}
749760
PrivateKeyEncodingConfig(const PrivateKeyEncodingConfig&);
@@ -1072,7 +1083,8 @@ class X509View final {
10721083
INVALID_NAME,
10731084
OPERATION_FAILED,
10741085
};
1075-
CheckMatch checkHost(const std::string_view host, int flags,
1086+
CheckMatch checkHost(const std::string_view host,
1087+
int flags,
10761088
DataPointer* peerName = nullptr) const;
10771089
CheckMatch checkEmail(const std::string_view email, int flags) const;
10781090
CheckMatch checkIp(const std::string_view ip, int flags) const;
@@ -1404,35 +1416,53 @@ const EVP_CIPHER* getCipherByName(const std::string_view name);
14041416
// hash size for the given digest algorithm.
14051417
bool checkHkdfLength(const EVP_MD* md, size_t length);
14061418

1407-
bool extractP1363(const Buffer<const unsigned char>& buf, unsigned char* dest,
1419+
bool extractP1363(const Buffer<const unsigned char>& buf,
1420+
unsigned char* dest,
14081421
size_t n);
14091422

1410-
bool hkdfInfo(const EVP_MD* md, const Buffer<const unsigned char>& key,
1423+
bool hkdfInfo(const EVP_MD* md,
1424+
const Buffer<const unsigned char>& key,
14111425
const Buffer<const unsigned char>& info,
1412-
const Buffer<const unsigned char>& salt, size_t length,
1426+
const Buffer<const unsigned char>& salt,
1427+
size_t length,
14131428
Buffer<unsigned char>* out);
14141429

1415-
DataPointer hkdf(const EVP_MD* md, const Buffer<const unsigned char>& key,
1430+
DataPointer hkdf(const EVP_MD* md,
1431+
const Buffer<const unsigned char>& key,
14161432
const Buffer<const unsigned char>& info,
1417-
const Buffer<const unsigned char>& salt, size_t length);
1433+
const Buffer<const unsigned char>& salt,
1434+
size_t length);
14181435

14191436
bool checkScryptParams(uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem);
14201437

14211438
bool scryptInto(const Buffer<const char>& pass,
1422-
const Buffer<const unsigned char>& salt, uint64_t N, uint64_t r,
1423-
uint64_t p, uint64_t maxmem, size_t length,
1439+
const Buffer<const unsigned char>& salt,
1440+
uint64_t N,
1441+
uint64_t r,
1442+
uint64_t p,
1443+
uint64_t maxmem,
1444+
size_t length,
14241445
Buffer<unsigned char>* out);
14251446

14261447
DataPointer scrypt(const Buffer<const char>& pass,
1427-
const Buffer<const unsigned char>& salt, uint64_t N,
1428-
uint64_t r, uint64_t p, uint64_t maxmem, size_t length);
1448+
const Buffer<const unsigned char>& salt,
1449+
uint64_t N,
1450+
uint64_t r,
1451+
uint64_t p,
1452+
uint64_t maxmem,
1453+
size_t length);
14291454

1430-
bool pbkdf2Into(const EVP_MD* md, const Buffer<const char>& pass,
1431-
const Buffer<const unsigned char>& salt, uint32_t iterations,
1432-
size_t length, Buffer<unsigned char>* out);
1455+
bool pbkdf2Into(const EVP_MD* md,
1456+
const Buffer<const char>& pass,
1457+
const Buffer<const unsigned char>& salt,
1458+
uint32_t iterations,
1459+
size_t length,
1460+
Buffer<unsigned char>* out);
14331461

1434-
DataPointer pbkdf2(const EVP_MD* md, const Buffer<const char>& pass,
1435-
const Buffer<const unsigned char>& salt, uint32_t iterations,
1462+
DataPointer pbkdf2(const EVP_MD* md,
1463+
const Buffer<const char>& pass,
1464+
const Buffer<const unsigned char>& salt,
1465+
uint32_t iterations,
14361466
size_t length);
14371467

14381468
// ============================================================================

src/engine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ EnginePointer::EnginePointer(EnginePointer&& other) noexcept
1414
other.release();
1515
}
1616

17-
EnginePointer::~EnginePointer() { reset(); }
17+
EnginePointer::~EnginePointer() {
18+
reset();
19+
}
1820

1921
EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2022
if (this == &other) return *this;

0 commit comments

Comments
 (0)