Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Why not a fill()-type API? #27

@xfbs

Description

@xfbs

Hey guys! Awesome work here. I'm working on passgen in my free time and I'm trying to make this work well within WASM/WASI. For that, I obviously need access to good random data. Right now, I'm using Linux's getrandom() and arc4_random() on macOS. So much for context.

In my code, I have a ring buffer of random data that I use up and then replenish by filling it with random data, overwriting what was in it previously. Hence my question: why not a fill()-style API?

let bytes: Vec<u8> = get_random_bytes(len);

vs

let mut bytes: Vec<u8> = Vec::new();
fill_random_bytes(&mut bytes[..]);

I might be missing something here — kind of new to this WASM/WASI thing. Please excuse me if this does not make sense.

The advantage of this would obviously be that I don't need to create a new buffer of random data every time, but I can just have one buffer around. The other advantage is that by continuously overwriting the random data, you can't accidentally leak it, like you could with new allocations. This might not be an issue for WebAssembly, however.

Cheers,
Patrick

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions