Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ssh-key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
target: ${{ matrix.target }}
override: true
- uses: RustCrypto/actions/cargo-hack-install@master
- run: cargo hack build --target ${{ matrix.target }} --feature-powerset --exclude-features std
- run: cargo hack build --target ${{ matrix.target }} --feature-powerset --exclude-features default,std

minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
Expand Down
2 changes: 1 addition & 1 deletion ssh-key/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ hex-literal = "0.3"
tempfile = "3"

[features]
default = ["alloc", "ecdsa"]
default = ["ecdsa", "std"]
alloc = ["zeroize/alloc"]
ecdsa = ["sec1"]
std = ["alloc", "base64ct/std"]
Expand Down
3 changes: 2 additions & 1 deletion ssh-key/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ and `authorized_keys` files.
- [x] Parsing `autorized_keys` files
- [x] Built-in zeroize support for private keys

#### TODO:
#### TODO

- [ ] Encrypted private key support
- [ ] SSH certificate support
- [ ] Legacy SSH key (pre-OpenSSH) format support
- [ ] Integrations with other RustCrypto crates (e.g. `ecdsa`, `ed25519`, `rsa`)
- [ ] FIDO2 key support
Expand Down
20 changes: 20 additions & 0 deletions ssh-key/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ use alloc::{
string::{String, ToString},
};

#[cfg(feature = "std")]
use std::{fs, path::Path};

/// SSH public key.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct PublicKey {
Expand Down Expand Up @@ -104,6 +107,23 @@ impl PublicKey {
Ok(String::from_utf8(buf)?)
}

/// Read public key from an OpenSSH-formatted PEM file.
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn read_openssh_file(path: &Path) -> Result<Self> {
let input = fs::read_to_string(path)?;
Self::from_openssh(&*input)
}

/// Write public key as an OpenSSH-formatted PEM file.
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn write_openssh_file(&self, path: &Path) -> Result<()> {
let encoded = self.to_openssh()?;
fs::write(path, encoded.as_bytes())?;
Ok(())
}

/// Get the digital signature [`Algorithm`] used by this key.
pub fn algorithm(&self) -> Algorithm {
self.key_data.algorithm()
Expand Down