Read a Snapshot From Filesystem
Run the Example
You can read a snapshot from the file system and retrieve the public key from the stored secret Ed25519 key stored at
the given path
by running the following command from within the
client crate.
cargo run --example cli read-snapshot --path "/path/to/snapshot.file" --client-path "client-path-0" --vault-path "vault-path" --record-path "record-path" --key "passphrase"
Expected Output
[2022-03-28T08:29:33Z INFO cli] Loading snapshot
[2022-03-28T08:29:33Z INFO cli] Creating public key
[2022-03-28T08:29:33Z INFO cli] Public key is "smsmXBG/Ln/Yjip72OJns4PB4iejVBIzs4MOXO9IkTE=" (Base64)
Example Code
async fn command_read_snapshot(path: String, client_path: String, key: String, private_key_location: VaultLocation) {
let stronghold = Stronghold::default();
let client_path = client_path.as_bytes().to_vec();
let snapshot_path = SnapshotPath::from_path(path);
// calculate hash from key
let key = hash_blake2b(key);
let keyprovider = KeyProvider::try_from(key).expect("Failed to load key");
info!("Loading snapshot");
let client = stronghold
.load_client_from_snapshot(client_path, &keyprovider, &snapshot_path)
.expect("Could not load client from Snapshot");
// get the public key
let public_key_procedure = stronghold::procedures::PublicKey {
ty: KeyType::Ed25519,
private_key: private_key_location.to_location(),
};
info!("Creating public key");
let procedure_result = client.execute_procedure(StrongholdProcedure::PublicKey(public_key_procedure));
let procedure_result = procedure_result.unwrap();
let output: Vec<u8> = procedure_result.into();
info!(r#"Public key is "{}" (Base64)"#, base64::encode(output));
}