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 package_versions;
20pub mod path_install;
21pub mod pathutil;
22pub mod pest_plugin;
23pub mod phparray;
24pub mod phpcs_installer;
25pub mod phpjson;
26pub mod phpserialize;
27pub mod platform;
28pub mod root_version;
29pub mod runtime_stub;
30pub mod scope;
31pub mod state;
32pub mod store;
33pub mod version;
34pub mod yii2_composer;
35
36pub use error::{Error, Result};
37
38/// `random_bytes($n)` for the few places Composer draws randomness (the
39/// APCu prefix): the OS entropy source, or the hasher seed as a fallback.
40pub fn random_bytes(n: usize) -> Vec<u8> {
41    let mut out = vec![0u8; n];
42    #[cfg(unix)]
43    {
44        use std::io::Read as _;
45        if let Ok(mut f) = std::fs::File::open("/dev/urandom") {
46            if f.read_exact(&mut out).is_ok() {
47                return out;
48            }
49        }
50    }
51    use std::hash::{BuildHasher as _, Hasher as _};
52    let mut i = 0;
53    while i < n {
54        let word = std::collections::hash_map::RandomState::new()
55            .build_hasher()
56            .finish();
57        for b in word.to_le_bytes() {
58            if i < n {
59                out[i] = b;
60                i += 1;
61            }
62        }
63    }
64    out
65}