diff options
| author | Conrad Ludgate <conrad.ludgate@truelayer.com> | 2022-04-22 19:24:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-22 19:24:38 +0100 |
| commit | 02c70deecba955c1b01f661ed7a709038e90addc (patch) | |
| tree | fc6881b607120cdb97991e17142b2e3159bff759 /atuin-common | |
| parent | Added docker-compose.yml (#325) (diff) | |
| download | atuin-02c70deecba955c1b01f661ed7a709038e90addc.zip | |
refactor (#327)
Diffstat (limited to 'atuin-common')
| -rw-r--r-- | atuin-common/Cargo.toml | 7 | ||||
| -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 |
5 files changed, 5 insertions, 61 deletions
diff --git a/atuin-common/Cargo.toml b/atuin-common/Cargo.toml index 93814acb..59caa796 100644 --- a/atuin-common/Cargo.toml +++ b/atuin-common/Cargo.toml @@ -12,11 +12,6 @@ repository = "https://github.com/ellie/atuin" [dependencies] rust-crypto = "^0.2" -sodiumoxide = "0.2.6" chrono = { version = "0.4", features = ["serde"] } -serde_derive = "1.0.125" -serde = "1.0.126" -serde_json = "1.0.75" +serde = { version = "1.0.126", features = ["derive"] } uuid = { version = "0.8", features = ["v4"] } -axum = "0.5" -http = "0.2" 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); |
