add lib crate

This commit is contained in:
Joe Ardent 2023-05-12 12:08:18 -07:00
parent 61520964ec
commit d9aee1a87f
5 changed files with 823 additions and 24 deletions

796
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,4 +15,11 @@ tower = { version = "0.4", features = ["util", "timeout"] }
tower-http = { version = "0.4", features = ["add-extension", "trace"] }
uuid = { version = "1.3", features = ["serde", "v4"] }
serde = { version = "1", features = ["derive"] }
sqlx = { version = "0.5.10", features = ["runtime-tokio-rustls", "any", "sqlite", "chrono", "time", "uuid"] }
sqlx = { version = "0.5.10", features = ["runtime-tokio-rustls", "any", "sqlite", "chrono", "time", "uuid"] }
argon2 = "0.5"
rand_core = { version = "0.6", features = ["getrandom"] }
thiserror = "1.0.40"
justerror = "1.1.0"
password-hash = { version = "0.5.0", features = ["std", "getrandom"] }
async-sqlx-session = { version = "0.4.0", default-features = false, features = ["sqlite", "rustls"] }
axum-sessions = "0.5.0"

View File

@ -7,7 +7,8 @@
create table if not exists witches (
id blob not null primary key,
last_seen int,
name text,
username text not null unique,
displayname text,
email text,
secret blob not null, -- encrypted password? need to figure auth out
created_at int not null default (unixepoch()),

35
src/lib.rs Normal file
View File

@ -0,0 +1,35 @@
#[macro_use]
extern crate justerror;
use argon2::{
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
Argon2,
};
use uuid::Uuid;
pub mod db;
pub mod handlers;
fn create_user(username: &str, password: &[u8]) -> Result<Uuid, CreateUserError> {
// Argon2 with default params (Argon2id v19)
let argon2 = Argon2::default();
let salt = SaltString::generate(&mut OsRng);
let password_hash = argon2
.hash_password(password, &salt)
.unwrap() // safe to unwrap, we know the salt is valid
.to_string();
todo!()
}
#[Error(desc = "Could not create user.")]
#[non_exhaustive]
pub struct CreateUserError(#[from] CreateUserErrorKind);
#[Error]
#[non_exhaustive]
pub enum CreateUserErrorKind {
AlreadyExists,
Unknown,
}

View File

@ -2,9 +2,7 @@ use std::net::SocketAddr;
use axum::{routing::get, Router};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
mod db;
mod handlers;
use witch_watch::{db, handlers};
#[tokio::main]
async fn main() {