mirror of
https://github.com/atuinsh/atuin.git
synced 2025-08-15 09:42:45 +02:00
refactor (#327)
This commit is contained in:
@ -1,8 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use axum::{response::IntoResponse, Json};
|
||||
use chrono::Utc;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UserResponse {
|
||||
@ -56,34 +53,3 @@ pub struct SyncHistoryRequest {
|
||||
pub struct SyncHistoryResponse {
|
||||
pub history: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ErrorResponse<'a> {
|
||||
pub reason: Cow<'a, str>,
|
||||
}
|
||||
|
||||
impl<'a> IntoResponse for ErrorResponseStatus<'a> {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
(self.status, Json(self.error)).into_response()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ErrorResponseStatus<'a> {
|
||||
pub error: ErrorResponse<'a>,
|
||||
pub status: http::StatusCode,
|
||||
}
|
||||
|
||||
impl<'a> ErrorResponse<'a> {
|
||||
pub fn with_status(self, status: http::StatusCode) -> ErrorResponseStatus<'a> {
|
||||
ErrorResponseStatus {
|
||||
error: self,
|
||||
status,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reply(reason: &'a str) -> ErrorResponse {
|
||||
Self {
|
||||
reason: reason.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Calendar data
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
pub enum TimePeriod {
|
||||
YEAR,
|
||||
|
@ -1,7 +1,4 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
pub mod api;
|
||||
pub mod utils;
|
||||
|
@ -1,26 +1,11 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use crypto::digest::Digest;
|
||||
use crypto::sha2::Sha256;
|
||||
use sodiumoxide::crypto::pwhash::argon2id13;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub fn hash_secret(secret: &str) -> String {
|
||||
sodiumoxide::init().unwrap();
|
||||
let hash = argon2id13::pwhash(
|
||||
secret.as_bytes(),
|
||||
argon2id13::OPSLIMIT_INTERACTIVE,
|
||||
argon2id13::MEMLIMIT_INTERACTIVE,
|
||||
)
|
||||
.unwrap();
|
||||
let texthash = std::str::from_utf8(&hash.0).unwrap().to_string();
|
||||
|
||||
// postgres hates null chars. don't do that to postgres
|
||||
texthash.trim_end_matches('\u{0}').to_string()
|
||||
}
|
||||
|
||||
pub fn hash_str(string: &str) -> String {
|
||||
use crypto::digest::Digest;
|
||||
use crypto::sha2::Sha256;
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.input_str(string);
|
||||
|
||||
|
Reference in New Issue
Block a user