]>
git.proxmox.com Git - cargo.git/blob - vendor/rand_os/src/dragonfly_haiku_emscripten.rs
1 // Copyright 2018 Developers of the Rand project.
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
9 //! Implementation for DragonFly / Haiku / Emscripten
12 use super::random_device
;
16 #[derive(Clone, Debug)]
19 impl OsRngImpl
for OsRng
{
20 fn new() -> Result
<OsRng
, Error
> {
21 random_device
::open("/dev/random", &|p
| File
::open(p
))?
;
25 fn fill_chunk(&mut self, dest
: &mut [u8]) -> Result
<(), Error
> {
26 random_device
::read(dest
)
29 #[cfg(target_os = "emscripten")]
30 fn max_chunk_size(&self) -> usize {
31 // `Crypto.getRandomValues` documents `dest` should be at most 65536
32 // bytes. `crypto.randomBytes` documents: "To minimize threadpool
33 // task length variation, partition large randomBytes requests when
34 // doing so as part of fulfilling a client request.
38 fn method_str(&self) -> &'
static str { "/dev/random" }