Skip to content

Commit

Permalink
style: Reformatting with clang-format (aws#1627)
Browse files Browse the repository at this point in the history
* feature: Reformatting with clang-format
* Note: full codebase reformat in future PR
  • Loading branch information
dougch authored May 14, 2020
1 parent 6161a53 commit 342872f
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 2 deletions.
156 changes: 156 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom #This unlocks BraceWrapping settings
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ clang-format pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: false
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: true
SpacesInParentheses: false
SpacesInSquareBrackets: true
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ fuzz_dependencies/*
.travis/.libs/*
.vscode/
test-deps/*
.idea/*
27 changes: 27 additions & 0 deletions codebuild/bin/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

set -e
CLANG_NINE=$(which clang-format-9)
CLANG_VER=${CLANG_NINE:-clang-format}
for i in $(find . -not -path "./test-deps/*" -name '*.h' -or -name '*.c' -or -name '*.cpp'); do
$CLANG_VER --verbose -i "$i" ;
done

if [[ `git status --porcelain` ]]; then
echo "clang-format updated files, throwing an error"
exit 255
else
echo "No files touched"
fi
4 changes: 3 additions & 1 deletion error/s2n_errno.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static const char *no_such_error = "Internal s2n error";
* Define error entries with descriptions in this macro once
* to generate code in next 2 following functions.
*/
/* clang-format off */
#define ERR_ENTRIES(ERR_ENTRY) \
ERR_ENTRY(S2N_ERR_OK, "no error") \
ERR_ENTRY(S2N_ERR_IO, "underlying I/O operation failed, check system errno") \
Expand Down Expand Up @@ -219,7 +220,8 @@ static const char *no_such_error = "Internal s2n error";
ERR_ENTRY(S2N_ERR_MISSING_EXTENSION, "Mandatory extension not received") \
ERR_ENTRY(S2N_ERR_INVALID_SECURITY_POLICY, "Invalid security policy") \
ERR_ENTRY(S2N_ERR_INVALID_KEM_PREFERENCES, "Invalid kem preferences version") \


/* clang-format on */
#define ERR_STR_CASE(ERR, str) case ERR: return str;
#define ERR_NAME_CASE(ERR, str) case ERR: return #ERR;

Expand Down
3 changes: 3 additions & 0 deletions error/s2n_errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define S2N_ERR_T_INTERNAL_START (S2N_ERR_T_INTERNAL << S2N_ERR_NUM_VALUE_BITS)
#define S2N_ERR_T_USAGE_START (S2N_ERR_T_USAGE << S2N_ERR_NUM_VALUE_BITS)

/* clang-format off */
/* Order of values in this enum is important. New error values should be placed at the end of their respective category.
* For example, a new TLS protocol related error belongs in the S2N_ERR_T_PROTO category. It should be placed
* immediately before S2N_ERR_T_INTERNAL_START(the first value of he next category).
Expand Down Expand Up @@ -303,3 +304,5 @@ extern int s2n_calculate_stacktrace(void);
extern int s2n_print_stacktrace(FILE *fptr);
extern int s2n_free_stacktrace(void);
extern int s2n_get_stacktrace(struct s2n_stacktrace *trace);

/* clang-format on */
3 changes: 3 additions & 0 deletions tls/s2n_cipher_preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "error/s2n_errno.h"
#include "utils/s2n_safety.h"

/* clang-format off */
/* TLS 1.3 cipher suites, in order of preference.
* Can be added to other ciphers suite lists to enable
* TLS1.3 compatibility. */
Expand Down Expand Up @@ -899,3 +900,5 @@ const struct s2n_cipher_preferences cipher_preferences_kms_fips_tls_1_2_2018_10
.count = s2n_array_len(cipher_suites_kms_fips_tls_1_2_2018_10),
.suites = cipher_suites_kms_fips_tls_1_2_2018_10,
};

/* clang-format on */
3 changes: 2 additions & 1 deletion tls/s2n_handshake_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "utils/s2n_random.h"
#include "utils/s2n_str.h"


/* clang-format off */
struct s2n_handshake_action {
uint8_t record_type;
uint8_t message_type;
Expand Down Expand Up @@ -404,6 +404,7 @@ static message_type_t tls13_handshakes[S2N_HANDSHAKES_COUNT][S2N_MAX_HANDSHAKE_L
},

};
/* clang-format on */

#define MAX_HANDSHAKE_TYPE_LEN 128
static char handshake_type_str[S2N_HANDSHAKES_COUNT][MAX_HANDSHAKE_TYPE_LEN] = {0};
Expand Down

0 comments on commit 342872f

Please sign in to comment.