Files
libsignal/swift/Sources/LibSignalClient/zkgroup/Randomness.swift
Jordan Rose 9e13263581 Switch to swift-format for formatting instead of swiftformat
swift-format is owned by the Swift project and is generally less
opinionated than swiftformat (but better at formatting to a limited
line length).
2025-06-25 11:24:57 -07:00

31 lines
826 B
Swift

//
// Copyright 2021 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
public struct Randomness: Sendable {
public var bytes: SignalRandomnessBytes
public init(_ bytes: SignalRandomnessBytes) {
self.bytes = bytes
}
static func generate() throws -> Randomness {
var bytes: SignalRandomnessBytes = (
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
)
try withUnsafeMutableBytes(of: &bytes) {
try fillRandom($0)
}
return Randomness(bytes)
}
func withUnsafePointerToBytes<Result>(
_ callback: (UnsafePointer<SignalRandomnessBytes>) throws -> Result
) rethrows -> Result {
try withUnsafePointer(to: self.bytes, callback)
}
}