Skip to content

Commit 5979a99

Browse files
authored
ssh-cipher: add encoding feature (#560)
Makes `ssh-encoding` support optional, for anyone who implements their own support for the SSH packet format and just wants to use the cryptographic aspects of this crate.
1 parent dce0357 commit 5979a99

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

ssh-cipher/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ rust-version = "1.85"
1919

2020
[dependencies]
2121
cipher = "0.5"
22-
encoding = { package = "ssh-encoding", version = "0.3" }
2322

2423
# optional dependencies
2524
aead = { version = "0.6", optional = true, default-features = false }
@@ -28,6 +27,7 @@ aes-gcm = { version = "0.11", optional = true, default-features = false, feature
2827
ctutils = { version = "0.4", optional = true, default-features = false }
2928
chacha20 = { version = "0.10", optional = true, default-features = false, features = ["cipher", "legacy"] }
3029
des = { version = "0.9", optional = true, default-features = false }
30+
encoding = { package = "ssh-encoding", version = "0.3", optional = true }
3131
poly1305 = { version = "0.9", optional = true, default-features = false }
3232
zeroize = { version = "1", optional = true, default-features = false }
3333

@@ -37,6 +37,7 @@ hex-literal = "1"
3737
[features]
3838
aes = ["dep:aead", "dep:aes", "dep:aes-gcm"]
3939
chacha20poly1305 = ["dep:aead", "dep:chacha20", "dep:poly1305", "dep:ctutils"]
40+
encoding = ["dep:encoding"]
4041
getrandom = ["rand_core", "aead?/getrandom", "cipher/getrandom"]
4142
rand_core = ["aead?/rand_core", "cipher/rand_core"]
4243
tdes = ["dep:des"]

ssh-cipher/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ pub use crate::chacha20poly1305::{ChaCha20, ChaCha20Poly1305, ChaChaKey, ChaChaN
2121

2222
use cipher::array::{Array, typenum::U16};
2323
use core::{fmt, str};
24-
use encoding::{Label, LabelError};
2524

2625
#[cfg(feature = "aes")]
2726
use self::block_cipher::Aes;
2827
#[cfg(feature = "tdes")]
2928
use self::block_cipher::Tdes;
3029
#[cfg(any(feature = "aes", feature = "chacha20poly1305"))]
3130
use ::aead::{AeadInOut, KeyInit};
31+
#[cfg(feature = "encoding")]
32+
use encoding::{Label, LabelError};
3233
#[cfg(any(feature = "aes", feature = "tdes"))]
3334
use {
3435
self::block_cipher::{BlockMode, sealed::BlockCipher},
@@ -163,6 +164,7 @@ impl Cipher {
163164
///
164165
/// # Errors
165166
/// Returns [`LabelError`] if the provided `ciphername` is unknown.
167+
#[cfg(feature = "encoding")]
166168
pub fn new(ciphername: &str) -> core::result::Result<Self, LabelError> {
167169
ciphername.parse()
168170
}
@@ -472,6 +474,7 @@ impl AsRef<str> for Cipher {
472474
}
473475
}
474476

477+
#[cfg(feature = "encoding")]
475478
impl Label for Cipher {}
476479

477480
impl fmt::Display for Cipher {
@@ -480,6 +483,7 @@ impl fmt::Display for Cipher {
480483
}
481484
}
482485

486+
#[cfg(feature = "encoding")]
483487
impl str::FromStr for Cipher {
484488
type Err = LabelError;
485489

ssh-key/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rust-version = "1.85"
2121
[dependencies.cipher]
2222
version = "0.3.0-rc.10"
2323
package = "ssh-cipher"
24-
features = ["zeroize"]
24+
features = ["encoding", "zeroize"]
2525

2626
# ssh-encoding
2727
[dependencies.encoding]

0 commit comments

Comments
 (0)