0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-12-06 14:52:41 +01:00

Initial commit

This commit is contained in:
Delta1925 2023-04-13 18:56:32 +02:00
commit 9c9f4793be
No known key found for this signature in database
GPG key ID: 1C21ACE44193CB25
7 changed files with 2935 additions and 0 deletions

30
src/utils.rs Normal file
View file

@ -0,0 +1,30 @@
use crate::VARIANT;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use sequoia_net::wkd::Url;
use sequoia_openpgp::{parse::Parse, Cert};
use std::path::PathBuf;
#[macro_export]
macro_rules! pending_path {
() => {
Path::new(PATH).join(PENDING)
};
}
pub fn parse_pem(data: &str) -> Cert {
sequoia_openpgp::Cert::from_bytes(data.as_bytes()).unwrap()
}
pub fn gen_random_token() -> String {
let mut rng = thread_rng();
(0..10).map(|_| rng.sample(Alphanumeric) as char).collect()
}
pub fn get_email_from_cert(cert: &Cert) -> String {
cert.userids().next().unwrap().email().unwrap().unwrap()
}
pub fn get_user_file_path(email: &str) -> PathBuf {
Url::from(email).unwrap().to_file_path(VARIANT).unwrap()
}