mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2025-09-05 17:00:39 +00:00
feat: add note id size option
This commit is contained in:
@@ -30,6 +30,10 @@ lazy_static! {
|
||||
.unwrap_or("true".to_string())
|
||||
.parse()
|
||||
.unwrap();
|
||||
pub static ref ID_LENGTH: u32 = std::env::var("ID_LENGTH")
|
||||
.unwrap_or("32".to_string())
|
||||
.parse()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// THEME
|
||||
|
@@ -2,6 +2,8 @@ use bs62;
|
||||
use ring::rand::SecureRandom;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::config;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct Note {
|
||||
pub meta: String,
|
||||
@@ -22,8 +24,13 @@ pub struct NotePublic {
|
||||
}
|
||||
|
||||
pub fn generate_id() -> String {
|
||||
let mut id: [u8; 32] = [0; 32];
|
||||
let mut result = "".to_owned();
|
||||
let mut id: [u8; 1] = [0; 1];
|
||||
let sr = ring::rand::SystemRandom::new();
|
||||
let _ = sr.fill(&mut id);
|
||||
return bs62::encode_data(&id);
|
||||
|
||||
for _ in 0..*config::ID_LENGTH {
|
||||
let _ = sr.fill(&mut id);
|
||||
result.push_str(&bs62::encode_data(&id));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user