mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-05 10:49:40 +02:00
Almost eliminate util module
This commit is contained in:
parent
9378ae5b6f
commit
e688e7e886
9 changed files with 59 additions and 67 deletions
|
@ -1,50 +1,4 @@
|
|||
use num_bigint::BigUint;
|
||||
use num_integer::Integer;
|
||||
use num_traits::{One, Zero};
|
||||
use rand::Rng;
|
||||
use std::mem;
|
||||
use std::ops::{Mul, Rem, Shr};
|
||||
|
||||
pub fn rand_vec<G: Rng>(rng: &mut G, size: usize) -> Vec<u8> {
|
||||
::std::iter::repeat(())
|
||||
.map(|()| rng.gen())
|
||||
.take(size)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn url_encode(inp: &str) -> String {
|
||||
let mut encoded = String::new();
|
||||
|
||||
for c in inp.as_bytes().iter() {
|
||||
match *c as char {
|
||||
'A'..='Z' | 'a'..='z' | '0'..='9' | '-' | '_' | '.' | '~' | ':' | '/' => {
|
||||
encoded.push(*c as char)
|
||||
}
|
||||
c => encoded.push_str(format!("%{:02X}", c as u32).as_str()),
|
||||
};
|
||||
}
|
||||
|
||||
encoded
|
||||
}
|
||||
|
||||
pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint {
|
||||
let mut base = base.clone();
|
||||
let mut exp = exp.clone();
|
||||
let mut result: BigUint = One::one();
|
||||
|
||||
while !exp.is_zero() {
|
||||
if exp.is_odd() {
|
||||
result = result.mul(&base).rem(modulus);
|
||||
}
|
||||
exp = exp.shr(1);
|
||||
base = (&base).mul(&base).rem(modulus);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub trait ReadSeek: ::std::io::Read + ::std::io::Seek {}
|
||||
impl<T: ::std::io::Read + ::std::io::Seek> ReadSeek for T {}
|
||||
|
||||
pub trait Seq {
|
||||
fn next(&self) -> Self;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue