Skip to content

Commit 1df69f7

Browse files
committed
Upgrade dependencies, clap in CLI
1 parent 0b3f683 commit 1df69f7

File tree

11 files changed

+198
-141
lines changed

11 files changed

+198
-141
lines changed

Cargo.lock

Lines changed: 134 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ license = "MIT"
66
name = "atomic-cli"
77
readme = "README.md"
88
repository = "https://github.com/atomicdata-dev/atomic-data-rust"
9-
version = "0.34.2"
9+
version = "0.34.3"
1010

1111
[dependencies]
12-
atomic_lib = {version = "0.34.2", path = "../lib", features = ["config", "rdf"]}
13-
clap = {version = "3", features = ["cargo"]}
12+
atomic_lib = {version = "0.34.3", path = "../lib", features = ["config", "rdf"]}
13+
clap = {version = "4", features = ["cargo"]}
1414
colored = "2"
1515
dirs = "4"
1616
edit = {version = "0.1", optional = true}

cli/src/commit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ fn argument_to_string(context: &Context, argument: &str) -> AtomicResult<String>
6262
let command_name = context.matches.subcommand_name().unwrap();
6363
let subcommand_matches = context.matches.subcommand_matches(command_name).unwrap();
6464
let user_arg = subcommand_matches
65-
.value_of(argument)
65+
.get_one::<&str>(argument)
6666
.ok_or(format!("No argument value for {} found", argument))?;
67-
Ok(user_arg.into())
67+
Ok(user_arg.to_string())
6868
}
6969

7070
/// Parses a single argument (URL or Bookmark), should return a valid URL
7171
fn argument_to_url(context: &Context, argument: &str) -> AtomicResult<String> {
7272
let command_name = context.matches.subcommand_name().unwrap();
7373
let subcommand_matches = context.matches.subcommand_matches(command_name).unwrap();
7474
let user_arg = subcommand_matches
75-
.value_of(argument)
75+
.get_one::<&str>(argument)
7676
.ok_or(format!("No argument value for {} found", argument))?;
7777
let id_url: String = context
7878
.mapping
7979
.lock()
8080
.unwrap()
81-
.try_mapping_or_url(&String::from(user_arg))
81+
.try_mapping_or_url(&String::from(user_arg.to_string()))
8282
.ok_or(&*format!("No url found for {}", user_arg))?;
8383
Ok(id_url)
8484
}

cli/src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ fn main() -> AtomicResult<()> {
105105
",
106106
)
107107
.required(true)
108-
.min_values(1)
108+
.num_args(1..)
109109
)
110110
.arg(Arg::new("as")
111111
.long("as")
112-
.possible_values(SERIALIZE_OPTIONS)
112+
.value_parser(SERIALIZE_OPTIONS)
113113
.default_value("pretty")
114114
.help("Serialization format")
115-
.takes_value(true)
115+
.num_args(1)
116116
)
117117
)
118118
.subcommand(
@@ -138,10 +138,10 @@ fn main() -> AtomicResult<()> {
138138
)
139139
.arg(Arg::new("as")
140140
.long("as")
141-
.possible_values(SERIALIZE_OPTIONS)
141+
.value_parser(SERIALIZE_OPTIONS)
142142
.default_value("pretty")
143143
.help("Serialization format")
144-
.takes_value(true)
144+
.num_args(1)
145145
)
146146
)
147147
.subcommand(
@@ -294,9 +294,9 @@ fn list(context: &mut Context) {
294294
/// Triple Pattern Fragment Query
295295
fn tpf(context: &Context) -> AtomicResult<()> {
296296
let subcommand_matches = context.matches.subcommand_matches("tpf").unwrap();
297-
let subject = tpf_value(subcommand_matches.value_of("subject").unwrap());
298-
let property = tpf_value(subcommand_matches.value_of("property").unwrap());
299-
let value = tpf_value(subcommand_matches.value_of("value").unwrap());
297+
let subject = tpf_value(subcommand_matches.get_one::<&str>("subject").unwrap());
298+
let property = tpf_value(subcommand_matches.get_one::<&str>("property").unwrap());
299+
let value = tpf_value(subcommand_matches.get_one::<&str>("value").unwrap());
300300
let endpoint = format!("{}/tpf", &context.get_write_context().server);
301301
let resources =
302302
atomic_lib::client::fetch_tpf(&endpoint, subject, property, value, &context.store)?;

cli/src/new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn new(context: &mut Context) -> AtomicResult<()> {
1818
.matches
1919
.subcommand_matches("new")
2020
.unwrap()
21-
.value_of("class")
21+
.get_one::<&str>("class")
2222
.expect("Add a class value");
2323
let class_url = context
2424
.mapping

cli/src/path.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use serialize::Format;
88
/// Resolves an Atomic Path query
99
pub fn get_path(context: &mut Context) -> AtomicResult<()> {
1010
let subcommand_matches = context.matches.subcommand_matches("get").unwrap();
11-
let path_vec: Vec<&str> = subcommand_matches
12-
.values_of("path")
11+
let path_vec: Vec<String> = subcommand_matches
12+
.get_many::<String>("path")
1313
.expect("Add a URL, shortname or path")
14+
.map(|s| s.to_string())
1415
.collect();
1516
let path_string: String = path_vec.join(" ");
1617
let serialization: Format = get_serialization(subcommand_matches)?;

cli/src/print.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub const SERIALIZE_OPTIONS: [&str; 7] =
1414

1515
/// Returns preferred serialization format. Defaults to pretty.
1616
pub fn get_serialization(argmatches: &ArgMatches) -> AtomicResult<Format> {
17-
let format = if let Some(preferred_format) = argmatches.value_of("as") {
18-
match preferred_format {
17+
let format = if let Some(preferred_format) = argmatches.get_one::<String>("as") {
18+
match preferred_format.as_str() {
1919
"pretty" => Format::Pretty,
2020
"json" => Format::Json,
2121
"jsonld" => Format::JsonLd,

lib/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ name = "benchmarks"
1616
# path = "benches/benchmarks.rs"
1717

1818
[dependencies]
19-
base64 = "0.13"
19+
base64 = "0.21"
2020
bincode = {version = "1", optional = true}
2121
directories = {version = ">= 2, < 5", optional = true}
2222
html2md = {version = "0.2.13", optional = true}
@@ -25,22 +25,22 @@ lol_html = {version = "0.3.1", optional = true}
2525
rand = {version = "0.8"}
2626
regex = "1"
2727
ring = "0.16.19"
28-
rio_api = {version = "0.7", optional = true}
29-
rio_turtle = {version = "0.7", optional = true}
28+
rio_api = {version = "0.8", optional = true}
29+
rio_turtle = {version = "0.8", optional = true}
3030
serde = {version = "1", features = ["derive"]}
3131
serde_json = "1"
3232
sled = {version = "0.34", optional = true, features = ["no_logs"]}
33-
toml = {version = "0.5", optional = true}
33+
toml = {version = "0.7", optional = true}
3434
tracing = "0.1"
3535
ureq = "2"
3636
url = "2"
3737
urlencoding = "2"
3838

3939
[dev-dependencies]
40-
criterion = "0.3"
40+
criterion = "0.4"
4141
iai = "0.1"
4242
lazy_static = "1"
43-
ntest = "0.7"
43+
ntest = "0.9"
4444

4545
[features]
4646
config = ["directories", "toml"]

lib/src/agents.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//! Agents are actors (such as users) that can edit content.
33
//! https://docs.atomicdata.dev/commits/concepts.html
44
5+
use base64::{engine::general_purpose, Engine};
6+
57
use crate::{errors::AtomicResult, urls, Resource, Storelike, Value};
68

79
#[derive(Clone, Debug)]
@@ -93,28 +95,39 @@ fn generate_keypair() -> AtomicResult<Pair> {
9395
.map_err(|e| format!("Error generating keypair {}", e))
9496
.unwrap();
9597
Ok(Pair {
96-
private: base64::encode(seed),
97-
public: base64::encode(key_pair.public_key()),
98+
private: encode_base64(&seed),
99+
public: encode_base64(key_pair.public_key().as_ref()),
98100
})
99101
}
100102

101103
/// Returns a Key Pair (including public key) from a private key, base64 encoded.
102104
pub fn generate_public_key(private_key: &str) -> Pair {
103105
use ring::signature::KeyPair;
104-
let private_key_bytes = base64::decode(private_key).unwrap();
106+
let private_key_bytes = decode_base64(private_key).unwrap();
105107
let key_pair = ring::signature::Ed25519KeyPair::from_seed_unchecked(private_key_bytes.as_ref())
106108
.map_err(|_| "Error generating keypair")
107109
.unwrap();
108110
Pair {
109-
private: base64::encode(private_key_bytes),
110-
public: base64::encode(key_pair.public_key().as_ref()),
111+
private: encode_base64(&private_key_bytes),
112+
public: encode_base64(key_pair.public_key().as_ref()),
111113
}
112114
}
113115

116+
pub fn decode_base64(string: &str) -> AtomicResult<Vec<u8>> {
117+
let vec = general_purpose::STANDARD
118+
.decode(string)
119+
.map_err(|e| format!("Invalid key. Not valid Base64. {}", e))?;
120+
Ok(vec)
121+
}
122+
123+
pub fn encode_base64(bytes: &[u8]) -> String {
124+
general_purpose::STANDARD.encode(bytes)
125+
}
126+
114127
/// Checks if the public key is a valid ED25519 base64 key.
115128
/// Not perfect - only checks byte length and parses base64.
116129
pub fn verify_public_key(public_key: &str) -> AtomicResult<()> {
117-
let pubkey_bin = base64::decode(public_key)
130+
let pubkey_bin = decode_base64(public_key)
118131
.map_err(|e| format!("Invalid public key. Not valid Base64. {}", e))?;
119132
if pubkey_bin.len() != 32 {
120133
return Err(format!(

lib/src/authentication.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Check signatures in authentication headers, find the correct agent. Authorization is done in Hierarchies
22
3-
use crate::{commit::check_timestamp, errors::AtomicResult, urls, Storelike};
3+
use crate::{
4+
agents::decode_base64, commit::check_timestamp, errors::AtomicResult, urls, Storelike,
5+
};
46

57
/// Set of values extracted from the request.
68
/// Most are coming from headers.
@@ -26,11 +28,11 @@ pub struct AuthValues {
2628
/// Does not check if the agent has rights to access the subject.
2729
#[tracing::instrument(skip_all)]
2830
pub fn check_auth_signature(subject: &str, auth_header: &AuthValues) -> AtomicResult<()> {
29-
let agent_pubkey = base64::decode(&auth_header.public_key)?;
31+
let agent_pubkey = decode_base64(&auth_header.public_key)?;
3032
let message = format!("{} {}", subject, &auth_header.timestamp);
3133
let peer_public_key =
3234
ring::signature::UnparsedPublicKey::new(&ring::signature::ED25519, agent_pubkey);
33-
let signature_bytes = base64::decode(&auth_header.signature)?;
35+
let signature_bytes = decode_base64(&auth_header.signature)?;
3436
peer_public_key
3537
.verify(message.as_bytes(), &signature_bytes)
3638
.map_err(|_e| {

0 commit comments

Comments
 (0)