tools/fetcher: Decode tokens

This commit is contained in:
Bilal Elmoussaoui 2022-06-06 21:04:05 +02:00
parent 42011356d5
commit a06721730f
3 changed files with 19 additions and 7 deletions

View file

@ -597,6 +597,7 @@ name = "keyring-fetch"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-std", "async-std",
"hex",
"oo7", "oo7",
] ]

View file

@ -7,4 +7,5 @@ edition = "2021"
[dependencies] [dependencies]
oo7 = {version = "0.1.0-alpha.5", features = ["tracing", "unstable", "async-std"]} oo7 = {version = "0.1.0-alpha.5", features = ["tracing", "unstable", "async-std"]}
async-std = "1.11.0" async-std = "1.11.0"
hex = "0.4"

View file

@ -26,15 +26,25 @@ async fn main() -> oo7::Result<()> {
let secret = items[0].secret().await?; let secret = items[0].secret().await?;
let keyring = oo7::portal::Keyring::load(keyring_path, &secret).await?; let keyring = oo7::portal::Keyring::load(keyring_path, &secret).await?;
let keyring_items = keyring.items().await?; let keyring_items = keyring
.search_items(HashMap::from([("type", "token")]))
.await?;
for item in keyring_items.iter() { for item in keyring_items.iter() {
let attributes = item.attributes(); let attributes = item.attributes();
let secret = item.secret(); let secret = item.secret();
println!( if let Ok(decoded_secret) = hex::decode(secret.clone()) {
"Found a secret: \nAttributes: {:#?}\nSecret: {:#?}", println!(
attributes, "Found a secret: \nAttributes: {:#?}\nSecret: {:#?}",
String::from_utf8_lossy(&secret) attributes,
); String::from_utf8_lossy(&decoded_secret)
);
} else {
println!(
"ERROR!! Failed to decode secret for \n Attributes {:#?} \n {:#?}",
attributes,
String::from_utf8_lossy(&secret)
);
}
println!("################################################"); println!("################################################");
} }