//===----------------------------------------------------------------------===// // // This source file is part of the SwiftCertificates open source project // // Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors // Licensed under Apache License v2.0 // // See LICENSE.txt for license information // See CONTRIBUTORS.txt for the list of SwiftCertificates project authors // // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// extension RandomNumberGenerator { @inlinable internal mutating func bytes(count: Int) -> ArraySlice { precondition(count >= 0) var bytes = [UInt8]() while bytes.count < count { bytes.appendLittleEndianBytes(self.next()) } return bytes[...size) { let shifted = number >> (byte * 8) self.append(UInt8(truncatingIfNeeded: shifted)) } } }