diff options
author | Bryan Newbold <bnewbold@archive.org> | 2022-09-07 19:49:40 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2022-09-07 19:49:42 -0700 |
commit | d941d472ada2b5943142751cf2c7e01b66f1d17a (patch) | |
tree | 48a3b895bddb7cfc44cecc51eb133cb99abbf520 /fatcat-cli | |
parent | 19ad74a98458360473dbf0ff474368e1c1c45156 (diff) | |
download | fatcat-cli-d941d472ada2b5943142751cf2c7e01b66f1d17a.tar.gz fatcat-cli-d941d472ada2b5943142751cf2c7e01b66f1d17a.zip |
use upstream version of 'macaroon' crate
The code changes are pretty minor: using default() instead of new(), and
(safely) parsing bytes out of predicates instead of getting String
directly.
The validate() function is now run automatically as part of
deserialization, so don't need that function call.
This reduces duplication in the dependency tree, and gets us on sounder
footing for maintainability, which is great!
Diffstat (limited to 'fatcat-cli')
-rw-r--r-- | fatcat-cli/Cargo.toml | 2 | ||||
-rw-r--r-- | fatcat-cli/src/lib.rs | 29 |
2 files changed, 15 insertions, 16 deletions
diff --git a/fatcat-cli/Cargo.toml b/fatcat-cli/Cargo.toml index c2b258a..6e24c7c 100644 --- a/fatcat-cli/Cargo.toml +++ b/fatcat-cli/Cargo.toml @@ -16,7 +16,7 @@ categories = ["command-line-utilities"] [dependencies] data-encoding = "2.1" fatcat-openapi = { version = "*", path = "../fatcat-openapi", default-features = false, features = ["client"] } -macaroon = { git = "https://github.com/bnewbold/libmacaroon-rs", branch = "bnewbold-broken" } +macaroon = "0.2" toml = "0.5" termcolor = "1" colored_json = "*" diff --git a/fatcat-cli/src/lib.rs b/fatcat-cli/src/lib.rs index ab63ec7..6c1f449 100644 --- a/fatcat-cli/src/lib.rs +++ b/fatcat-cli/src/lib.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Context, Result}; use data_encoding::BASE64; -use macaroon::{Macaroon, Verifier}; +use macaroon::{Caveat, Macaroon, Verifier}; use std::path::PathBuf; use std::str::FromStr; @@ -87,28 +87,27 @@ pub fn parse_macaroon_editor_id(s: &str) -> Result<String> { .context("macaroon parsing failed")?; let mac = Macaroon::deserialize(&raw) .map_err(|err| anyhow!("macaroon deserialization failed: {:?}", err))?; - let mac = mac - .validate() - .map_err(|err| anyhow!("macaroon validation failed: {:?}", err))?; - let mut verifier = Verifier::new(); + let mut verifier = Verifier::default(); let mut editor_id: Option<String> = None; for caveat in mac.first_party_caveats() { - if caveat.predicate().starts_with("editor_id = ") { - editor_id = Some( - caveat - .predicate() - .get(12..) - .context("parsing macaroon")? - .to_string(), - ); - break; + if let Caveat::FirstParty(fp) = caveat { + let predicate_str = String::from_utf8(fp.predicate().as_ref().to_vec())?; + if predicate_str.starts_with("editor_id = ") { + editor_id = Some( + predicate_str + .get(12..) + .context("parsing macaroon")? + .to_string(), + ); + break; + } } } let editor_id = match editor_id { Some(id) => id, None => return Err(anyhow!("expected an editor_id caveat in macaroon token")), }; - verifier.satisfy_exact(&format!("editor_id = {}", editor_id)); + verifier.satisfy_exact(format!("editor_id = {}", editor_id).into()); Ok(editor_id) } |