aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock6
-rw-r--r--Cargo.toml4
-rw-r--r--src/model.rs15
3 files changed, 11 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7e94f75..967d575 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -126,9 +126,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]]
name = "cc"
-version = "1.2.42"
+version = "1.2.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "81bbf3b3619004ad9bd139f62a9ab5cfe467f307455a0d307b0cf58bf070feaa"
+checksum = "739eb0f94557554b3ca9a86d2d37bebd49c5e6d0c1d2bda35ba5bdac830befc2"
dependencies = [
"find-msvc-tools",
"shlex",
@@ -272,7 +272,6 @@ name = "files"
version = "0.1.0"
dependencies = [
"anyhow",
- "base64",
"chrono",
"const_format",
"env_logger",
@@ -283,7 +282,6 @@ dependencies = [
"hyper-util",
"log",
"rand",
- "rand_core",
"rusqlite_migration",
"tempfile",
"tokio",
diff --git a/Cargo.toml b/Cargo.toml
index 279698e..623afd3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,6 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
-base64 = "0.22"
chrono = "0.4"
const_format = "0.2"
env_logger = "0.11"
@@ -16,8 +15,7 @@ http-body-util = "0.1"
hyper = { version = "1", features = ["full"] }
hyper-util = { version = "0.1", features = ["full"] }
log = "0.4"
-rand = { version = "0.8", features = ["getrandom"] }
-rand_core = "0.6"
+rand = "0.8"
tempfile = "3.23"
tokio = { version = "1", features = ["full"] }
tokio-rusqlite = "0.6"
diff --git a/src/model.rs b/src/model.rs
index ed4fbf8..12b0433 100644
--- a/src/model.rs
+++ b/src/model.rs
@@ -1,6 +1,5 @@
-use base64::{engine::general_purpose::URL_SAFE, Engine as _};
use chrono::{DateTime, Local, NaiveDateTime, TimeZone};
-use rand_core::{OsRng, RngCore};
+use rand::{distributions::Alphanumeric, Rng};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct File {
@@ -18,15 +17,17 @@ pub fn local_time() -> DateTime<Local> {
}
}
-// Using 20 bytes (160 bits) to file identifiers
+// Using 28 Base 62 characters, which corresponds to 166 bits of entropy
// https://owasp.org/www-community/vulnerabilities/Insufficient_Session-ID_Length
// https://www.rfc-editor.org/rfc/rfc6749.html#section-10.10
-const FILE_ID_BYTES: usize = 20;
+const FILE_ID_CHARS: usize = 28;
pub fn generate_file_id() -> String {
- let mut token = [0u8; FILE_ID_BYTES];
- OsRng.fill_bytes(&mut token);
- URL_SAFE.encode(token)
+ rand::thread_rng()
+ .sample_iter(&Alphanumeric)
+ .take(FILE_ID_CHARS)
+ .map(char::from)
+ .collect()
}
const FORMAT: &str = "%Y-%m-%d %H:%M:%S";