This commit is contained in:
2026-01-22 23:33:14 -05:00
parent ace356381a
commit bcbd6cb6c8
8 changed files with 180 additions and 77 deletions

View File

@@ -4,6 +4,7 @@ mod no_cert;
mod transfer;
pub use no_cert::*;
use rand::{TryRngCore, rngs::OsRng};
pub use transfer::*;
pub const SERVER_NAME: &str = "openworm";
@@ -13,8 +14,15 @@ pub const BINCODE_CONFIG: Configuration = bincode::config::standard();
pub enum ClientMsg {
SendMsg(NetClientMsg),
RequestMsgs,
CreateAccount { username: String, password: String },
Login { username: String, password: String },
CreateAccount {
username: String,
password: String,
device: LoginKey,
},
Login {
username: String,
password: String,
},
}
#[derive(Debug, bincode::Encode, bincode::Decode)]
@@ -63,3 +71,26 @@ pub fn install_crypto_provider() {
.install_default()
.unwrap();
}
#[derive(Debug, bincode::Encode, bincode::Decode)]
pub struct LoginKey([u8; LoginKey::BYTE_LEN]);
impl LoginKey {
pub const BIT_LEN: usize = 1024;
pub const BYTE_LEN: usize = Self::BIT_LEN / 8;
pub fn new() -> Self {
let mut key = [0u8; Self::BYTE_LEN];
OsRng
.try_fill_bytes(&mut key)
.expect("failed to generate random key");
Self(key)
}
}
impl TryFrom<Vec<u8>> for LoginKey {
type Error = ();
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
Ok(Self(value.try_into().map_err(|_| ())?))
}
}