diff options
Diffstat (limited to 'atuin-common/src')
| -rw-r--r-- | atuin-common/src/api.rs | 36 | ||||
| -rw-r--r-- | atuin-common/src/calendar.rs | 1 | ||||
| -rw-r--r-- | atuin-common/src/lib.rs | 3 | ||||
| -rw-r--r-- | atuin-common/src/utils.rs | 19 |
4 files changed, 4 insertions, 55 deletions
diff --git a/atuin-common/src/api.rs b/atuin-common/src/api.rs index 803fbbcc..47bbcde1 100644 --- a/atuin-common/src/api.rs +++ b/atuin-common/src/api.rs @@ -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(), - } - } -} diff --git a/atuin-common/src/calendar.rs b/atuin-common/src/calendar.rs index d576f1a7..d3b1d921 100644 --- a/atuin-common/src/calendar.rs +++ b/atuin-common/src/calendar.rs @@ -1,4 +1,5 @@ // Calendar data +use serde::{Serialize, Deserialize}; pub enum TimePeriod { YEAR, diff --git a/atuin-common/src/lib.rs b/atuin-common/src/lib.rs index 77cd644d..e76a7abb 100644 --- a/atuin-common/src/lib.rs +++ b/atuin-common/src/lib.rs @@ -1,7 +1,4 @@ #![forbid(unsafe_code)] -#[macro_use] -extern crate serde_derive; - pub mod api; pub mod utils; diff --git a/atuin-common/src/utils.rs b/atuin-common/src/utils.rs index 35647bd4..23e34252 100644 --- a/atuin-common/src/utils.rs +++ b/atuin-common/src/utils.rs @@ -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); |
