Integrate linter

Re-integrate swiftlint support (which was accidentally removed in #6). In addition, de-integrate swiftformat.

Fix style violations throughout code.
This commit is contained in:
Keefer Taylor 2019-01-27 19:14:56 +00:00 committed by GitHub
commit 3722358c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2122 additions and 2086 deletions

View File

@ -1,5 +0,0 @@
--exclude Pods
--header "Copyright Keefer Taylor, 2018"
--allman false
--indent 2
--disable redundantSelf

View File

@ -1,11 +1,44 @@
disabled_rules:
- file_length
- function_parameter_count
- function_body_length
- type_body_length
- xctfail_message
opt_in_rules:
- attributes
- closure_end_indentation
- closure_spacing
- empty_count
- empty_string
- explicit_init
- file_header
- first_where
- force_unwrapping
- implicitly_unwrapped_optional
- literal_expression_end_indentation
- multiline_arguments
- multiline_arguments_brackets
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
- multiple_closures_with_trailing_closure
- number_separator
- object_literal
- operator_usage_whitespace
- overridden_super_call
- prohibited_super_call
- redundant_nil_coalescing
- sorted_imports
- trailing_closure
- vertical_parameter_alignment_on_call
excluded:
- Pods
- Carthage/
- Pods/
identifier_name:
min_length: 1
file_header:
required_pattern: "Copyright Keefer Taylor, 2018"
required_pattern: Copyright Keefer Taylor, 201(8|9)

View File

@ -1,6 +1,8 @@
// Copyright Keefer Taylor, 2019
import MnemonicKit
let strength = 128
if let mnemonic = Mnemonic.generateMnemonic(strength: strength) {
print("A mnemonic of strength \(strength): \(mnemonic)");
print("A mnemonic of strength \(strength): \(mnemonic)")
}

View File

@ -175,6 +175,7 @@
F8A8C55721CD4C86005684A3 /* Frameworks */,
F8A8C55821CD4C86005684A3 /* Resources */,
F8A8C57321CD4D6E005684A3 /* Carthage */,
7791E60E21FE346900957650 /* SwiftLint */,
);
buildRules = (
);
@ -245,6 +246,24 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
7791E60E21FE346900957650 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = SwiftLint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint --strict\nelse\necho \"warning: SwiftLint not installed, run `brew install swiftlint`\"\nfi\n";
};
F8A8C57321CD4D6E005684A3 /* Carthage */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@ -485,7 +504,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = marekfort.MnemonicKit;
PRODUCT_BUNDLE_IDENTIFIER = keefertaylor.MnemonicKit;
PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
@ -522,7 +541,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = marekfort.MnemonicKit;
PRODUCT_BUNDLE_IDENTIFIER = keefertaylor.MnemonicKit;
PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;

View File

@ -1,11 +1,10 @@
// Copyright Keefer Taylor, 2018
// swiftlint:disable file_length
import Foundation
extension String {
static let chineseMnemonics = ["",
static let chineseMnemonics = [
"",
"",
"",
"",
@ -2052,5 +2051,6 @@ extension String {
"",
"",
"",
""]
""
]
}

View File

@ -1,7 +1,5 @@
// Copyright Keefer Taylor, 2018
// swiftlint:disable file_length
import Foundation
extension String {

View File

@ -25,8 +25,7 @@ public class Mnemonic {
* Parameter hexString: The hex string to generate a mnemonic from.
* Parameter language: The language to use. Default is english.
*/
public static func mnemonicString(from hexString: String,
language: MnemonicLanguageType = .english) -> String? {
public static func mnemonicString(from hexString: String, language: MnemonicLanguageType = .english) -> String? {
let seedData = hexString.mnemonicData()
let hashData = seedData.sha256()
let checkSum = hashData.toBitArray()
@ -59,9 +58,11 @@ public class Mnemonic {
* Parameter passphrase: An optional passphrase. Default is the empty string.
* Parameter language: The language to use. Default is english.
*/
public static func deterministicSeedString(from mnemonic: String,
public static func deterministicSeedString(
from mnemonic: String,
passphrase: String = "",
language _: MnemonicLanguageType = .english) -> String? {
language _: MnemonicLanguageType = .english
) -> String? {
guard let normalizedData = self.normalized(string: mnemonic),
let saltData = normalized(string: "mnemonic" + passphrase) else {
return nil
@ -70,10 +71,8 @@ public class Mnemonic {
let passwordBytes = normalizedData.bytes
let saltBytes = saltData.bytes
do {
let bytes = try PKCS5.PBKDF2(password: passwordBytes,
salt: saltBytes,
iterations: 2048,
variant: .sha512).calculate()
let bytes =
try PKCS5.PBKDF2(password: passwordBytes, salt: saltBytes, iterations: 2_048, variant: .sha512).calculate()
return bytes.toHexString()
} catch {
return nil

View File

@ -1,10 +1,4 @@
//
// MnemonicKit.h
// MnemonicKit
//
// Created by Marek Fořt on 12/21/18.
// Copyright © 2018 Keefer Taylor. All rights reserved.
//
// Copyright Keefer Taylor, 2019
#import <UIKit/UIKit.h>

View File

@ -1,7 +1,7 @@
// Copyright Keefer Taylor, 2018
import XCTest
import MnemonicKit
import XCTest
class MnemonicTests: XCTestCase {
/// Indices in the input file.
@ -48,8 +48,7 @@ class MnemonicTests: XCTestCase {
let mnemonicString = testCase[mnenomicStringIndex]
let expectedDeterministicSeedString = testCase[deterministicSeedStringIndex]
let deterministicSeedString = Mnemonic.deterministicSeedString(from: mnemonicString,
passphrase: passphrase)
let deterministicSeedString = Mnemonic.deterministicSeedString(from: mnemonicString, passphrase: passphrase)
XCTAssertEqual(deterministicSeedString, expectedDeterministicSeedString)
}
}
@ -64,8 +63,7 @@ class MnemonicTests: XCTestCase {
let data = try Data(contentsOf: url)
let options: JSONSerialization.ReadingOptions = [.allowFragments, .mutableContainers, .mutableLeaves]
guard let parsedDictionary =
try JSONSerialization.jsonObject(with: data,
options: options) as? [String: Any] else {
try JSONSerialization.jsonObject(with: data, options: options) as? [String: Any] else {
return nil
}
return parsedDictionary

View File

@ -1,5 +1,3 @@
# List of ignore directories for code coverage.
ignore:
- "MnemonicKitTests"
- "Sources/App"
- "Pods/CryptoSwift"
- "Tests"