Expand Shadowsocks runtime compatibility
This commit is contained in:
parent
d1638726ca
commit
4d1f589280
167 changed files with 57173 additions and 1640 deletions
30
third_party/rustls-fork-shadow-tls/src/rand.rs
vendored
Normal file
30
third_party/rustls-fork-shadow-tls/src/rand.rs
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use crate::msgs::codec;
|
||||
/// The single place where we generate random material
|
||||
/// for our own use. These functions never fail,
|
||||
/// they panic on error.
|
||||
use ring::rand::{SecureRandom, SystemRandom};
|
||||
|
||||
/// Fill the whole slice with random material.
|
||||
pub(crate) fn fill_random(bytes: &mut [u8]) -> Result<(), GetRandomFailed> {
|
||||
SystemRandom::new()
|
||||
.fill(bytes)
|
||||
.map_err(|_| GetRandomFailed)
|
||||
}
|
||||
|
||||
/// Make a Vec<u8> of the given size
|
||||
/// containing random material.
|
||||
pub(crate) fn random_vec(len: usize) -> Result<Vec<u8>, GetRandomFailed> {
|
||||
let mut v = vec![0; len];
|
||||
fill_random(&mut v)?;
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
/// Return a uniformly random u32.
|
||||
pub(crate) fn random_u32() -> Result<u32, GetRandomFailed> {
|
||||
let mut buf = [0u8; 4];
|
||||
fill_random(&mut buf)?;
|
||||
codec::decode_u32(&buf).ok_or(GetRandomFailed)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GetRandomFailed;
|
||||
Loading…
Add table
Add a link
Reference in a new issue