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: on:
push: push:
branches: ["main"] branches: ["master"]
pull_request: pull_request:
branches: ["main"] branches: ["master"]
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always

View File

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

View File

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