mirror of
https://github.com/laosb/swift-minisign.git
synced 2025-04-30 18:01:08 +00:00
feat: Add configurable buffer size for file signature verification
This commit is contained in:
parent
e10a2449c8
commit
d2657b54f3
1 changed files with 1 additions and 2 deletions
|
@ -87,13 +87,12 @@ 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.
|
||||
/// It's recommended to use this method in a background thread or task.
|
||||
public func isValidSignature(_ signature: Signature, forFileAt url: URL) throws -> Bool {
|
||||
public func isValidSignature(_ signature: Signature, forFileAt url: URL, bufferSize: Int = 8192) throws -> Bool {
|
||||
guard signature.signatureAlgorithm == .hashedEdDSA else { throw SignatureVerifyError.algorithmNotSupportedForFile }
|
||||
var blake2b = try! BLAKE2b()
|
||||
|
||||
let fileHandle = try FileHandle(forReadingFrom: url)
|
||||
|
||||
let bufferSize = 4096
|
||||
while true {
|
||||
let data = fileHandle.readData(ofLength: bufferSize)
|
||||
if data.isEmpty { break }
|
||||
|
|
Loading…
Add table
Reference in a new issue