Skip to content

Commit bcc70e2

Browse files
authored
Merge pull request #5 from swift-libp2p/soundness
Soundness
2 parents 041db88 + 630e66b commit bcc70e2

File tree

10 files changed

+816
-347
lines changed

10 files changed

+816
-347
lines changed

.license_header_template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@@===----------------------------------------------------------------------===@@
2+
@@
3+
@@ This source file is part of the swift-libp2p open source project
4+
@@
5+
@@ Copyright (c) YEARS swift-libp2p project authors
6+
@@ Licensed under MIT
7+
@@
8+
@@ See LICENSE for license information
9+
@@ See CONTRIBUTORS for the list of swift-libp2p project authors
10+
@@
11+
@@ SPDX-License-Identifier: MIT
12+
@@
13+
@@===----------------------------------------------------------------------===@@

.licenseignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.github/workflows/configs/.flake8
2+
**/*.yml
3+
*.md
4+
*.txt
5+
Package.swift
6+
Package.resolved
7+
.gitignore
8+
.swift-format
9+
.licenseignore
10+
.license_header_template
11+
Sources/Multicodec/Codecs.swift

.swift-format

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"version" : 1,
3+
"indentation" : {
4+
"spaces" : 4
5+
},
6+
"tabWidth" : 4,
7+
"fileScopedDeclarationPrivacy" : {
8+
"accessLevel" : "private"
9+
},
10+
"spacesAroundRangeFormationOperators" : false,
11+
"indentConditionalCompilationBlocks" : false,
12+
"indentSwitchCaseLabels" : false,
13+
"lineBreakAroundMultilineExpressionChainComponents" : false,
14+
"lineBreakBeforeControlFlowKeywords" : false,
15+
"lineBreakBeforeEachArgument" : true,
16+
"lineBreakBeforeEachGenericRequirement" : true,
17+
"lineLength" : 120,
18+
"maximumBlankLines" : 1,
19+
"respectsExistingLineBreaks" : true,
20+
"prioritizeKeepingFunctionOutputTogether" : true,
21+
"noAssignmentInExpressions" : {
22+
"allowedFunctions" : [
23+
"XCTAssertNoThrow",
24+
"XCTAssertThrowsError"
25+
]
26+
},
27+
"rules" : {
28+
"AllPublicDeclarationsHaveDocumentation" : false,
29+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
30+
"AlwaysUseLowerCamelCase" : false,
31+
"AmbiguousTrailingClosureOverload" : true,
32+
"BeginDocumentationCommentWithOneLineSummary" : false,
33+
"DoNotUseSemicolons" : true,
34+
"DontRepeatTypeInStaticProperties" : true,
35+
"FileScopedDeclarationPrivacy" : true,
36+
"FullyIndirectEnum" : true,
37+
"GroupNumericLiterals" : true,
38+
"IdentifiersMustBeASCII" : true,
39+
"NeverForceUnwrap" : false,
40+
"NeverUseForceTry" : false,
41+
"NeverUseImplicitlyUnwrappedOptionals" : false,
42+
"NoAccessLevelOnExtensionDeclaration" : true,
43+
"NoAssignmentInExpressions" : true,
44+
"NoBlockComments" : true,
45+
"NoCasesWithOnlyFallthrough" : true,
46+
"NoEmptyTrailingClosureParentheses" : true,
47+
"NoLabelsInCasePatterns" : true,
48+
"NoLeadingUnderscores" : false,
49+
"NoParensAroundConditions" : true,
50+
"NoVoidReturnOnFunctionSignature" : true,
51+
"OmitExplicitReturns" : true,
52+
"OneCasePerLine" : true,
53+
"OneVariableDeclarationPerLine" : true,
54+
"OnlyOneTrailingClosureArgument" : true,
55+
"OrderedImports" : true,
56+
"ReplaceForEachWithForLoop" : true,
57+
"ReturnVoidInsteadOfEmptyTuple" : true,
58+
"UseEarlyExits" : false,
59+
"UseExplicitNilCheckInConditions" : false,
60+
"UseLetInEveryBoundCaseVariable" : false,
61+
"UseShorthandTypeNames" : true,
62+
"UseSingleLinePropertyGetter" : false,
63+
"UseSynthesizedInitializer" : false,
64+
"UseTripleSlashForDocumentationComments" : true,
65+
"UseWhereClausesInForLoops" : false,
66+
"ValidateDocumentationComments" : false
67+
}
68+
}

Package.swift

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,57 @@
1-
// swift-tools-version:5.4
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
// swift-tools-version:5.5
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the swift-libp2p open source project
5+
//
6+
// Copyright (c) 2022-2025 swift-libp2p project authors
7+
// Licensed under MIT
8+
//
9+
// See LICENSE for license information
10+
// See CONTRIBUTORS for the list of swift-libp2p project authors
11+
//
12+
// SPDX-License-Identifier: MIT
13+
//
14+
//===----------------------------------------------------------------------===//
315

416
import PackageDescription
517

618
let package = Package(
719
name: "swift-multicodec",
820
platforms: [
921
.macOS(.v10_10),
10-
.iOS(.v10)
22+
.iOS(.v10),
1123
],
1224
products: [
1325
// Products define the executables and libraries produced by a package, and make them visible to other packages.
1426
.executable(
1527
name: "update-codecs",
16-
targets: ["Updater"]),
28+
targets: ["Updater"]
29+
),
1730
.library(
1831
name: "Multicodec",
19-
targets: ["Multicodec"]),
32+
targets: ["Multicodec"]
33+
),
2034
],
2135
dependencies: [
2236
// Dependencies declare other packages that this package depends on.
23-
// .package(url: /* package url */, from: "1.0.0"),
24-
//.package(name: "VarInt", path: "../VarInt") //Use this when attempting to run update-codecs (until our repo is public)
2537
.package(url: "https://github.com/swift-libp2p/swift-varint.git", from: "0.0.1")
2638
],
2739
targets: [
2840
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2941
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
3042
.executableTarget(
3143
name: "Updater",
32-
dependencies: []),
44+
dependencies: []
45+
),
3346
.target(
3447
name: "Multicodec",
3548
dependencies: [
36-
.product(name: "VarInt", package: "swift-varint"),
37-
]),
49+
.product(name: "VarInt", package: "swift-varint")
50+
]
51+
),
3852
.testTarget(
3953
name: "MulticodecTests",
40-
dependencies: ["Multicodec"]),
54+
dependencies: ["Multicodec"]
55+
),
4156
]
4257
)

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ let package = Package(
3838
)
3939
```
4040

41-
4241
## Usage
4342

4443
### Example
4544

46-
```Swift
45+
```swift
4746

4847
import Multicodec
4948

@@ -72,7 +71,7 @@ Updating the Codec enum is done by running the following command at the projects
7271

7372
## Contributing
7473

75-
Contributions are welcomed! This code is very much a proof of concept. I can guarantee you there's a better / safer way to accomplish the same results. Any suggestions, improvements, or even just critques, are welcome!
74+
Contributions are welcomed! This code is very much a proof of concept. I can guarantee you there's a better / safer way to accomplish the same results. Any suggestions, improvements, or even just critiques, are welcome!
7675

7776
Let's make this code better together! 🤝
7877

Sources/Multicodec/Codecs+Equatable.swift

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1+
//===----------------------------------------------------------------------===//
12
//
2-
// Codecs+Equatable.swift
3-
//
3+
// This source file is part of the swift-libp2p open source project
44
//
5-
// Created by Brandon Toms on 5/1/22.
5+
// Copyright (c) 2022-2025 swift-libp2p project authors
6+
// Licensed under MIT
67
//
8+
// See LICENSE for license information
9+
// See CONTRIBUTORS for the list of swift-libp2p project authors
10+
//
11+
// SPDX-License-Identifier: MIT
12+
//
13+
//===----------------------------------------------------------------------===//
714

815
import Foundation
916

10-
public extension Codecs {
11-
static func ==(lhs: Codecs, rhs: Codecs) -> Bool {
12-
return lhs.rawValue == rhs.rawValue
17+
extension Codecs {
18+
public static func == (lhs: Codecs, rhs: Codecs) -> Bool {
19+
lhs.rawValue == rhs.rawValue
1320
}
14-
15-
static func ==(lhs: Codecs, rhs: Int64) -> Bool {
16-
return lhs.rawValue == rhs
21+
22+
public static func == (lhs: Codecs, rhs: Int64) -> Bool {
23+
lhs.rawValue == rhs
1724
}
1825

19-
static func ==(lhs: Codecs, rhs: Int) -> Bool {
20-
return lhs.rawValue == Int64(rhs)
26+
public static func == (lhs: Codecs, rhs: Int) -> Bool {
27+
lhs.rawValue == Int64(rhs)
2128
}
2229

23-
static func ==(lhs: Codecs, rhs: String) -> Bool {
24-
return lhs.name == rhs
30+
public static func == (lhs: Codecs, rhs: String) -> Bool {
31+
lhs.name == rhs
2532
}
26-
27-
func isEqual(object: AnyObject?) -> Bool {
33+
34+
public func isEqual(object: AnyObject?) -> Bool {
2835
if let obj = object as? Codecs {
2936
return self.rawValue == obj.rawValue
3037
} else if let obj = object as? Int64 {
@@ -57,4 +64,3 @@ public extension Codecs {
5764
// return lhs.rawValue == rhs
5865
// }
5966
//}
60-

0 commit comments

Comments
 (0)