try this string formatter

This commit is contained in:
Cappy Ishihara 2024-06-02 01:09:58 +07:00
parent d7f04e7a9f
commit 4e63f7ce7a
No known key found for this signature in database
GPG key ID: 50862C285CB76906

View file

@ -1,10 +1,9 @@
use std::{fs::File, io::Read};
use base64::prelude::*;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use ring::digest::{self, digest};
use uuid::Uuid;
use base64::prelude::*;
// Кор функции
pub fn rand() -> [u8; 50] {
@ -16,31 +15,34 @@ pub fn rand() -> [u8; 50] {
}
nums
}
//? What is this guy doing
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 { // FIXME: Variable doesn't using!
pub fn _generate_hex_string(length: usize) -> String {
// FIXME: Variable doesn't using!
let rng = thread_rng();
let random_bytes: Vec<u8> = rng
.sample_iter(&Alphanumeric)
.take(length / 2)
.collect();
let random_bytes: Vec<u8> = rng.sample_iter(&Alphanumeric).take(length / 2).collect();
hex::encode(random_bytes)
}
pub fn get_correct_array(value: &toml::Value) -> 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 {
// let uuid = Uuid::parse_str(&uuid)?; TODO: Вероятно format_uuid стоит убрать
// .map_err(|_| tide::Error::from_str(StatusCode::InternalServerError, "Failed to parse UUID"))?;
// .map_err(|_| tide::Error::from_str(StatusCode::InternalServerError, "Failed to parse UUID"))?;
uuid.as_hyphenated().to_string()
}
@ -61,4 +63,4 @@ pub fn calculate_file_sha256(file_path: &str) -> Result<String, std::io::Error>
let hex_hash = bytes_into_string(hash);
Ok(hex_hash)
}
}