1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#![doc = include_str!("../README.md")]
use rand::rngs::OsRng;
use rand::RngCore;
#[macro_use]
mod macros;
#[cfg(feature = "cipher")]
pub mod cipher;
#[cfg(feature = "signature")]
pub mod signature;
#[cfg(feature = "hash")]
pub mod hash;
pub fn xor(buf: &mut [u8], key: &[u8]) {
assert_eq!(buf.len(), key.len());
for (a, b) in buf.iter_mut().zip(key) {
*a ^= *b;
}
}
pub fn fill_random(buf: &mut [u8]) {
OsRng.fill_bytes(buf)
}
#[cfg(feature = "b64")]
#[derive(Debug, Clone)]
pub enum FromBase64Error {
LengthNot32Bytes,
LengthNot64Bytes,
Base64(base64::DecodeError)
}
#[cfg(feature = "b64")]
impl From<base64::DecodeError> for FromBase64Error {
fn from(e: base64::DecodeError) -> Self {
Self::Base64(e)
}
}