-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(encryption): initial api + tests (#1)
- Loading branch information
Showing
14 changed files
with
767 additions
and
24 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
RowndFrameworkTestApp/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
RowndFrameworkTestApp/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "83.5x83.5" | ||
}, | ||
{ | ||
"idiom" : "ios-marketing", | ||
"scale" : "1x", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// ContentView.swift | ||
// RowndFrameworkTestApp | ||
// | ||
// Created by Matt Hamann on 7/15/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
var body: some View { | ||
Text("Hello, world!") | ||
.padding() | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
RowndFrameworkTestApp/Preview Content/Preview Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// RowndFrameworkTestAppApp.swift | ||
// RowndFrameworkTestApp | ||
// | ||
// Created by Matt Hamann on 7/15/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct RowndFrameworkTestAppApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// EncryptionTests.swift | ||
// RowndTests | ||
// | ||
// Created by Matt Hamann on 7/15/22. | ||
// | ||
|
||
import XCTest | ||
@testable import Rownd | ||
|
||
class EncryptionTests: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
RowndEncryption.deleteKey(keyId: "my-test-account") | ||
try super.setUpWithError() | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
RowndEncryption.deleteKey(keyId: "my-test-account") | ||
try super.tearDownWithError() | ||
} | ||
|
||
func testGenerateSymmetricKey() throws { | ||
let key = RowndEncryption.generateKey() | ||
print("base64 key:", String(decoding: key.asData().base64EncodedData(), as: UTF8.self)) | ||
XCTAssertNotNil(key, "Generated encryption key was nil") | ||
} | ||
|
||
func testStoreSymmetricKey() throws { | ||
let key = RowndEncryption.generateKey() | ||
try RowndEncryption.storeKey(key: key, keyId: "my-test-account") | ||
print("base64 key:", String(decoding: key.asData().base64EncodedData(), as: UTF8.self)) | ||
let atch = XCTAttachment(data: key.asData().base64EncodedData()) | ||
self.add(atch) | ||
} | ||
|
||
func testRetrieveSymmetricKey() throws { | ||
let origKey = RowndEncryption.generateKey() | ||
try RowndEncryption.storeKey(key: origKey, keyId: "my-test-account") | ||
print("stored key:", String(decoding: origKey.asData().base64EncodedData(), as: UTF8.self)) | ||
let retKey = try RowndEncryption.loadKey(keyId: "my-test-account") | ||
XCTAssertNotNil(retKey, "Failed to retrieve a key that should exist") | ||
XCTAssertEqual(String(decoding: origKey.asData().base64EncodedData(), as: UTF8.self), String(decoding: retKey?.asData().base64EncodedData() ?? Data(), as: UTF8.self), "Stored and retrieved keys are not equal") | ||
|
||
guard let key = retKey else { | ||
return | ||
} | ||
|
||
print("retrieved key:", String(decoding: key.asData().base64EncodedData(), as: UTF8.self)) | ||
// print(key.asData().base64EncodedData()) | ||
let atch = XCTAttachment(data: key.asData().base64EncodedData()) | ||
self.add(atch) | ||
} | ||
|
||
func testEncryptingData() throws { | ||
let keyId = "test-key" | ||
let key = Array(Data(base64Encoded: "4f4a6IInDuSga0wyQQQpMSrDHIZ/ryoc9w6s5xVF/VQ=")!) | ||
try RowndEncryption.storeKey(key: key, keyId: keyId) | ||
|
||
let plainText = "This super secret string will never be known." | ||
let cipherText: String = try RowndEncryption.encrypt(plaintext: plainText, withKeyId: keyId) | ||
|
||
print(cipherText) | ||
|
||
XCTAssertNotNil(cipherText, "Failed to encrypt plaintext into ciphertext") | ||
} | ||
|
||
func testDecryptingData() throws { | ||
let keyId = "test-key" | ||
let key = Array(Data(base64Encoded: "4f4a6IInDuSga0wyQQQpMSrDHIZ/ryoc9w6s5xVF/VQ=")!) | ||
try RowndEncryption.storeKey(key: key, keyId: keyId) | ||
|
||
let expectedPlainText = "This super secret string will never be known." | ||
let cipherText = "Di0IyYbC141WIPKzFnlsQc0BIi1AWKSpLf6Th9TcDDJiidPfkVazXtFibnsqJyKFaQf7SaF68yihnqJXidodfKqKzjM2MnbHbh+O8wpxFO3gO6OhVg==" | ||
|
||
let computedPlainText: String = try RowndEncryption.decrypt(ciphertext: cipherText, withKeyId: keyId) | ||
|
||
print(computedPlainText) | ||
|
||
XCTAssertEqual(expectedPlainText, computedPlainText, "The computed plaintext did not match the expected") | ||
} | ||
|
||
func testEncryptThenDecrypt() throws { | ||
let keyId = "test-key" | ||
let key = RowndEncryption.generateKey() | ||
try RowndEncryption.storeKey(key: key, keyId: keyId) | ||
|
||
let plainText = "This super secret string will never be known." | ||
let cipherText: String = try RowndEncryption.encrypt(plaintext: plainText, withKeyId: keyId) | ||
|
||
print(cipherText) | ||
|
||
let computedPlainText: String = try RowndEncryption.decrypt(ciphertext: cipherText, withKeyId: keyId) | ||
|
||
print(computedPlainText) | ||
|
||
XCTAssertEqual(plainText, computedPlainText, "The original and computed plaintexts do not match even though the key matched") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// RowndTests.swift | ||
// RowndTests | ||
// | ||
// Created by Matt Hamann on 7/15/22. | ||
// | ||
|
||
import XCTest | ||
|
||
class RowndTests: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testExample() throws { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct results. | ||
// Any test you write for XCTest can be annotated as throws and async. | ||
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. | ||
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. | ||
} | ||
|
||
func testPerformanceExample() throws { | ||
// This is an example of a performance test case. | ||
measure { | ||
// Put the code you want to measure the time of here. | ||
} | ||
} | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.