Skip to content

Commit

Permalink
Moved VSSKeyEntry to swift, added SPM
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogerets committed Jul 4, 2022
1 parent d48652e commit 4b3aa70
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 203 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Pods

## Build generated
build/
.build/
DerivedData/

## Various settings
Expand Down
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"pins" : [
{
"identity" : "virgil-crypto-x",
"kind" : "remoteSourceControl",
"location" : "https://github.com/VirgilSecurity/virgil-crypto-x.git",
"state" : {
"branch" : "develop",
"revision" : "bb45915104076945276d8d32c515ecb5b2a1b362"
}
},
{
"identity" : "virgil-cryptowrapper-x",
"kind" : "remoteSourceControl",
"location" : "https://github.com/VirgilSecurity/virgil-cryptowrapper-x.git",
"state" : {
"branch" : "develop",
"revision" : "aa65889e563b99527aefa8b53af4b769a92fbf21"
}
}
],
"version" : 2
}
30 changes: 30 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "VirgilSDK",
platforms: [
.macOS(.v10_11), .iOS(.v9), .tvOS(.v9), .watchOS(.v2)
],
products: [
.library(
name: "VirgilSDK",
targets: ["VirgilSDK"]),
],

dependencies: [
.package(url: "https://github.com/VirgilSecurity/virgil-crypto-x.git", branch: "develop")
],

targets: [
.target(
name: "VirgilSDK",
dependencies: [
.product(name: "VirgilCrypto", package: "virgil-crypto-x"),
],
path: "Source"
)
]
)
44 changes: 42 additions & 2 deletions Source/VirgilSDK.h → Source/KeychainStorage/KeyEntry.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2015-2021 Virgil Security Inc.
// Copyright (C) 2015-2022 Virgil Security Inc.
//
// All rights reserved.
//
Expand Down Expand Up @@ -34,4 +34,44 @@
// Lead Maintainer: Virgil Security Inc. <[email protected]>
//

#import "VSSKeyEntry.h"
import Foundation

@objc(VSSKeyEntry) public class KeyEntry: NSObject, NSCoding {

public let name: String
public let value: Data
public let meta: [String: String]?

private enum CodingKeys: String {
case name = "name"
case value = "value"
case meta = "meta"
}

public init(name: String, value: Data, meta: [String: String]?) {
self.name = name
self.value = value
self.meta = meta
}

public required init?(coder: NSCoder) {
self.name = coder.decodeObject(forKey: CodingKeys.name.rawValue) as! String
self.value = coder.decodeObject(forKey: CodingKeys.value.rawValue) as! Data

if coder.containsValue(forKey: CodingKeys.meta.rawValue) {
self.meta = coder.decodeObject(forKey: CodingKeys.meta.rawValue) as? [String: String]
}
else {
self.meta = nil
}
}

public func encode(with coder: NSCoder) {
coder.encode(self.name, forKey: CodingKeys.name.rawValue)
coder.encode(self.value, forKey: CodingKeys.value.rawValue)

if let meta = self.meta {
coder.encode(meta, forKey: CodingKeys.value.rawValue)
}
}
}
84 changes: 0 additions & 84 deletions Source/KeychainStorage/VSSKeyEntry.h

This file was deleted.

87 changes: 0 additions & 87 deletions Source/KeychainStorage/VSSKeyEntry.m

This file was deleted.

1 change: 1 addition & 0 deletions Source/Utils/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// Lead Maintainer: Virgil Security Inc. <[email protected]>
//

import Foundation
import VirgilCrypto

/// Encryption credentials
Expand Down
32 changes: 32 additions & 0 deletions Tests/Cards/VSS012_KeychainStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,36 @@ class VSS012_KeychainStorageTests: XCTestCase {
try! self.storage.deleteEntry(withName: name)
XCTAssert(!(try! self.storage.existsEntry(withName: name)))
}

func test009_KeyEntryMigration() {
let name = "22AE48D7-37EB-456F-8BBA-2916F4AF3DBE"
let data = Data(base64Encoded: "QjZEQTRBNTgtRjRFQS00NDFFLUJGQ0EtQTE1OEEyNDVEQzMx")!
let meta = ["DE1307F5-8EFB-4C89-BCB9-318A5D46CDDF": "8C5E4A12-B671-4C08-A868-BA463E34D40D"]

let dataString = "YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGpCwwVFhcfICEnVSRudWxs1A0ODxAREhMUVXZhbHVlVG1ldGFUbmFtZVYkY2xhc3OAA4AEgAKACF8QJDIyQUU0OEQ3LTM3RUItNDU2Ri04QkJBLTI5MTZGNEFGM0RCRU8QJEI2REE0QTU4LUY0RUEtNDQxRS1CRkNBLUExNThBMjQ1REMzMdMYGRAaHB5XTlMua2V5c1pOUy5vYmplY3RzoRuABaEdgAaAB18QJERFMTMwN0Y1LThFRkItNEM4OS1CQ0I5LTMxOEE1RDQ2Q0RERl8QJDhDNUU0QTEyLUI2NzEtNEMwOC1BODY4LUJBNDYzRTM0RDQwRNIiIyQlWiRjbGFzc25hbWVYJGNsYXNzZXNcTlNEaWN0aW9uYXJ5oiQmWE5TT2JqZWN00iIjKClbVlNTS2V5RW50cnmiKiZbVlNTS2V5RW50cnkACAARABoAJAApADIANwBJAEwAUQBTAF0AYwBsAHIAdwB8AIMAhQCHAIkAiwCyANkA4ADoAPMA9QD3APkA+wD9ASQBSwFQAVsBZAFxAXQBfQGCAY4BkQAAAAAAAAIBAAAAAAAAACsAAAAAAAAAAAAAAAAAAAGd"
let objectData = Data(base64Encoded: dataString)!

let object = NSKeyedUnarchiver.unarchiveObject(with: objectData)
let storedKeyEntry = object as! KeyEntry

XCTAssert(storedKeyEntry.name == name)
XCTAssert(storedKeyEntry.value == data)
XCTAssert(storedKeyEntry.meta == meta)
}

func test010_KeyEntryMigration_EmptyMeta() {
let name = "22AE48D7-37EB-456F-8BBA-2916F4AF3DBE"
let data = Data(base64Encoded: "QjZEQTRBNTgtRjRFQS00NDFFLUJGQ0EtQTE1OEEyNDVEQzMx")!
let meta: [String: String]? = nil

let dataString = "YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGlCwwVFhdVJG51bGzUDQ4PEBESExRVdmFsdWVUbWV0YVRuYW1lViRjbGFzc4ADgACAAoAEXxAkMjJBRTQ4RDctMzdFQi00NTZGLThCQkEtMjkxNkY0QUYzREJFTxAkQjZEQTRBNTgtRjRFQS00NDFFLUJGQ0EtQTE1OEEyNDVEQzMx0hgZGhtaJGNsYXNzbmFtZVgkY2xhc3Nlc1tWU1NLZXlFbnRyeaIcHVtWU1NLZXlFbnRyeVhOU09iamVjdAAIABEAGgAkACkAMgA3AEkATABRAFMAWQBfAGgAbgBzAHgAfwCBAIMAhQCHAK4A1QDaAOUA7gD6AP0BCQAAAAAAAAIBAAAAAAAAAB4AAAAAAAAAAAAAAAAAAAES"
let objectData = Data(base64Encoded: dataString)!

let object = NSKeyedUnarchiver.unarchiveObject(with: objectData)
let storedKeyEntry = object as! KeyEntry

XCTAssert(storedKeyEntry.name == name)
XCTAssert(storedKeyEntry.value == data)
XCTAssert(storedKeyEntry.meta == meta)
}
}
1 change: 1 addition & 0 deletions Tests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// Lead Maintainer: Virgil Security Inc. <[email protected]>
//

import Foundation
import VirgilSDK
import VirgilCrypto

Expand Down
Loading

0 comments on commit 4b3aa70

Please sign in to comment.