pub struct SshVault { /* private fields */ }Expand description
Main vault interface for encrypting and decrypting data using SSH keys
SshVault provides a unified interface for working with both Ed25519 and RSA
encryption schemes. It handles key type detection and delegates operations to
the appropriate underlying implementation.
Implementations§
Source§impl SshVault
impl SshVault
Sourcepub fn new(
key_type: &SshKeyType,
public: Option<PublicKey>,
private: Option<PrivateKey>,
) -> Result<Self>
pub fn new( key_type: &SshKeyType, public: Option<PublicKey>, private: Option<PrivateKey>, ) -> Result<Self>
Creates a new vault instance with the specified key type
§Arguments
key_type- The SSH key type (Ed25519 or RSA)public- Optional public key for encryption operationsprivate- Optional private key for decryption operations
§Errors
Returns an error if:
- The key type doesn’t match the provided keys
- Both public and private keys are provided (only one should be provided)
- The keys are invalid or encrypted without proper decryption
§Examples
use ssh_vault::vault::{SshVault, SshKeyType};
use ssh_key::PublicKey;
use std::path::Path;
let public_key = PublicKey::read_openssh_file(Path::new("id_ed25519.pub"))?;
let vault = SshVault::new(&SshKeyType::Ed25519, Some(public_key), None)?;Sourcepub fn create(
&self,
password: SecretSlice<u8>,
data: &mut [u8],
) -> Result<String>
pub fn create( &self, password: SecretSlice<u8>, data: &mut [u8], ) -> Result<String>
Encrypts data and creates a vault
§Arguments
password- Secret password for encrypting the datadata- Mutable byte slice to encrypt (will be zeroed after encryption)
§Returns
Returns the vault as a formatted string that can be stored or transmitted. The format includes the algorithm, fingerprint, and encrypted payload.
§Security
The input data is zeroed after encryption to prevent sensitive data
from remaining in memory.
§Errors
Returns an error if encryption fails.
Sourcepub fn view(
&self,
password: &[u8],
data: &[u8],
fingerprint: &str,
) -> Result<String>
pub fn view( &self, password: &[u8], data: &[u8], fingerprint: &str, ) -> Result<String>
Decrypts and views vault contents
§Arguments
password- Encrypted password bytes from the vaultdata- Encrypted data bytes from the vaultfingerprint- Expected key fingerprint for verification
§Returns
Returns the decrypted data as a UTF-8 string.
§Errors
Returns an error if:
- The fingerprint doesn’t match the private key
- Decryption fails (wrong key or corrupted data)
- The decrypted data is not valid UTF-8
Auto Trait Implementations§
impl Freeze for SshVault
impl !RefUnwindSafe for SshVault
impl !Send for SshVault
impl !Sync for SshVault
impl Unpin for SshVault
impl !UnwindSafe for SshVault
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more