authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-07 10:59:44-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-07 11:03:37-08:00
log5d0929c40dcb0456cbef88fe10197af81e984142
tree3670b522bc6de68da95081ddde76f3b69afde749
parent5e5b328dacb23e0804f05e0e1228f1671001d7ff

std.Io.Threaded.randomSecure: eliminate dead code


1 files changed, 6 insertions(+), 9 deletions(-)

lib/std/Io/Threaded.zig+6-9
...@@ -15284,9 +15284,9 @@ fn fallbackSeedWasi(seed: *[Csprng.seed_len]u8) void {...@@ -15284,9 +15284,9 @@ fn fallbackSeedWasi(seed: *[Csprng.seed_len]u8) void {
1528415284
15285fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {15285fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {
15286 const t: *Threaded = @ptrCast(@alignCast(userdata));15286 const t: *Threaded = @ptrCast(@alignCast(userdata));
15287 if (buffer.len == 0) return;
1528815287
15289 if (is_windows) {15288 if (is_windows) {
15289 if (buffer.len == 0) return;
15290 // ProcessPrng from bcryptprimitives.dll has the following properties:15290 // ProcessPrng from bcryptprimitives.dll has the following properties:
15291 // * introduces a dependency on bcryptprimitives.dll, which apparently15291 // * introduces a dependency on bcryptprimitives.dll, which apparently
15292 // runs a test suite every time it is loaded15292 // runs a test suite every time it is loaded
...@@ -15331,11 +15331,13 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {...@@ -15331,11 +15331,13 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {
15331 }15331 }
1533215332
15333 if (builtin.link_libc and @TypeOf(posix.system.arc4random_buf) != void) {15333 if (builtin.link_libc and @TypeOf(posix.system.arc4random_buf) != void) {
15334 if (buffer.len == 0) return;
15334 posix.system.arc4random_buf(buffer.ptr, buffer.len);15335 posix.system.arc4random_buf(buffer.ptr, buffer.len);
15335 return;15336 return;
15336 }15337 }
1533715338
15338 if (native_os == .wasi) {15339 if (native_os == .wasi) {
15340 if (buffer.len == 0) return;
15339 const syscall: Syscall = try .start();15341 const syscall: Syscall = try .start();
15340 while (true) switch (std.os.wasi.random_get(buffer.ptr, buffer.len)) {15342 while (true) switch (std.os.wasi.random_get(buffer.ptr, buffer.len)) {
15341 .SUCCESS => return syscall.finish(),15343 .SUCCESS => return syscall.finish(),
...@@ -15351,7 +15353,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {...@@ -15351,7 +15353,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {
15351 const getrandom = if (use_libc_getrandom) std.c.getrandom else std.os.linux.getrandom;15353 const getrandom = if (use_libc_getrandom) std.c.getrandom else std.os.linux.getrandom;
15352 var i: usize = 0;15354 var i: usize = 0;
15353 const syscall: Syscall = try .start();15355 const syscall: Syscall = try .start();
15354 while (i < buffer.len) {15356 while (buffer.len - i != 0) {
15355 const buf = buffer[i..];15357 const buf = buffer[i..];
15356 const rc = getrandom(buf.ptr, buf.len, 0);15358 const rc = getrandom(buf.ptr, buf.len, 0);
15357 switch (posix.errno(rc)) {15359 switch (posix.errno(rc)) {
...@@ -15372,6 +15374,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {...@@ -15372,6 +15374,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {
15372 }15374 }
1537315375
15374 if (native_os == .emscripten) {15376 if (native_os == .emscripten) {
15377 if (buffer.len == 0) return;
15375 const err = posix.errno(std.c.getentropy(buffer.ptr, buffer.len));15378 const err = posix.errno(std.c.getentropy(buffer.ptr, buffer.len));
15376 switch (err) {15379 switch (err) {
15377 .SUCCESS => return,15380 .SUCCESS => return,
...@@ -15391,13 +15394,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {...@@ -15391,13 +15394,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void {
15391 .SUCCESS => {15394 .SUCCESS => {
15392 syscall.finish();15395 syscall.finish();
15393 const n: usize = @intCast(rc);15396 const n: usize = @intCast(rc);
15394 if (n == 0) {15397 if (n == 0) return error.EntropyUnavailable;
15395 if (buffer.len - i != 0) {
15396 return error.EntropyUnavailable;
15397 } else {
15398 return;
15399 }
15400 }
15401 i += n;15398 i += n;
15402 continue;15399 continue;
15403 },15400 },