Signal-iOS/SignalMessaging/groups/GroupsV2Utils.swift
2022-03-24 11:55:45 -07:00

30 lines
887 B
Swift

//
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
//
import Foundation
import SignalServiceKit
import LibSignalClient
public extension UUID {
var data: Data {
return withUnsafeBytes(of: self.uuid, { Data($0) })
}
}
// MARK: -
public extension ProfileKeyVersion {
// GroupsV2 TODO: We might move this to the wrappers.
func asHexadecimalString() throws -> String {
let profileKeyVersionData = serialize().asData
// A peculiarity of ProfileKeyVersion is that its contents
// are an ASCII-encoded hexadecimal string of the profile key
// version, rather than the raw version bytes.
guard let profileKeyVersionString = String(data: profileKeyVersionData, encoding: .ascii) else {
throw OWSAssertionError("Invalid profile key version.")
}
return profileKeyVersionString
}
}