mirror of
https://github.com/laosb/swift-minisign.git
synced 2025-05-19 18:11:07 +00:00
Compare commits
No commits in common. "main" and "0.1.0" have entirely different histories.
4 changed files with 11 additions and 57 deletions
|
@ -8,8 +8,9 @@ let package = Package(
|
||||||
platforms: [
|
platforms: [
|
||||||
.macOS(.v10_15),
|
.macOS(.v10_15),
|
||||||
.iOS(.v13),
|
.iOS(.v13),
|
||||||
.watchOS(.v6),
|
.visionOS(.v1),
|
||||||
.tvOS(.v13),
|
.tvOS(.v13),
|
||||||
|
.watchOS(.v6)
|
||||||
],
|
],
|
||||||
products: [
|
products: [
|
||||||
// Products define the executables and libraries a package produces, making them visible to other packages.
|
// Products define the executables and libraries a package produces, making them visible to other packages.
|
||||||
|
@ -27,7 +28,7 @@ let package = Package(
|
||||||
.default(enabledTraits: ["UseSwiftCrypto"]),
|
.default(enabledTraits: ["UseSwiftCrypto"]),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/apple/swift-crypto", "1.0.0" ..< "4.0.0"),
|
.package(url: "https://github.com/apple/swift-crypto", from: "2.0.0"),
|
||||||
.package(url: "https://github.com/lovetodream/swift-blake2", from: "0.1.0")
|
.package(url: "https://github.com/lovetodream/swift-blake2", from: "0.1.0")
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
|
@ -44,6 +45,5 @@ let package = Package(
|
||||||
name: "MinisignTests",
|
name: "MinisignTests",
|
||||||
dependencies: ["Minisign"]
|
dependencies: ["Minisign"]
|
||||||
),
|
),
|
||||||
],
|
]
|
||||||
swiftLanguageModes: [.v6]
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
// swift-tools-version: 5.9
|
|
||||||
|
|
||||||
import PackageDescription
|
|
||||||
|
|
||||||
let package = Package(
|
|
||||||
name: "Minisign",
|
|
||||||
platforms: [
|
|
||||||
.macOS(.v10_15),
|
|
||||||
.iOS(.v13),
|
|
||||||
.watchOS(.v6),
|
|
||||||
.tvOS(.v13),
|
|
||||||
],
|
|
||||||
products: [
|
|
||||||
// Products define the executables and libraries a package produces, making them visible to other packages.
|
|
||||||
.library(
|
|
||||||
name: "Minisign",
|
|
||||||
targets: ["Minisign"]
|
|
||||||
)
|
|
||||||
],
|
|
||||||
dependencies: [
|
|
||||||
.package(url: "https://github.com/apple/swift-crypto", "1.0.0" ..< "4.0.0"),
|
|
||||||
.package(url: "https://github.com/lovetodream/swift-blake2", from: "0.1.0"),
|
|
||||||
],
|
|
||||||
targets: [
|
|
||||||
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
|
||||||
// Targets can depend on other targets in this package and products from dependencies.
|
|
||||||
.target(
|
|
||||||
name: "Minisign",
|
|
||||||
dependencies: [
|
|
||||||
.product(name: "Crypto", package: "swift-crypto"),
|
|
||||||
.product(name: "BLAKE2", package: "swift-blake2"),
|
|
||||||
],
|
|
||||||
swiftSettings: [
|
|
||||||
.define("UseSwiftCrypto")
|
|
||||||
]
|
|
||||||
),
|
|
||||||
.testTarget(
|
|
||||||
name: "MinisignTests",
|
|
||||||
dependencies: ["Minisign"]
|
|
||||||
),
|
|
||||||
],
|
|
||||||
swiftLanguageVersions: [.version("6"), .v5]
|
|
||||||
)
|
|
|
@ -1,14 +1,10 @@
|
||||||
# Swift Minisign
|
# Swift Minisign
|
||||||
|
|
||||||
[](https://swiftpackageindex.com/laosb/swift-minisign)
|
|
||||||
[](https://swiftpackageindex.com/laosb/swift-minisign)
|
|
||||||
|
|
||||||
Swift implementation of Minisign, a simple and secure tool for signing and verifying files.
|
Swift implementation of Minisign, a simple and secure tool for signing and verifying files.
|
||||||
|
|
||||||
This is a fork of [slarew/swift-minisign](https://github.com/slarew/swift-minisign), with these improvements:
|
This is a fork of [slarew/swift-minisign](https://github.com/slarew/swift-minisign), with these improvements:
|
||||||
|
|
||||||
- Convenient & efficient API for verifying (big) files
|
- Convenient & efficient API for verifying (big) files
|
||||||
- `Sendable` conformance & full Swift 6 support
|
|
||||||
- Replaced C wrapping `swift-crypto-blake2` with [pure Swift implementation of blake2b](https://github.com/lovetodream/swift-blake2).
|
- Replaced C wrapping `swift-crypto-blake2` with [pure Swift implementation of blake2b](https://github.com/lovetodream/swift-blake2).
|
||||||
- For Apple platforms, Swift Crypto dependency is now optional, controllable via trait `UseSwiftCrypto`.
|
- For Apple platforms, Swift Crypto dependency is now optional, controllable via trait `UseSwiftCrypto`.
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,12 @@ import BLAKE2
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
#if UseSwiftCrypto
|
#if UseSwiftCrypto
|
||||||
@preconcurrency import Crypto
|
import Crypto
|
||||||
#else
|
#else
|
||||||
@preconcurrency import CryptoKit
|
import CryptoKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public enum SignatureAlgorithm: Sendable, RawRepresentable {
|
public enum SignatureAlgorithm: RawRepresentable {
|
||||||
case pureEdDSA
|
case pureEdDSA
|
||||||
case hashedEdDSA
|
case hashedEdDSA
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public enum SignatureAlgorithm: Sendable, RawRepresentable {
|
||||||
private let untrustedCommentHeader = "untrusted comment: ".data(using: .utf8)!
|
private let untrustedCommentHeader = "untrusted comment: ".data(using: .utf8)!
|
||||||
private let trustedCommentHeader = "trusted comment: ".data(using: .utf8)!
|
private let trustedCommentHeader = "trusted comment: ".data(using: .utf8)!
|
||||||
|
|
||||||
public struct PublicKey: Sendable {
|
public struct PublicKey {
|
||||||
public let untrustedComment: String
|
public let untrustedComment: String
|
||||||
public let signatureAlgorithm: SignatureAlgorithm
|
public let signatureAlgorithm: SignatureAlgorithm
|
||||||
public let keyID: Data
|
public let keyID: Data
|
||||||
|
@ -87,12 +87,13 @@ public struct PublicKey: Sendable {
|
||||||
///
|
///
|
||||||
/// This method reads the file in chunks to avoid loading the entire file into memory, but does so in a blocking manner.
|
/// This method reads the file in chunks to avoid loading the entire file into memory, but does so in a blocking manner.
|
||||||
/// It's recommended to use this method in a background thread or task.
|
/// It's recommended to use this method in a background thread or task.
|
||||||
public func isValidSignature(_ signature: Signature, forFileAt url: URL, bufferSize: Int = 8192) throws -> Bool {
|
public func isValidSignature(_ signature: Signature, forFileAt url: URL) throws -> Bool {
|
||||||
guard signature.signatureAlgorithm == .hashedEdDSA else { throw SignatureVerifyError.algorithmNotSupportedForFile }
|
guard signature.signatureAlgorithm == .hashedEdDSA else { throw SignatureVerifyError.algorithmNotSupportedForFile }
|
||||||
var blake2b = try! BLAKE2b()
|
var blake2b = try! BLAKE2b()
|
||||||
|
|
||||||
let fileHandle = try FileHandle(forReadingFrom: url)
|
let fileHandle = try FileHandle(forReadingFrom: url)
|
||||||
|
|
||||||
|
let bufferSize = 4096
|
||||||
while true {
|
while true {
|
||||||
let data = fileHandle.readData(ofLength: bufferSize)
|
let data = fileHandle.readData(ofLength: bufferSize)
|
||||||
if data.isEmpty { break }
|
if data.isEmpty { break }
|
||||||
|
@ -114,7 +115,7 @@ public struct PublicKey: Sendable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct Signature: Sendable {
|
public struct Signature {
|
||||||
public let untrustedComment: String
|
public let untrustedComment: String
|
||||||
public let signatureAlgorithm: SignatureAlgorithm
|
public let signatureAlgorithm: SignatureAlgorithm
|
||||||
public let keyID: Data
|
public let keyID: Data
|
||||||
|
|
Loading…
Add table
Reference in a new issue