Skip to main content

vivacity_core/
lib.rs

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