Files
libsignal/swift/Sources/LibSignalClient/zkgroup/ProfileKey.swift
Jordan Rose 6a547bf3f2 zkgroup: Use ServiceId and Aci in public APIs instead of UidBytes
Some of these APIs have to match up with UuidCiphertexts, and so we
convert them all for consistency.
2023-07-20 12:26:46 -07:00

48 lines
1.2 KiB
Swift

//
// Copyright 2020-2021 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
import SignalFfi
public class ProfileKey: ByteArray {
public static let SIZE: Int = 32
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: ProfileKey.SIZE)
}
public func getCommitment(userId: Aci) throws -> ProfileKeyCommitment {
return try withUnsafePointerToSerialized { contents in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_profile_key_get_commitment($0, contents, userId)
}
}
}
}
public func getProfileKeyVersion(userId: Aci) throws -> ProfileKeyVersion {
return try withUnsafePointerToSerialized { contents in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_profile_key_get_profile_key_version($0, contents, userId)
}
}
}
}
public func deriveAccessKey() -> [UInt8] {
return failOnError {
try withUnsafePointerToSerialized { contents in
try invokeFnReturningFixedLengthArray {
signal_profile_key_derive_access_key($0, contents)
}
}
}
}
}