From db898001eb171393ddd1989c50b01fefa169702d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 31 Oct 2019 15:24:47 +0100 Subject: [PATCH] Get rid of rust-crypto and uuid --- meilidb-http/Cargo.toml | 3 +-- meilidb-http/src/routes/key.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/meilidb-http/Cargo.toml b/meilidb-http/Cargo.toml index 062d4e5e9..890c8aec8 100644 --- a/meilidb-http/Cargo.toml +++ b/meilidb-http/Cargo.toml @@ -22,13 +22,12 @@ main_error = "0.1.0" meilidb-core = { path = "../meilidb-core", version = "0.6.0" } meilidb-schema = { path = "../meilidb-schema", version = "0.6.0" } pretty-bytes = "0.2.2" +rand = "0.7.2" rayon = "1.2.0" -rust-crypto = "0.2.36" serde = { version = "1.0.101", features = ["derive"] } serde_json = { version = "1.0.41", features = ["preserve_order"] } structopt = "0.3.3" sysinfo = "0.9.5" -uuid = { version = "0.8.1", features = ["v4"] } walkdir = "2.2.9" [dependencies.async-compression] diff --git a/meilidb-http/src/routes/key.rs b/meilidb-http/src/routes/key.rs index 8cfb80dea..cdefc39ba 100644 --- a/meilidb-http/src/routes/key.rs +++ b/meilidb-http/src/routes/key.rs @@ -1,13 +1,11 @@ use chrono::serde::ts_seconds; use chrono::{DateTime, Utc}; -use crypto::digest::Digest; -use crypto::sha1::Sha1; use heed::types::{SerdeBincode, Str}; use http::StatusCode; +use rand::seq::SliceRandom; use serde::{Deserialize, Serialize}; use tide::response::IntoResponse; use tide::{Context, Response}; -use uuid::Uuid; use crate::error::{ResponseError, SResult}; use crate::helpers::tide::ContextExt; @@ -16,9 +14,12 @@ use crate::models::token::*; use crate::Data; fn generate_api_key() -> String { - let mut hasher = Sha1::new(); - hasher.input_str(&Uuid::new_v4().to_string()); - hasher.result_str().to_string() + let mut rng = rand::thread_rng(); + let sample = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + sample + .choose_multiple(&mut rng, 40) + .map(|c| *c as char) + .collect() } pub async fn list(ctx: Context) -> SResult {