mirror of
https://github.com/laosb/swift-minisign.git
synced 2025-05-01 10:21:08 +00:00
Compare commits
No commits in common. "main" and "0.1.3" have entirely different histories.
4 changed files with 8 additions and 11 deletions
|
@ -27,7 +27,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 +44,5 @@ let package = Package(
|
||||||
name: "MinisignTests",
|
name: "MinisignTests",
|
||||||
dependencies: ["Minisign"]
|
dependencies: ["Minisign"]
|
||||||
),
|
),
|
||||||
],
|
]
|
||||||
swiftLanguageModes: [.v6]
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// swift-tools-version: 5.9
|
// swift-tools-version: 5.8
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ let package = Package(
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
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: [
|
|
@ -1,8 +1,5 @@
|
||||||
# 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:
|
||||||
|
|
|
@ -6,9 +6,9 @@ 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: Sendable, RawRepresentable {
|
||||||
|
@ -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 }
|
||||||
|
|
Loading…
Add table
Reference in a new issue