mirror of
https://github.com/signalapp/libsignal.git
synced 2026-04-25 17:25:18 +02:00
...to have a period after "Signal Messenger, LLC." ...except for the Java sources, which still need a cleanup pass.
39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
//
|
|
// Copyright 2021 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import SignalFfi
|
|
import Foundation
|
|
|
|
public struct DeviceTransferKey {
|
|
public let privateKey: [UInt8]
|
|
|
|
public static func generate() -> Self {
|
|
let privateKey = failOnError {
|
|
try invokeFnReturningArray {
|
|
signal_device_transfer_generate_private_key($0, $1)
|
|
}
|
|
}
|
|
|
|
return Self(privateKey: privateKey)
|
|
}
|
|
|
|
public func privateKeyMaterial() -> [UInt8] {
|
|
return self.privateKey
|
|
}
|
|
|
|
public func generateCertificate(_ name: String, _ daysTilExpire: Int) -> [UInt8] {
|
|
return privateKey.withUnsafeBytes { privateKeyBytes in
|
|
failOnError {
|
|
try invokeFnReturningArray {
|
|
signal_device_transfer_generate_certificate($0, $1,
|
|
privateKeyBytes.baseAddress?.assumingMemoryBound(to: UInt8.self),
|
|
privateKeyBytes.count,
|
|
name, UInt32(daysTilExpire))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|