Added initial support for signature

This commit is contained in:
Christian Risi
2024-12-02 19:15:12 +01:00
parent 44d6d9a84f
commit 0eb4c0069e
16 changed files with 285 additions and 8 deletions

View File

@@ -1,9 +1,11 @@
import Testing
import RandomCpp
import Foundation
import SwiftASN1
@testable import IoT_Simulator_Core
@Test func example() async throws {
@Test func workingGeneratorTest() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
var a = GaussianRNG(10, 0.5)
@@ -11,3 +13,46 @@ import RandomCpp
print(a.generate())
}
}
@Test func pemDecoded() async throws {
/*
Even though here you would expect both texts to be equal,
the openssl generated one (the raw string) is ANSI x9.62
while ours (the one made with the library) is ASN.1
When inspected with openssl, both curves where identical,
so no need to be worried
*/
let keyPath = "./Private/privateKey.pem"
let url = URL(filePath: keyPath)
let pemString = try String(contentsOf: url, encoding: String.Encoding.utf8)
let key = try pem2key(filePath: keyPath)
print(pemString)
print(key.pemRepresentation)
}
@Test func sign() async throws {
let keyPath = "./Private/privateKey.pem"
let key = try pem2key(filePath: keyPath)
let obj = [1, 2, 3]
let signature = try sign(object: obj, key: key)
}
@Test func verifySignature() async throws {
let keyPath = "./Private/privateKey.pem"
let key = try pem2key(filePath: keyPath)
let obj = "[1, 2, 3]"
let signature = try sign(object: obj, key: key)
}