Skip to content

Commit

Permalink
Base64 encode the scope value
Browse files Browse the repository at this point in the history
bkt permits setting a cache scope (provided via the `BKT_SCOPE`
environment variable or the `--scope` command line option) to prevent
collisions between unrelated command invocations. Previously, the scope
value was used verbatim in a directory path, causing errors if the scope
contained path-sensitive characters such as `/`.

This commit modifies bkt to base64 encode the scope value. Given a scope
value like `https://example.com/`, that means we now end up with a path
like:

    /tmp/bkt-0.7-cache/keys/aHR0cHM6Ly9leGFtcGxlLmNvbS8.C3823B193F1E0C78

Instead of the invalid:

    /tmp/bkt-0.7-cache/keys/https://www.example.com/.C3823B193F1E0C78

Fixes #50
  • Loading branch information
larsks committed Nov 22, 2023
1 parent 84c483a commit b01ecb6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bincode = "1.3.1"
humantime = "2.1.0"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
base64 = "0.21.5"

[dependencies.clap]
version = "4.2"
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use anyhow::{anyhow, Context, Error, Result};
use serde::{Serialize, Deserialize};
use serde::de::DeserializeOwned;

use base64::{Engine as _, engine::general_purpose};


#[cfg(feature="debug")]
macro_rules! debug_msg {
($($arg:tt)*) => { eprintln!("bkt: {}", format!($($arg)*)) }
Expand Down Expand Up @@ -627,7 +630,7 @@ impl Cache {

fn scoped(mut self, scope: String) -> Self {
assert!(self.scope.is_none());
self.scope = Some(scope);
self.scope = Some(general_purpose::STANDARD_NO_PAD.encode(scope));
self
}

Expand Down

0 comments on commit b01ecb6

Please sign in to comment.