keygen to crypto module & fixed CI branch naming

This commit is contained in:
17ms 2023-04-11 23:26:50 +03:00
parent f1bb0049da
commit 66dec81364
3 changed files with 11 additions and 11 deletions

View File

@ -2,9 +2,9 @@ name: Cargo Build & Test
on:
push:
branches: ["main"]
branches: ["master"]
pull_request:
branches: ["main"]
branches: ["master"]
env:
CARGO_TERM_COLOR: always

View File

@ -4,6 +4,7 @@ use aes_gcm::{
aes::Aes256,
Aes256Gcm, AesGcm, KeyInit, Nonce,
};
use rand::{distributions::Alphanumeric, Rng};
use rand::{rngs::OsRng, RngCore};
use std::{error::Error, path::Path};
use tokio::{
@ -87,6 +88,14 @@ pub fn try_hash(path: &String) -> Result<String, Box<dyn Error + Send + Sync>> {
Ok(hash)
}
pub fn keygen() -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect::<String>()
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -2,7 +2,6 @@ use crate::{
common::{Connection, Message},
comms, crypto,
};
use rand::{distributions::Alphanumeric, Rng};
use std::{collections::HashMap, error::Error, net::SocketAddr, path::PathBuf, str::FromStr};
use tokio::{
fs::File,
@ -218,11 +217,3 @@ impl Listener {
Ok(())
}
}
pub fn keygen() -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect::<String>()
}