mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 12:02:18 +02:00
Tweaks the Swift interface for HSM Enclave Client
- Fixes an issue where a call to decrypt would instead re-encrypt the ciphertext. - Tweaks the interface for the initializer to instead take raw public key bytes. This matches the java interface. Framework clients have no way to construct a PublicKey from raw bytes.
This commit is contained in:
parent
4bd3778e69
commit
e2fe069d38
@ -49,17 +49,19 @@ public struct HsmCodeHashList {
|
||||
///
|
||||
public class HsmEnclaveClient: NativeHandleOwner {
|
||||
|
||||
public convenience init(publicKey: PublicKey, codeHashes: HsmCodeHashList) throws {
|
||||
public convenience init<Bytes: ContiguousBytes>(publicKey: Bytes, codeHashes: HsmCodeHashList) throws {
|
||||
let codeHashBytes = codeHashes.flatten()
|
||||
|
||||
let handle: OpaquePointer? = try codeHashBytes.withUnsafeBytes { bytes in
|
||||
var result: OpaquePointer?
|
||||
try checkError(signal_hsm_enclave_client_new(&result,
|
||||
publicKey.keyBytes,
|
||||
publicKey.keyBytes.count,
|
||||
bytes.baseAddress?.assumingMemoryBound(to: UInt8.self),
|
||||
bytes.count))
|
||||
return result
|
||||
let handle: OpaquePointer? = try publicKey.withUnsafeBytes { publicKeyBytes in
|
||||
try codeHashBytes.withUnsafeBytes { codeHashBytes in
|
||||
var result: OpaquePointer?
|
||||
try checkError(signal_hsm_enclave_client_new(&result,
|
||||
publicKeyBytes.baseAddress?.assumingMemoryBound(to: UInt8.self),
|
||||
publicKeyBytes.count,
|
||||
codeHashBytes.baseAddress?.assumingMemoryBound(to: UInt8.self),
|
||||
codeHashBytes.count))
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
self.init(owned: handle!)
|
||||
@ -103,7 +105,7 @@ public class HsmEnclaveClient: NativeHandleOwner {
|
||||
return try withNativeHandle { nativeHandle in
|
||||
try receivedCiphertext.withUnsafeBytes { bytes in
|
||||
try invokeFnReturningArray {
|
||||
signal_hsm_enclave_client_established_send($0, $1, nativeHandle, bytes.baseAddress?.assumingMemoryBound(to: UInt8.self), bytes.count)
|
||||
signal_hsm_enclave_client_established_recv($0, $1, nativeHandle, bytes.baseAddress?.assumingMemoryBound(to: UInt8.self), bytes.count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user