From 783fece367eb9e2942052dc2b82ae8cb84f8d5f6 Mon Sep 17 00:00:00 2001 From: ieow Date: Tue, 23 Jan 2024 15:22:59 +0800 Subject: [PATCH] feat: make encryption separate product --- Package.swift | 14 ++++++++++++-- .../EncryptedMessage.swift | 1 + .../{secp256k1 => encryption}/Encryption.swift | 1 + Sources/curvelib/secp256k1/CurveError.swift | 4 ++-- Sources/curvelib/secp256k1/PublicKey.swift | 4 ++-- Sources/curvelib/secp256k1/SecretKey.swift | 2 +- Tests/curvelibTests/curvelibTests.swift | 1 + 7 files changed, 20 insertions(+), 7 deletions(-) rename Sources/curvelib/{secp256k1 => encryption}/EncryptedMessage.swift (99%) rename Sources/curvelib/{secp256k1 => encryption}/Encryption.swift (98%) diff --git a/Package.swift b/Package.swift index ce13cb7..0597395 100644 --- a/Package.swift +++ b/Package.swift @@ -13,6 +13,10 @@ let package = Package( .library( name: "secp256k1.swift", targets: ["secp256k1.swift"]), + + .library( + name: "encryption_aes_cbc_sha512.swift", + targets: ["encryption_aes_cbc_sha512.swift"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -32,10 +36,16 @@ let package = Package( .target( name: "secp256k1.swift", dependencies: ["curvelib"], - path: "Sources/curvelib" + path: "Sources/curvelib/secp256k1" ), + .target( + name: "encryption_aes_cbc_sha512.swift", + dependencies: ["curvelib", "secp256k1.swift"], + path: "Sources/curvelib/encryption" + ), + .testTarget( name: "curvelibTests", - dependencies: ["secp256k1.swift"]), + dependencies: ["secp256k1.swift", "encryption_aes_cbc_sha512.swift"]), ] ) diff --git a/Sources/curvelib/secp256k1/EncryptedMessage.swift b/Sources/curvelib/encryption/EncryptedMessage.swift similarity index 99% rename from Sources/curvelib/secp256k1/EncryptedMessage.swift rename to Sources/curvelib/encryption/EncryptedMessage.swift index 56db35f..0c23f1f 100644 --- a/Sources/curvelib/secp256k1/EncryptedMessage.swift +++ b/Sources/curvelib/encryption/EncryptedMessage.swift @@ -3,6 +3,7 @@ import Foundation #if canImport(curvelib) import curvelib #endif +import secp256k1_swift public final class EncryptedMessage { private(set) var pointer: OpaquePointer? diff --git a/Sources/curvelib/secp256k1/Encryption.swift b/Sources/curvelib/encryption/Encryption.swift similarity index 98% rename from Sources/curvelib/secp256k1/Encryption.swift rename to Sources/curvelib/encryption/Encryption.swift index 24b0367..d974beb 100644 --- a/Sources/curvelib/secp256k1/Encryption.swift +++ b/Sources/curvelib/encryption/Encryption.swift @@ -3,6 +3,7 @@ import Foundation #if canImport(curvelib) import curvelib #endif +import secp256k1_swift public final class Encryption { public static func encrypt(pk: PublicKey, plainText: String) throws -> EncryptedMessage { diff --git a/Sources/curvelib/secp256k1/CurveError.swift b/Sources/curvelib/secp256k1/CurveError.swift index 2adea06..145536c 100644 --- a/Sources/curvelib/secp256k1/CurveError.swift +++ b/Sources/curvelib/secp256k1/CurveError.swift @@ -1,7 +1,7 @@ import Foundation public struct CurveError: Error, LocalizedError { - enum ErrorType { + public enum ErrorType { case null case convert case parse @@ -17,7 +17,7 @@ public struct CurveError: Error, LocalizedError { private(set) var type: ErrorType - init(code: Int32) { + public init(code: Int32) { switch code { case 1: type = .null case 2: type = .convert diff --git a/Sources/curvelib/secp256k1/PublicKey.swift b/Sources/curvelib/secp256k1/PublicKey.swift index 68c6da6..7ba0e2b 100644 --- a/Sources/curvelib/secp256k1/PublicKey.swift +++ b/Sources/curvelib/secp256k1/PublicKey.swift @@ -5,9 +5,9 @@ import Foundation #endif public final class PublicKey { - private(set) var pointer: OpaquePointer? + private(set) public var pointer: OpaquePointer? - internal init(ptr: OpaquePointer) { + public init(ptr: OpaquePointer) { pointer = ptr } diff --git a/Sources/curvelib/secp256k1/SecretKey.swift b/Sources/curvelib/secp256k1/SecretKey.swift index f3222d0..251e694 100644 --- a/Sources/curvelib/secp256k1/SecretKey.swift +++ b/Sources/curvelib/secp256k1/SecretKey.swift @@ -5,7 +5,7 @@ import Foundation #endif public final class SecretKey { - private(set) var pointer: OpaquePointer? + private(set) public var pointer: OpaquePointer? public init() { pointer = curve_secp256k1_private_key_generate() diff --git a/Tests/curvelibTests/curvelibTests.swift b/Tests/curvelibTests/curvelibTests.swift index 08a9186..3372f54 100644 --- a/Tests/curvelibTests/curvelibTests.swift +++ b/Tests/curvelibTests/curvelibTests.swift @@ -1,5 +1,6 @@ import XCTest import secp256k1_swift +import encryption_aes_cbc_sha512_swift final class curvelibTests: XCTestCase { func testSecretKey() throws {