From b50135024df87ceb0e200b76ef1e214584816352 Mon Sep 17 00:00:00 2001 From: Josh <36625023+JoshuaBrest@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:58:15 -0800 Subject: [PATCH] fix: remove UnsafeRawBufferPointer and change hasher to var --- Sources/blake3-swift/blake3_swift.swift | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/blake3-swift/blake3_swift.swift b/Sources/blake3-swift/blake3_swift.swift index caf0eb9..426795f 100644 --- a/Sources/blake3-swift/blake3_swift.swift +++ b/Sources/blake3-swift/blake3_swift.swift @@ -2,7 +2,9 @@ import Foundation import blake3_c public final class Blake3 { - private let hasher: blake3_hasher + private static let BLAKE3_OUT_LENGTH: Int = Int(BLAKE3_OUT_LEN) + + private var hasher: blake3_hasher public init() { hasher = blake3_hasher() @@ -14,21 +16,19 @@ public final class Blake3 { } public func update(buffer: [UInt8]) { - update(bytes: buffer) + buffer.withUnsafeBufferPointer { ptr in + update(bytes: UnsafeRawBufferPointer(ptr)) + } } public func update(data: Data) { update(bytes: data.withUnsafeBytes { $0 }) } - public func finalizeBytes() -> UnsafeRawBufferPointer { - var out = [UInt8](repeating: 0, count: BLAKE3_OUT_LEN) - blake3_hasher_finalize(&hasher, &out, BLAKE3_OUT_LEN) - return UnsafeRawBufferPointer(start: out, count: BLAKE3_OUT_LEN) - } - - public func finalizeBuffer() -> [UInt8] { - return finalizeBytes().bindMemory(to: UInt8.self).map { $0 } + public func finalizeBytes() -> [UInt8] { + var out = [UInt8](repeating: 0, count: Blake3.BLAKE3_OUT_LENGTH) + blake3_hasher_finalize(&hasher, &out, Blake3.BLAKE3_OUT_LENGTH) + return out } public func finalizeData() -> Data {