Skip to content

Commit b66b201

Browse files
committed
[core] clang-format almost all first-party code
Added a .clang-format file and auto-formatted almost all first-party code (all except `core/include/config.h` and the auto-generated file `core/src/checks/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.h`).
1 parent f4f4d86 commit b66b201

61 files changed

Lines changed: 880 additions & 653 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/.clang-format

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
2+
---
3+
# BasedOnStyle: Mozilla
4+
5+
Language: Cpp
6+
AccessModifierOffset: -2
7+
AlignAfterOpenBracket: AlwaysBreak
8+
AlignArrayOfStructures: None
9+
AlignConsecutiveAssignments:
10+
Enabled: false
11+
AcrossEmptyLines: false
12+
AcrossComments: false
13+
AlignCompound: false
14+
PadOperators: true
15+
AlignConsecutiveBitFields:
16+
Enabled: false
17+
AcrossEmptyLines: false
18+
AcrossComments: false
19+
AlignCompound: false
20+
PadOperators: false
21+
AlignConsecutiveDeclarations:
22+
Enabled: false
23+
AcrossEmptyLines: false
24+
AcrossComments: false
25+
AlignCompound: false
26+
PadOperators: false
27+
AlignConsecutiveMacros:
28+
Enabled: false
29+
AcrossEmptyLines: false
30+
AcrossComments: false
31+
AlignCompound: false
32+
PadOperators: false
33+
AlignEscapedNewlines: Left
34+
AlignOperands: Align
35+
AlignTrailingComments:
36+
Kind: Always
37+
OverEmptyLines: 0
38+
AllowAllArgumentsOnNextLine: true
39+
AllowAllParametersOfDeclarationOnNextLine: false
40+
AllowShortBlocksOnASingleLine: Never
41+
AllowShortCaseLabelsOnASingleLine: false
42+
AllowShortEnumsOnASingleLine: true
43+
AllowShortFunctionsOnASingleLine: Inline
44+
AllowShortIfStatementsOnASingleLine: Never
45+
AllowShortLambdasOnASingleLine: All
46+
AllowShortLoopsOnASingleLine: false
47+
AlwaysBreakAfterDefinitionReturnType: None
48+
AlwaysBreakAfterReturnType: None
49+
AlwaysBreakBeforeMultilineStrings: true
50+
AlwaysBreakTemplateDeclarations: Yes
51+
AttributeMacros:
52+
- __capability
53+
BinPackArguments: false
54+
BinPackParameters: false
55+
BitFieldColonSpacing: Both
56+
BraceWrapping:
57+
AfterCaseLabel: false
58+
AfterClass: false
59+
AfterControlStatement: Never
60+
AfterEnum: false
61+
AfterExternBlock: false
62+
AfterFunction: false
63+
AfterNamespace: false
64+
AfterObjCDeclaration: false
65+
AfterStruct: false
66+
AfterUnion: false
67+
BeforeCatch: false
68+
BeforeElse: false
69+
BeforeLambdaBody: false
70+
BeforeWhile: false
71+
IndentBraces: false
72+
SplitEmptyFunction: false
73+
SplitEmptyRecord: false
74+
SplitEmptyNamespace: false
75+
BreakAfterAttributes: Never
76+
BreakAfterJavaFieldAnnotations: false
77+
BreakArrays: false
78+
BreakBeforeBinaryOperators: None
79+
BreakBeforeConceptDeclarations: Always
80+
BreakBeforeBraces: Custom
81+
BreakBeforeInlineASMColon: OnlyMultiline
82+
BreakBeforeTernaryOperators: true
83+
BreakConstructorInitializers: AfterColon
84+
BreakInheritanceList: AfterColon
85+
BreakStringLiterals: true
86+
ColumnLimit: 120
87+
CommentPragmas: '^ IWYU pragma:'
88+
CompactNamespaces: false
89+
ConstructorInitializerIndentWidth: 4
90+
ContinuationIndentWidth: 4
91+
Cpp11BracedListStyle: false
92+
DerivePointerAlignment: false
93+
DisableFormat: false
94+
EmptyLineAfterAccessModifier: Never
95+
EmptyLineBeforeAccessModifier: LogicalBlock
96+
ExperimentalAutoDetectBinPacking: false
97+
FixNamespaceComments: true
98+
ForEachMacros:
99+
- foreach
100+
- Q_FOREACH
101+
- BOOST_FOREACH
102+
IfMacros:
103+
- KJ_IF_MAYBE
104+
IncludeBlocks: Regroup
105+
IncludeCategories:
106+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
107+
Priority: 2
108+
SortPriority: 0
109+
CaseSensitive: false
110+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
111+
Priority: 3
112+
SortPriority: 0
113+
CaseSensitive: false
114+
- Regex: '.*'
115+
Priority: 1
116+
SortPriority: 0
117+
CaseSensitive: false
118+
IncludeIsMainRegex: '(Test)?$'
119+
IncludeIsMainSourceRegex: ''
120+
IndentAccessModifiers: false
121+
IndentCaseBlocks: false
122+
IndentCaseLabels: false
123+
IndentExternBlock: AfterExternBlock
124+
IndentGotoLabels: true
125+
IndentPPDirectives: BeforeHash
126+
IndentRequiresClause: true
127+
IndentWidth: 2
128+
IndentWrappedFunctionNames: false
129+
InsertBraces: true
130+
InsertNewlineAtEOF: true
131+
InsertTrailingCommas: None
132+
IntegerLiteralSeparator:
133+
Binary: 0
134+
BinaryMinDigits: 0
135+
Decimal: 0
136+
DecimalMinDigits: 0
137+
Hex: 0
138+
HexMinDigits: 0
139+
JavaScriptQuotes: Leave
140+
JavaScriptWrapImports: true
141+
KeepEmptyLinesAtTheStartOfBlocks: false
142+
LambdaBodyIndentation: Signature
143+
LineEnding: DeriveLF
144+
MacroBlockBegin: ''
145+
MacroBlockEnd: ''
146+
MaxEmptyLinesToKeep: 1
147+
NamespaceIndentation: None
148+
ObjCBinPackProtocolList: Auto
149+
ObjCBlockIndentWidth: 2
150+
ObjCBreakBeforeNestedBlockParam: true
151+
ObjCSpaceAfterProperty: true
152+
ObjCSpaceBeforeProtocolList: false
153+
PackConstructorInitializers: CurrentLine
154+
PenaltyBreakAssignment: 2
155+
PenaltyBreakBeforeFirstCallParameter: 19
156+
PenaltyBreakComment: 300
157+
PenaltyBreakFirstLessLess: 120
158+
PenaltyBreakOpenParenthesis: 0
159+
PenaltyBreakString: 1000
160+
PenaltyBreakTemplateDeclaration: 10
161+
PenaltyExcessCharacter: 1000000
162+
PenaltyIndentedWhitespace: 0
163+
PenaltyReturnTypeOnItsOwnLine: 200
164+
PointerAlignment: Left
165+
PPIndentWidth: -1
166+
QualifierAlignment: Leave
167+
ReferenceAlignment: Pointer
168+
ReflowComments: true
169+
RemoveBracesLLVM: false
170+
RemoveSemicolon: true
171+
RequiresClausePosition: OwnLine
172+
RequiresExpressionIndentation: OuterScope
173+
SeparateDefinitionBlocks: Always
174+
ShortNamespaceLines: 1
175+
SortIncludes: CaseSensitive
176+
SortJavaStaticImport: Before
177+
SortUsingDeclarations: LexicographicNumeric
178+
SpaceAfterCStyleCast: true
179+
SpaceAfterLogicalNot: false
180+
SpaceAfterTemplateKeyword: false
181+
SpaceAroundPointerQualifiers: Default
182+
SpaceBeforeAssignmentOperators: true
183+
SpaceBeforeCaseColon: false
184+
SpaceBeforeCpp11BracedList: false
185+
SpaceBeforeCtorInitializerColon: true
186+
SpaceBeforeInheritanceColon: true
187+
SpaceBeforeParens: Custom
188+
SpaceBeforeParensOptions:
189+
AfterControlStatements: true
190+
AfterForeachMacros: true
191+
AfterFunctionDefinitionName: false
192+
AfterFunctionDeclarationName: false
193+
AfterIfMacros: true
194+
AfterOverloadedOperator: false
195+
AfterRequiresInClause: false
196+
AfterRequiresInExpression: false
197+
BeforeNonEmptyParentheses: false
198+
SpaceBeforeRangeBasedForLoopColon: true
199+
SpaceBeforeSquareBrackets: false
200+
SpaceInEmptyBlock: false
201+
SpaceInEmptyParentheses: false
202+
SpacesBeforeTrailingComments: 1
203+
SpacesInAngles: Never
204+
SpacesInConditionalStatement: false
205+
SpacesInContainerLiterals: false
206+
SpacesInCStyleCastParentheses: false
207+
SpacesInLineCommentPrefix:
208+
Minimum: 1
209+
Maximum: -1
210+
SpacesInParentheses: false
211+
SpacesInSquareBrackets: false
212+
Standard: Latest
213+
StatementAttributeLikeMacros:
214+
- Q_EMIT
215+
StatementMacros:
216+
- Q_UNUSED
217+
- QT_REQUIRE_VERSION
218+
TabWidth: 8
219+
UseTab: Never
220+
WhitespaceSensitiveMacros:
221+
- BOOST_PP_STRINGIZE
222+
- CF_SWIFT_NAME
223+
- NS_SWIFT_NAME
224+
- PP_STRINGIZE
225+
- STRINGIZE

core/external-crypto/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

core/include/aes_gcm_dev.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@
1919
// reserved for an invalid key object in the nCipher target. We would like to
2020
// simulate this behavior in the dev target, and therefore avoid value 0 for
2121
// M_KeyID enum below.
22-
typedef enum {master_seed_encryption_key = 1,
23-
pub_key_encryption_key = 2} M_KeyID;
22+
typedef enum { master_seed_encryption_key = 1, pub_key_encryption_key = 2 } M_KeyID;
2423

2524
// Key encryption key declaration, for AES-128-GCM
2625
// KEK[0], i.e., KEK[master_seed_encryption_key - 1], is master seed encryption key
2726
// KEK[1], i.e., KEK[pub_key_encryption_key], is public key encryption key
2827
extern uint8_t KEK[2][16];
2928

30-
Result aes_gcm_encrypt(M_KeyID keyId, uint8_t *plaintext, size_t plaintext_len,
31-
uint8_t *ciphertext, size_t ciphertext_len,
32-
size_t *bytes_written);
33-
Result aes_gcm_decrypt(M_KeyID keyId, const uint8_t *ciphertext,
34-
size_t ciphertext_len, uint8_t *plaintext,
35-
size_t plaintext_len, size_t *bytes_written);
29+
Result aes_gcm_encrypt(
30+
M_KeyID keyId,
31+
uint8_t* plaintext,
32+
size_t plaintext_len,
33+
uint8_t* ciphertext,
34+
size_t ciphertext_len,
35+
size_t* bytes_written);
36+
Result aes_gcm_decrypt(
37+
M_KeyID keyId,
38+
const uint8_t* ciphertext,
39+
size_t ciphertext_len,
40+
uint8_t* plaintext,
41+
size_t plaintext_len,
42+
size_t* bytes_written);

core/include/aes_gcm_ncipher.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
// aes_gcm_ncipher:$(echo -n "aes_gcm_ncipher" | sha256sum | cut -c1-16)
1414
#define MAGIC "aes_gcm_ncipher:ffb944993c73a1d3"
1515

16-
Result aes_gcm_encrypt(M_KeyID keyId, uint8_t *plaintext, size_t plaintext_len,
17-
uint8_t *ciphertext, size_t ciphertext_len,
18-
size_t *bytes_written);
19-
Result aes_gcm_decrypt(M_KeyID keyId, const uint8_t *ciphertext,
20-
size_t ciphertext_len, uint8_t *plaintext,
21-
size_t plaintext_len, size_t *bytes_written);
16+
Result aes_gcm_encrypt(
17+
M_KeyID keyId,
18+
uint8_t* plaintext,
19+
size_t plaintext_len,
20+
uint8_t* ciphertext,
21+
size_t ciphertext_len,
22+
size_t* bytes_written);
23+
Result aes_gcm_decrypt(
24+
M_KeyID keyId,
25+
const uint8_t* ciphertext,
26+
size_t ciphertext_len,
27+
uint8_t* plaintext,
28+
size_t plaintext_len,
29+
size_t* bytes_written);

core/include/checks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ int verify_rpc_oversized_message_rejected(void);
6363
ERROR("got: %s", value); \
6464
return -1; \
6565
} \
66-
} while(0)
66+
} while (0)

core/include/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// clang-format off
2+
// (to avoid conflicting with production patch files)
3+
14
#pragma once
25

36
// maximum size for xpub. TODO: we can make this 112 bytes, based on:
@@ -119,3 +122,5 @@
119122
#define MASTER_SEED_SIZE 64
120123

121124
#define COMPRESSED_PUBKEY_SIZE 33
125+
126+
// clang-format on

core/include/hash.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
#include <stddef.h>
55
#include <stdint.h>
66

7-
void hash_uint8(Hasher *hasher, uint8_t value);
8-
void hash_uint16(Hasher *hasher, uint16_t value);
9-
void hash_uint32(Hasher *hasher, uint32_t value);
10-
void hash_uint64(Hasher *hasher, uint64_t value);
7+
void hash_uint8(Hasher* hasher, uint8_t value);
8+
void hash_uint16(Hasher* hasher, uint16_t value);
9+
void hash_uint32(Hasher* hasher, uint32_t value);
10+
void hash_uint64(Hasher* hasher, uint64_t value);
1111
// hashes are serialized in "normal" order
12-
void hash_bytes(Hasher *hasher, const uint8_t *data, size_t len);
12+
void hash_bytes(Hasher* hasher, const uint8_t* data, size_t len);
1313
// addresses are serialized in reverse order
14-
void hash_rev_bytes(Hasher *hasher, const uint8_t *data, size_t len);
14+
void hash_rev_bytes(Hasher* hasher, const uint8_t* data, size_t len);
1515
// scripts are serialized with a length prefix
16-
void hash_var_bytes(Hasher *hasher, const uint8_t *data, size_t len);
16+
void hash_var_bytes(Hasher* hasher, const uint8_t* data, size_t len);

core/include/init_wallet.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55

66
#include <stdint.h>
77

8-
Result mix_entropy(uint8_t wallet_entropy[static MASTER_SEED_SIZE],
9-
const InternalCommandRequest* const in);
8+
Result mix_entropy(uint8_t wallet_entropy[static MASTER_SEED_SIZE], const InternalCommandRequest* const in);

0 commit comments

Comments
 (0)