Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update fencing token to accept base64 instead of base16 #106

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ path = "src/main.rs"

[dependencies]
async-stream = "0.3.6"
base16ct = { version = "0.2.0", features = ["alloc"] }
base64ct = { version = "1.6.0", features = ["alloc"] }
clap = { version = "4.5.20", features = ["derive"] }
color-print = "0.3.6"
colored = "2.1.0"
Expand Down
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
};

use account::AccountService;
use base64ct::{Base64, Encoding};
use basin::BasinService;
use clap::{builder::styling, Parser, Subcommand};
use colored::*;
Expand Down Expand Up @@ -213,7 +214,7 @@ enum Commands {
/// and any regression will be ignored.
trim_point: u64,

/// Enforce fencing token specified in hex.
/// Enforce fencing token specified in base64.
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

Expand All @@ -233,12 +234,12 @@ enum Commands {
#[arg(value_name = "S2_URI")]
uri: S2BasinAndStreamUri,

/// New fencing token specified in hex.
/// New fencing token specified in base64.
/// It may be upto 16 bytes, and can be empty.
#[arg(value_parser = parse_fencing_token)]
new_fencing_token: FencingToken,

/// Enforce existing fencing token, specified in hex.
/// Enforce existing fencing token, specified in base64.
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

Expand All @@ -254,7 +255,7 @@ enum Commands {
#[arg(value_name = "S2_URI")]
uri: S2BasinAndStreamUri,

/// Enforce fencing token specified in hex.
/// Enforce fencing token specified in base64.
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

Expand Down Expand Up @@ -410,8 +411,8 @@ fn parse_records_output_source(s: &str) -> Result<RecordsOut, std::io::Error> {
}

fn parse_fencing_token(s: &str) -> Result<FencingToken, ConvertError> {
base16ct::mixed::decode_vec(s)
.map_err(|_| "invalid hex")?
Base64::decode_vec(s)
.map_err(|_| "invalid base64")?
.try_into()
}

Expand Down Expand Up @@ -860,7 +861,10 @@ async fn run() -> Result<(), S2CliError> {
let (cmd, description) = match command_record {
CommandRecord::Fence { fencing_token } => (
"fence",
format!("FencingToken({})", base16ct::lower::encode_string(fencing_token.as_ref())),
format!(
"FencingToken({})",
Base64::encode_string(fencing_token.as_ref()),
),
),
CommandRecord::Trim { seq_num } => (
"trim",
Expand Down
Loading