Skip to content

Commit

Permalink
Have examples/verify print a message indicating success
Browse files Browse the repository at this point in the history
  • Loading branch information
nresare committed Feb 27, 2024
1 parent e8ff4cf commit caebdd9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ fn main() -> Result<()> {
let key_bytes = read_to_string(Path::new(&path))?;
let key = PublicKey::from_openssh(key_bytes.as_str())?;

let path = env::var("SSH_AUTH_SOCK").expect("SSH_AUTH_SOCK is not set");
let mut client = Client::connect(Path::new(path.as_str()))?;
let agent_path = env::var("SSH_AUTH_SOCK").expect("SSH_AUTH_SOCK is not set");
let mut client = Client::connect(Path::new(agent_path.as_str()))?;

let mut data = BytesMut::zeroed(32);
getrandom(&mut data[..]).expect("Failed to obtain random data to sign");
let data = data.freeze();

let sig = client.sign(&key, data.as_ref())?;

let sig = client.sign(&key, &data)?;
key.key_data()
.verify(data.as_ref(), &sig)
.expect("verification failed");
println!(
"Successfully verified a signature from the agent '{}' with the public key in '{}'",
agent_path, path,
);
Ok(())
}

0 comments on commit caebdd9

Please sign in to comment.