Skip to content

Commit 0e3f39a

Browse files
committed
fix(swift): give some closures their return types
Signed-off-by: Skyler Ross <[email protected]>
1 parent 5e4a09d commit 0e3f39a

File tree

4 files changed

+6
-10
lines changed

4 files changed

+6
-10
lines changed

sdk/swift/Sources/Hedera/Data+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension Data {
4545
// safety: `hedera_bytes_free` needs to be called so...
4646
// perf: might as well enable use of the no copy constructor.
4747
internal static let unsafeCHederaBytesFree: Data.Deallocator = .custom { (buf, size) in
48-
hedera_bytes_free(buf, size)
48+
hedera_bytes_free(buf.bindMemory(to: UInt8.self, capacity: size), size)
4949
}
5050

5151
private static let hexAlphabet = Array("0123456789abcdef".unicodeScalars)

sdk/swift/Sources/Hedera/PrivateKey.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,16 @@ public final class PrivateKey: LosslessStringConvertible, ExpressibleByStringLit
5454
}
5555

5656
private static func unsafeFromAnyBytes(_ bytes: Data, _ chederaCallback: UnsafeFromBytesFunc) throws -> Self {
57-
let ptr = try bytes.withUnsafeTypedBytes { pointer in
57+
try bytes.withUnsafeTypedBytes { pointer -> Self in
5858
var key: OpaquePointer? = nil
5959
let err = chederaCallback(pointer.baseAddress, pointer.count, &key)
6060

6161
if err != HEDERA_ERROR_OK {
6262
throw HError(err)!
6363
}
6464

65-
return key!
65+
return Self(key!)
6666
}
67-
68-
return Self(ptr)
6967
}
7068

7169
public static func fromBytes(_ bytes: Data) throws -> Self {

sdk/swift/Sources/Hedera/PublicKey.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,16 @@ public final class PublicKey: LosslessStringConvertible, ExpressibleByStringLite
4141
}
4242

4343
private static func unsafeFromAnyBytes(_ bytes: Data, _ chederaCallback: UnsafeFromBytesFunc) throws -> Self {
44-
let ptr = try bytes.withUnsafeTypedBytes { pointer in
44+
try bytes.withUnsafeTypedBytes { pointer -> Self in
4545
var key: OpaquePointer? = nil
4646
let err = chederaCallback(pointer.baseAddress, pointer.count, &key)
4747

4848
if err != HEDERA_ERROR_OK {
4949
throw HError(err)!
5050
}
5151

52-
return key!
52+
return Self(key!)
5353
}
54-
55-
return Self(ptr)
5654
}
5755

5856
public static func fromBytes(_ bytes: Data) throws -> Self {

sdk/swift/Sources/Hedera/Signer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func sign(
1313
let signatureData = signer.signFunc(messageData)
1414

1515
// raw pointer timeeee (yes, we do need to double copy.)
16-
let buffer = signatureData.withUnsafeBytes { dataBuffer in
16+
let buffer = signatureData.withUnsafeBytes { dataBuffer -> UnsafeMutableBufferPointer<UInt8> in
1717
let buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: dataBuffer.count, alignment: 1)
1818
buffer.copyBytes(from: dataBuffer)
1919
return buffer.bindMemory(to: UInt8.self)

0 commit comments

Comments
 (0)