Skip to content

Commit

Permalink
Styling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjoDeundiak committed Dec 7, 2018
1 parent d6f4800 commit 0596363
Show file tree
Hide file tree
Showing 29 changed files with 274 additions and 90 deletions.
90 changes: 89 additions & 1 deletion .swiftlint.yml
@@ -1,9 +1,17 @@
disabled_rules:
- redundant_optional_initialization
- statement_position
- void_return
- nesting
- compiler_protocol_init
- sorted_imports
- discouraged_optional_collection
- attributes
- multiline_arguments_brackets
- explicit_type_interface
- multiline_parameters_brackets
- multiline_parameters
- closure_body_length
- no_grouping_extension

opt_in_rules:
- array_init
Expand Down Expand Up @@ -36,6 +44,86 @@ opt_in_rules:
- unneeded_parentheses_in_closure_argument
- vertical_parameter_alignment_on_call
- yoda_condition
- closing_brace
- closure_parameter_position
- collection_alignment
- colon
- comma
- control_statement
- convenience_type
- cyclomatic_complexity
- discouraged_direct_init
- discouraged_optional_boolean
- empty_enum_arguments
- empty_parameters
- empty_parentheses_with_trailing_closure
- empty_string
- empty_xctest_method
- explicit_self
- fallthrough
- file_length
- for_where
- force_cast
- force_try
- function_body_length
- function_parameter_count
- identical_operands
- identifier_name
- implicit_getter
- implicit_return
- inert_defer
- is_disjoint
- large_tuple
- leading_whitespace
- legacy_constant
- legacy_constructor
- legacy_random
- let_var_whitespace
- line_length
- lower_acl_than_parent
- mark
- missing_docs
- modifier_order
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiple_closures_with_trailing_closure
- number_separator
- opening_brace
- operator_whitespace
- pattern_matching_keywords
- private_over_fileprivate
- protocol_property_accessors_order
- redundant_discardable_let
- redundant_string_enum_value
- redundant_type_annotation
- redundant_void_return
- return_arrow_whitespace
- shorthand_operator
- single_test_class
- static_operator
- switch_case_alignment
- switch_case_on_newline
- syntactic_sugar
- todo
- trailing_closure
- trailing_comma
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- type_body_length
- type_name
- unavailable_function
- unneeded_break_in_switch
- unused_closure_parameter
- unused_enumerated
- unused_import
- unused_optional_binding
- unused_private_declaration
- vertical_parameter_alignment
- vertical_whitespace
- void_return
- weak_delegate

excluded:
- Carthage
Expand Down
9 changes: 6 additions & 3 deletions Source/Cards/CardManager/CardManager+Export.swift
Expand Up @@ -46,7 +46,8 @@ extension CardManager {
/// Rethrows from RawSignedModel, JSONDecoder, CardCrypto
@objc open func importCard(fromBase64Encoded base64EncodedString: String) throws -> Card {
return try CardManager.importCard(fromBase64Encoded: base64EncodedString,
cardCrypto: self.cardCrypto, cardVerifier: self.cardVerifier)
cardCrypto: self.cardCrypto,
cardVerifier: self.cardVerifier)
}

/// Imports and verifies Card from json Dictionary
Expand All @@ -57,7 +58,8 @@ extension CardManager {
/// Rethrows from RawSignedModel, JSONDecoder, CardCrypto, JSONSerialization
@objc open func importCard(fromJson json: Any) throws -> Card {
return try CardManager.importCard(fromJson: json,
cardCrypto: self.cardCrypto, cardVerifier: self.cardVerifier)
cardCrypto: self.cardCrypto,
cardVerifier: self.cardVerifier)
}

/// Imports and verifies Card from RawSignedModel
Expand All @@ -68,7 +70,8 @@ extension CardManager {
/// Rethrows from RawSignedModel, JSONDecoder, CardCrypto, JSONSerialization
@objc open func importCard(fromRawCard rawCard: RawSignedModel) throws -> Card {
return try CardManager.importCard(fromRawCard: rawCard,
cardCrypto: self.cardCrypto, cardVerifier: self.cardVerifier)
cardCrypto: self.cardCrypto,
cardVerifier: self.cardVerifier)
}

/// Exports Card as base64 encoded string
Expand Down
7 changes: 5 additions & 2 deletions Source/Cards/CardManager/CardManager+Obj-C.swift
Expand Up @@ -79,8 +79,11 @@ extension CardManager {
@objc open func publishCard(privateKey: PrivateKey, publicKey: PublicKey, identity: String,
previousCardId: String? = nil, extraFields: [String: String]? = nil,
completion: @escaping (Card?, Error?) -> Void) {
self.publishCard(privateKey: privateKey, publicKey: publicKey, identity: identity,
previousCardId: previousCardId, extraFields: extraFields)
self.publishCard(privateKey: privateKey,
publicKey: publicKey,
identity: identity,
previousCardId: previousCardId,
extraFields: extraFields)
.start(completion: completion)
}

Expand Down
8 changes: 5 additions & 3 deletions Source/Cards/CardManager/CardManager+Operations.swift
Expand Up @@ -147,7 +147,7 @@ extension CardManager {
throw CardManagerError.gotWrongCard
}

let previousCard = cards.first(where: { $0.identifier == card.previousCardId })
let previousCard = cards.first { $0.identifier == card.previousCardId }
card.previousCard = previousCard
previousCard?.isOutdated = true
}
Expand Down Expand Up @@ -200,8 +200,10 @@ extension CardManager {
do {
let token: AccessToken = try operation.findDependencyResult()

let rawCard = try self.generateRawCard(privateKey: privateKey, publicKey: publicKey,
identity: token.identity(), previousCardId: previousCardId,
let rawCard = try self.generateRawCard(privateKey: privateKey,
publicKey: publicKey,
identity: token.identity(),
previousCardId: previousCardId,
extraFields: extraFields)

completion(rawCard, nil)
Expand Down
17 changes: 12 additions & 5 deletions Source/Cards/CardManager/CardManager+Parse.swift
Expand Up @@ -67,17 +67,24 @@ extension CardManager {
extraFields = nil
}

let cardSignature = CardSignature(signer: rawSignature.signer, signature: rawSignature.signature,
snapshot: rawSignature.snapshot, extraFields: extraFields)
let cardSignature = CardSignature(signer: rawSignature.signer,
signature: rawSignature.signature,
snapshot: rawSignature.snapshot,
extraFields: extraFields)

cardSignatures.append(cardSignature)
}

let createdAt = DateUtils.dateFromTimestamp(rawCardContent.createdAt)

return Card(identifier: cardId, identity: rawCardContent.identity, publicKey: publicKey,
version: rawCardContent.version, createdAt: createdAt, signatures: cardSignatures,
previousCardId: rawCardContent.previousCardId, contentSnapshot: rawSignedModel.contentSnapshot)
return Card(identifier: cardId,
identity: rawCardContent.identity,
publicKey: publicKey,
version: rawCardContent.version,
createdAt: createdAt,
signatures: cardSignatures,
previousCardId: rawCardContent.previousCardId,
contentSnapshot: rawSignedModel.contentSnapshot)
}

/// Imports Virgil Card from RawSignedModel using self CardCrypto instance
Expand Down
62 changes: 46 additions & 16 deletions Source/Cards/CardManager/CardManager+Queries.swift
Expand Up @@ -46,7 +46,7 @@ extension CardManager {
/// - Returns: CallbackOperation<GetCardResponse> for getting `GetCardResponse` with verified Virgil Card
open func getCard(withId cardId: String) -> GenericOperation<Card> {
let makeAggregateOperation: (Bool) -> GenericOperation<Card> = { force in
return CallbackOperation { _, completion in
CallbackOperation { _, completion in
let tokenContext = TokenContext(service: "cards", operation: "get", forceReload: force)
let getTokenOperation = OperationUtils.makeGetTokenOperation(
tokenContext: tokenContext, accessTokenProvider: self.accessTokenProvider)
Expand Down Expand Up @@ -88,9 +88,12 @@ extension CardManager {
@objc open func generateRawCard(privateKey: PrivateKey, publicKey: PublicKey,
identity: String, previousCardId: String? = nil,
extraFields: [String: String]? = nil) throws -> RawSignedModel {
return try CardManager.generateRawCard(cardCrypto: self.cardCrypto, modelSigner: self.modelSigner,
privateKey: privateKey, publicKey: publicKey,
identity: identity, previousCardId: previousCardId,
return try CardManager.generateRawCard(cardCrypto: self.cardCrypto,
modelSigner: self.modelSigner,
privateKey: privateKey,
publicKey: publicKey,
identity: identity,
previousCardId: previousCardId,
extraFields: extraFields)
}

Expand All @@ -112,8 +115,10 @@ extension CardManager {
extraFields: [String: String]? = nil) throws -> RawSignedModel {
let exportedPubKey = try cardCrypto.exportPublicKey(publicKey)

let cardContent = RawCardContent(identity: identity, publicKey: exportedPubKey,
previousCardId: previousCardId, createdAt: Date())
let cardContent = RawCardContent(identity: identity,
publicKey: exportedPubKey,
previousCardId: previousCardId,
createdAt: Date())

let snapshot = try JSONEncoder().encode(cardContent)

Expand All @@ -139,7 +144,7 @@ extension CardManager {
/// - Returns: CallbackOperation<Card> for creating Virgil Card instance
open func publishCard(rawCard: RawSignedModel) -> GenericOperation<Card> {
let makeAggregateOperation: (Bool) -> GenericOperation<Card> = { forceReload in
return CallbackOperation { _, completion in
CallbackOperation { _, completion in
let tokenContext = TokenContext(service: "cards", operation: "publish", forceReload: forceReload)
let getTokenOperation = OperationUtils.makeGetTokenOperation(
tokenContext: tokenContext, accessTokenProvider: self.accessTokenProvider)
Expand All @@ -162,8 +167,16 @@ extension CardManager {
completionOperation.addDependency(verifyCardOperation)

let queue = OperationQueue()
let operations = [getTokenOperation, generateRawCardOperation, signOperation,
publishCardOperation, verifyCardOperation, completionOperation]

let operations = [
getTokenOperation,
generateRawCardOperation,
signOperation,
publishCardOperation,
verifyCardOperation,
completionOperation
]

queue.addOperations(operations, waitUntilFinished: false)
}
}
Expand Down Expand Up @@ -191,13 +204,15 @@ extension CardManager {
identity: String? = nil, previousCardId: String? = nil,
extraFields: [String: String]? = nil) -> GenericOperation<Card> {
let makeAggregateOperation: (Bool) -> GenericOperation<Card> = { forceReload in
return CallbackOperation { operation, completion in
CallbackOperation { operation, completion in
let tokenContext = TokenContext(service: "cards", operation: "publish", forceReload: forceReload)
let getTokenOperation = OperationUtils.makeGetTokenOperation(
tokenContext: tokenContext, accessTokenProvider: self.accessTokenProvider)
let generateRawCardOperation =
self.makeGenerateRawCardOperation(privateKey: privateKey, publicKey: publicKey,
previousCardId: previousCardId, extraFields: extraFields)
self.makeGenerateRawCardOperation(privateKey: privateKey,
publicKey: publicKey,
previousCardId: previousCardId,
extraFields: extraFields)
let signOperation = self.makeAdditionalSignOperation()
let publishCardOperation = self.makePublishCardOperation()
let verifyCardOperation = self.makeVerifyCardOperation()
Expand All @@ -216,8 +231,16 @@ extension CardManager {
completionOperation.addDependency(verifyCardOperation)

let queue = OperationQueue()
let operations = [getTokenOperation, generateRawCardOperation, signOperation,
publishCardOperation, verifyCardOperation, completionOperation]

let operations = [
getTokenOperation,
generateRawCardOperation,
signOperation,
publishCardOperation,
verifyCardOperation,
completionOperation
]

queue.addOperations(operations, waitUntilFinished: false)
}
}
Expand Down Expand Up @@ -252,7 +275,7 @@ extension CardManager {
/// - Returns: CallbackOperation<[Card]> for performing search of Virgil Cards
open func searchCards(identities: [String]) -> GenericOperation<[Card]> {
let makeAggregateOperation: (Bool) -> GenericOperation<[Card]> = { forceReload in
return CallbackOperation { _, completion in
CallbackOperation { _, completion in
let tokenContext = TokenContext(service: "cards", operation: "search", forceReload: forceReload)
let getTokenOperation = OperationUtils.makeGetTokenOperation(
tokenContext: tokenContext, accessTokenProvider: self.accessTokenProvider)
Expand All @@ -268,7 +291,14 @@ extension CardManager {
completionOperation.addDependency(verifyCardsOperation)

let queue = OperationQueue()
let operations = [getTokenOperation, searchCardsOperation, verifyCardsOperation, completionOperation]

let operations = [
getTokenOperation,
searchCardsOperation,
verifyCardsOperation,
completionOperation
]

queue.addOperations(operations, waitUntilFinished: false)
}
}
Expand Down
9 changes: 6 additions & 3 deletions Source/Cards/CardManager/CardManager+StaticExport.swift
Expand Up @@ -49,7 +49,8 @@ extension CardManager {
/// - Throws: CardManagerError.cardIsNotVerified, if Card verificaction has failed
/// Rethrows from RawSignedModel, JSONDecoder, CardCrypto
@objc open class func importCard(fromBase64Encoded base64EncodedString: String,
cardCrypto: CardCrypto, cardVerifier: CardVerifier) throws -> Card {
cardCrypto: CardCrypto,
cardVerifier: CardVerifier) throws -> Card {
let rawCard = try RawSignedModel.import(fromBase64Encoded: base64EncodedString)
let card = try CardManager.parseCard(from: rawCard, cardCrypto: cardCrypto)

Expand All @@ -70,7 +71,8 @@ extension CardManager {
/// - Throws: CardManagerError.cardIsNotVerified, if Card verificaction has failed
/// Rethrows from RawSignedModel, JSONDecoder, CardCrypto, JSONSerialization
@objc open class func importCard(fromJson json: Any,
cardCrypto: CardCrypto, cardVerifier: CardVerifier) throws -> Card {
cardCrypto: CardCrypto,
cardVerifier: CardVerifier) throws -> Card {
let rawCard = try RawSignedModel.import(fromJson: json)
let card = try CardManager.parseCard(from: rawCard, cardCrypto: cardCrypto)

Expand All @@ -91,7 +93,8 @@ extension CardManager {
/// - Throws: CardManagerError.cardIsNotVerified, if Card verificaction has failed
/// Rethrows from RawSignedModel, JSONDecoder, CardCrypto, JSONSerialization
@objc open class func importCard(fromRawCard rawCard: RawSignedModel,
cardCrypto: CardCrypto, cardVerifier: CardVerifier) throws -> Card {
cardCrypto: CardCrypto,
cardVerifier: CardVerifier) throws -> Card {
let card = try CardManager.parseCard(from: rawCard, cardCrypto: cardCrypto)

guard cardVerifier.verifyCard(card) else {
Expand Down
15 changes: 10 additions & 5 deletions Source/Cards/ModelSigner.swift
Expand Up @@ -66,7 +66,8 @@ import VirgilCryptoAPI
let combinedSnapshot = model.contentSnapshot + (additionalData ?? Data())
let signature = try cardCrypto.generateSignature(of: combinedSnapshot, using: privateKey)

let rawSignature = RawSignature(signer: signer, signature: signature,
let rawSignature = RawSignature(signer: signer,
signature: signature,
snapshot: additionalData)

try model.addSignature(rawSignature)
Expand All @@ -80,8 +81,10 @@ import VirgilCryptoAPI
/// - additionalData: additionalData to sign with model
/// - Throws: corresponding error id signature generation fails
@objc public func selfSign(model: RawSignedModel, privateKey: PrivateKey, additionalData: Data?) throws {
try self.sign(model: model, signer: ModelSigner.selfSignerIdentifier,
privateKey: privateKey, additionalData: additionalData)
try self.sign(model: model,
signer: ModelSigner.selfSignerIdentifier,
privateKey: privateKey,
additionalData: additionalData)
}

/// Adds signature to given RawSignedModel with provided signer, privateKey and additionalData
Expand Down Expand Up @@ -114,7 +117,9 @@ import VirgilCryptoAPI
/// - Throws: corresponding error id signature generation fails
@objc public func selfSign(model: RawSignedModel, privateKey: PrivateKey,
extraFields: [String: String]? = nil) throws {
try self.sign(model: model, signer: ModelSigner.selfSignerIdentifier,
privateKey: privateKey, extraFields: extraFields)
try self.sign(model: model,
signer: ModelSigner.selfSignerIdentifier,
privateKey: privateKey,
extraFields: extraFields)
}
}

0 comments on commit 0596363

Please sign in to comment.