You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is useful for the CLI/GUI to accept KeyPair objects to use in any asymmetric operations. Otherwise, we have to copy and paste public/private key values which is possible but cumbersome. Here's an example of where we ultimately want to end up after solving issue #21 using the capycrypt CLI to generate KeyPair objects:
To achieve this, we only need to make a few changes:
In cargo.toml:
Add the following:
[dependencies]
serde = { version = "1.0", features = ["derive"] }
Then, in lib.rs where KeyPair is defined, we need to make the following modifcations:
use serde::Serialize;use std::fmt;#[derive(Serialize)]structKeyPair{owner:String,// ... other fields ...}impl fmt::DisplayforKeyPair{fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{write!(f,"{}", serde_json::to_string_pretty(&self).unwrap())}}implKeyPair{// ... your new function and other methods ...pubfnsave_to_file(&self,filename:&str) -> std::io::Result<()>{
std::fs::write(filename,self.to_string())}}
Finally, to write the KeyPair to a JSON, do the following:
let keypair = KeyPair{owner:"Frank Poole".to_string(),// ... initialize other fields ...};
keypair.save_to_file("keypair.json").unwrap();
That's it for this issue!
The text was updated successfully, but these errors were encountered:
This is useful for the CLI/GUI to accept KeyPair objects to use in any asymmetric operations. Otherwise, we have to copy and paste public/private key values which is possible but cumbersome. Here's an example of where we ultimately want to end up after solving issue #21 using the capycrypt CLI to generate KeyPair objects:
To achieve this, we only need to make a few changes:
In cargo.toml:
Add the following:
Then, in
lib.rs
whereKeyPair
is defined, we need to make the following modifcations:Finally, to write the KeyPair to a JSON, do the following:
That's it for this issue!
The text was updated successfully, but these errors were encountered: