Skip to main content

vivacity_core/
lib.rs

1//! vivacity-core: manifests, platform, fetch and installation.
2
3pub mod binproxy;
4pub mod clone;
5pub mod constraint;
6pub mod content_hash;
7pub mod error;
8pub mod extract;
9pub mod fetch;
10pub mod glob;
11pub mod installer;
12pub mod installers;
13pub mod layout;
14pub mod lock;
15pub mod path_install;
16pub mod pathutil;
17pub mod pest_plugin;
18pub mod phpcs_installer;
19pub mod phpjson;
20pub mod phpserialize;
21pub mod platform;
22pub mod root_version;
23pub mod runtime_stub;
24pub mod scope;
25pub mod state;
26pub mod store;
27pub mod version;
28
29pub use error::{Error, Result};
30
31/// `random_bytes($n)` for the few places Composer draws randomness (the
32/// APCu prefix): the OS entropy source, or the hasher seed as a fallback.
33pub fn random_bytes(n: usize) -> Vec<u8> {
34    let mut out = vec![0u8; n];
35    #[cfg(unix)]
36    {
37        use std::io::Read as _;
38        if let Ok(mut f) = std::fs::File::open("/dev/urandom") {
39            if f.read_exact(&mut out).is_ok() {
40                return out;
41            }
42        }
43    }
44    use std::hash::{BuildHasher as _, Hasher as _};
45    let mut i = 0;
46    while i < n {
47        let word = std::collections::hash_map::RandomState::new()
48            .build_hasher()
49            .finish();
50        for b in word.to_le_bytes() {
51            if i < n {
52                out[i] = b;
53                i += 1;
54            }
55        }
56    }
57    out
58}