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.
65 lines
1.8 KiB
Swift
65 lines
1.8 KiB
Swift
//
|
|
// Copyright 2020-2021 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import SignalFfi
|
|
import Foundation
|
|
|
|
public struct IdentityKey: Equatable {
|
|
public let publicKey: PublicKey
|
|
|
|
public init(publicKey: PublicKey) {
|
|
self.publicKey = publicKey
|
|
}
|
|
|
|
public init<Bytes: ContiguousBytes>(bytes: Bytes) throws {
|
|
publicKey = try PublicKey(bytes)
|
|
}
|
|
|
|
public func serialize() -> [UInt8] {
|
|
return publicKey.serialize()
|
|
}
|
|
}
|
|
|
|
public struct IdentityKeyPair {
|
|
public let publicKey: PublicKey
|
|
public let privateKey: PrivateKey
|
|
|
|
public static func generate() -> IdentityKeyPair {
|
|
let privateKey = PrivateKey.generate()
|
|
let publicKey = privateKey.publicKey
|
|
return IdentityKeyPair(publicKey: publicKey, privateKey: privateKey)
|
|
}
|
|
|
|
public init<Bytes: ContiguousBytes>(bytes: Bytes) throws {
|
|
var pubkeyPtr: OpaquePointer?
|
|
var privkeyPtr: OpaquePointer?
|
|
try bytes.withUnsafeBytes {
|
|
try checkError(signal_identitykeypair_deserialize(&privkeyPtr, &pubkeyPtr, $0.baseAddress?.assumingMemoryBound(to: UInt8.self), $0.count))
|
|
}
|
|
|
|
publicKey = PublicKey(owned: pubkeyPtr!)
|
|
privateKey = PrivateKey(owned: privkeyPtr!)
|
|
}
|
|
|
|
public init(publicKey: PublicKey, privateKey: PrivateKey) {
|
|
self.publicKey = publicKey
|
|
self.privateKey = privateKey
|
|
}
|
|
|
|
public func serialize() -> [UInt8] {
|
|
return withNativeHandles(publicKey, privateKey) { publicKey, privateKey in
|
|
failOnError {
|
|
try invokeFnReturningArray {
|
|
signal_identitykeypair_serialize($0, $1, publicKey, privateKey)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public var identityKey: IdentityKey {
|
|
return IdentityKey(publicKey: publicKey)
|
|
}
|
|
}
|