| ... | ... | @@ -406,3 +406,17 @@ pub const AllocatingWriter = @import("./allocating_writer.zig").AllocatingWriter |
| 406 | 406 | pub const CountingReader = @import("./counting_reader.zig").CountingReader; |
| 407 | 407 | |
| 408 | 408 | pub const LimitedReader = @import("./limited_reader.zig").LimitedReader; |
| 409 | |
| 410 | pub const crypto_random: std.Random = .{ |
| 411 | .ptr = undefined, |
| 412 | .fillFn = getrandomFill, |
| 413 | }; |
| 414 | fn getrandomFill(_: *anyopaque, buffer: []u8) void { |
| 415 | _ = sys.getrandom(buffer, 0) catch unreachable; |
| 416 | } |
| 417 | |
| 418 | pub fn randomBytes(comptime len: usize) [len]u8 { |
| 419 | var bytes: [len]u8 = undefined; |
| 420 | crypto_random.bytes(&bytes); |
| 421 | return bytes; |
| 422 | } |