mirror of
https://github.com/shiroyashik/sculptor.git
synced 2025-12-06 13:01:12 +03:00
try this string formatter
This commit is contained in:
parent
d7f04e7a9f
commit
4e63f7ce7a
1 changed files with 15 additions and 13 deletions
24
src/utils.rs
24
src/utils.rs
|
|
@ -1,10 +1,9 @@
|
||||||
use std::{fs::File, io::Read};
|
use std::{fs::File, io::Read};
|
||||||
|
|
||||||
|
use base64::prelude::*;
|
||||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||||
use ring::digest::{self, digest};
|
use ring::digest::{self, digest};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use base64::prelude::*;
|
|
||||||
|
|
||||||
|
|
||||||
// Кор функции
|
// Кор функции
|
||||||
pub fn rand() -> [u8; 50] {
|
pub fn rand() -> [u8; 50] {
|
||||||
|
|
@ -16,26 +15,29 @@ pub fn rand() -> [u8; 50] {
|
||||||
}
|
}
|
||||||
nums
|
nums
|
||||||
}
|
}
|
||||||
|
//? What is this guy doing
|
||||||
pub fn bytes_into_string(code: &[u8]) -> String {
|
pub fn bytes_into_string(code: &[u8]) -> String {
|
||||||
code.iter().map(|byte| format!("{:02x}", byte)).collect::<String>()
|
// code.iter().map(|byte| format!("{:02x}", byte)).collect::<String>() // ????? Why do you need this? Why not just String::from_utf8()??
|
||||||
|
String::from_utf8(code.to_vec()).unwrap() // Unwrap might be unsafe here...
|
||||||
}
|
}
|
||||||
// Конец кор функций
|
// Конец кор функций
|
||||||
|
|
||||||
|
pub fn _generate_hex_string(length: usize) -> String {
|
||||||
pub fn _generate_hex_string(length: usize) -> String { // FIXME: Variable doesn't using!
|
// FIXME: Variable doesn't using!
|
||||||
let rng = thread_rng();
|
let rng = thread_rng();
|
||||||
let random_bytes: Vec<u8> = rng
|
let random_bytes: Vec<u8> = rng.sample_iter(&Alphanumeric).take(length / 2).collect();
|
||||||
.sample_iter(&Alphanumeric)
|
|
||||||
.take(length / 2)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
hex::encode(random_bytes)
|
hex::encode(random_bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_correct_array(value: &toml::Value) -> Vec<u8> {
|
pub fn get_correct_array(value: &toml::Value) -> Vec<u8> {
|
||||||
// let res: Vec<u8>;
|
// let res: Vec<u8>;
|
||||||
value.as_array().unwrap().iter().map(move |x| x.as_integer().unwrap() as u8).collect()
|
value
|
||||||
|
.as_array()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(move |x| x.as_integer().unwrap() as u8)
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_uuid(uuid: &Uuid) -> String {
|
pub fn format_uuid(uuid: &Uuid) -> String {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue