Skip to content

Commit b00fec8

Browse files
authored
ssh-encoding: enable and fix workspace-level lints (#513)
Applies the workspace-level config added in #509 to this crate and fixes any failures.
1 parent 93d0d81 commit b00fec8

18 files changed

Lines changed: 136 additions & 77 deletions

File tree

ssh-encoding/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
[package]
22
name = "ssh-encoding"
33
version = "0.3.0-rc.8"
4-
description = """
5-
Pure Rust implementation of SSH data type decoders/encoders as described
6-
in RFC4251
7-
"""
4+
description = "Pure Rust implementation of SSH data type decoders/encoders as described in RFC4251"
85
authors = ["RustCrypto Developers"]
96
license = "Apache-2.0 OR MIT"
107
homepage = "https://github.com/RustCrypto/SSH/tree/master/ssh-encoding"
@@ -37,6 +34,8 @@ bytes = ["alloc", "dep:bytes"]
3734
pem = ["base64", "dep:pem-rfc7468"]
3835
derive = ["ssh-derive"]
3936

37+
[lints]
38+
workspace = true
39+
4040
[package.metadata.docs.rs]
4141
all-features = true
42-
rustdoc-args = ["--cfg", "docsrs"]

ssh-encoding/LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2021-2024 The RustCrypto Project Developers
1+
Copyright (c) 2021-2026 The RustCrypto Project Developers
22

33
Permission is hereby granted, free of charge, to any
44
person obtaining a copy of this software and associated

ssh-encoding/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
Pure Rust implementation of SSH data type decoders/encoders as described
1515
in [RFC4251].
1616

17-
## Minimum Supported Rust Version
18-
19-
This crate requires **Rust 1.85** at a minimum.
20-
21-
We may change the MSRV in the future, but it will be accompanied by a minor
22-
version bump.
23-
2417
## License
2518

2619
Licensed under either of:

ssh-encoding/src/base64/reader.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Base64 reader support (constant-time).
22
33
use crate::{Decode, Error, Reader, Result};
4+
use core::fmt::{self, Debug};
45

56
/// Inner constant-time Base64 reader type from the `base64ct` crate.
67
type Inner<'i> = base64ct::Decoder<'i, base64ct::Base64>;
@@ -18,9 +19,8 @@ impl<'i> Base64Reader<'i> {
1819
/// Create a new Base64 reader for a byte slice containing contiguous (non-newline-delimited)
1920
/// Base64-encoded data.
2021
///
21-
/// # Returns
22-
/// - `Ok(reader)` on success.
23-
/// - `Err(Error::Base64)` if the input buffer is empty.
22+
/// # Errors
23+
/// Returns [`Error::Base64`] if the `input` buffer is empty.
2424
pub fn new(input: &'i [u8]) -> Result<Self> {
2525
let inner = Inner::new(input)?;
2626
let remaining_len = inner.remaining_len();
@@ -32,4 +32,12 @@ impl<'i> Base64Reader<'i> {
3232
}
3333
}
3434

35+
impl Debug for Base64Reader<'_> {
36+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37+
f.debug_struct("Base64Reader")
38+
.field("remaining_len", &self.remaining_len)
39+
.finish_non_exhaustive()
40+
}
41+
}
42+
3543
impl_reader_for_newtype!(Base64Reader<'_>);

ssh-encoding/src/base64/writer.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//! Base64 writer support (constant-time).
22
33
use crate::{Result, Writer};
4+
use core::fmt::{self, Debug};
5+
6+
#[cfg(doc)]
7+
use crate::Error;
48

59
/// Inner constant-time Base64 reader type from the `base64ct` crate.
610
type Inner<'o> = base64ct::Encoder<'o, base64ct::Base64>;
@@ -14,18 +18,30 @@ impl<'o> Base64Writer<'o> {
1418
/// Create a new Base64 writer which writes output to the given byte slice.
1519
///
1620
/// Output constructed using this method is not line-wrapped.
21+
///
22+
/// # Errors
23+
/// Returns [`Error::Base64`] if the `output` buffer is empty.
1724
pub fn new(output: &'o mut [u8]) -> Result<Self> {
1825
Ok(Self {
1926
inner: Inner::new(output)?,
2027
})
2128
}
2229

2330
/// Finish encoding data, returning the resulting Base64 as a `str`.
31+
///
32+
/// # Errors
33+
/// Returns [`Error::Base64`] if there is insufficient space in the output buffer.
2434
pub fn finish(self) -> Result<&'o str> {
2535
Ok(self.inner.finish()?)
2636
}
2737
}
2838

39+
impl Debug for Base64Writer<'_> {
40+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41+
f.debug_struct("Base64Writer").finish_non_exhaustive()
42+
}
43+
}
44+
2945
impl Writer for Base64Writer<'_> {
3046
fn write(&mut self, bytes: &[u8]) -> Result<()> {
3147
Ok(self.inner.encode(bytes)?)

ssh-encoding/src/checked.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{Error, Result};
66
pub trait CheckedSum<A>: Sized {
77
/// Iterate over the values of this type, computing a checked sum.
88
///
9+
/// # Errors
910
/// Returns [`Error::Length`] on overflow.
1011
fn checked_sum(self) -> Result<A>;
1112
}

ssh-encoding/src/decode.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pub trait Decode: Sized {
2222
type Error: From<Error>;
2323

2424
/// Attempt to decode a value of this type using the provided [`Reader`].
25+
///
26+
/// # Errors
27+
/// Returns errors specific to the concrete implementation of this trait.
2528
fn decode(reader: &mut impl Reader) -> core::result::Result<Self, Self::Error>;
2629
}
2730

ssh-encoding/src/encode.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,38 @@ use bytes::{Bytes, BytesMut};
1717
/// This trait describes how to encode a given type.
1818
pub trait Encode {
1919
/// Get the length of this type encoded in bytes, prior to Base64 encoding.
20+
///
21+
/// # Errors
22+
/// Returns errors specific to the concrete implementation of this trait.
2023
fn encoded_len(&self) -> Result<usize, Error>;
2124

2225
/// Encode this value using the provided [`Writer`].
26+
///
27+
/// # Errors
28+
/// Returns errors specific to the concrete implementation of this trait.
2329
fn encode(&self, writer: &mut impl Writer) -> Result<(), Error>;
2430

25-
/// Return the length of this type after encoding when prepended with a
26-
/// `uint32` length prefix.
31+
/// Return the length of this type after encoding when prepended with a `uint32` length prefix.
32+
///
33+
/// # Errors
34+
/// Returns errors specific to the concrete implementation of this trait.
2735
fn encoded_len_prefixed(&self) -> Result<usize, Error> {
2836
[4, self.encoded_len()?].checked_sum()
2937
}
3038

31-
/// Encode this value, first prepending a `uint32` length prefix
32-
/// set to [`Encode::encoded_len`].
39+
/// Encode this value, first prepending a `uint32` length prefix set to [`Encode::encoded_len`].
40+
///
41+
/// # Errors
42+
/// Returns errors specific to the concrete implementation of this trait.
3343
fn encode_prefixed(&self, writer: &mut impl Writer) -> Result<(), Error> {
3444
self.encoded_len()?.encode(writer)?;
3545
self.encode(writer)
3646
}
3747

3848
/// Encode this value, returning a `Vec<u8>` containing the encoded message.
49+
///
50+
/// # Errors
51+
/// Returns errors specific to the concrete implementation of this trait.
3952
#[cfg(feature = "alloc")]
4053
fn encode_vec(&self) -> Result<Vec<u8>, Error> {
4154
let mut ret = Vec::with_capacity(self.encoded_len()?);
@@ -44,6 +57,9 @@ pub trait Encode {
4457
}
4558

4659
/// Encode this value, returning a [`BytesMut`] containing the encoded message.
60+
///
61+
/// # Errors
62+
/// Returns errors specific to the concrete implementation of this trait.
4763
#[cfg(feature = "bytes")]
4864
fn encode_bytes(&self) -> Result<BytesMut, Error> {
4965
let mut ret = BytesMut::with_capacity(self.encoded_len()?);

ssh-encoding/src/label.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct LabelError {
4545
impl LabelError {
4646
/// Create a new [`LabelError`] for the given invalid label.
4747
#[cfg_attr(not(feature = "alloc"), allow(unused_variables))]
48+
#[must_use]
4849
pub fn new(label: &str) -> Self {
4950
Self {
5051
#[cfg(feature = "alloc")]
@@ -54,6 +55,7 @@ impl LabelError {
5455

5556
/// The invalid label string (if available).
5657
#[inline]
58+
#[must_use]
5759
pub fn label(&self) -> &str {
5860
#[cfg(not(feature = "alloc"))]
5961
{

ssh-encoding/src/lib.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
#![no_std]
2-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
2+
#![cfg_attr(docsrs, feature(doc_cfg))]
33
#![doc = include_str!("../README.md")]
44
#![doc(
55
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
66
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
77
)]
8-
#![forbid(unsafe_code)]
9-
#![warn(
10-
clippy::alloc_instead_of_core,
11-
clippy::arithmetic_side_effects,
12-
clippy::mod_module_files,
13-
clippy::panic,
14-
clippy::panic_in_result_fn,
15-
clippy::std_instead_of_alloc,
16-
clippy::std_instead_of_core,
17-
clippy::unwrap_used,
18-
missing_docs,
19-
rust_2018_idioms,
20-
unused_lifetimes,
21-
unused_qualifications
22-
)]
238

249
//! ## Conventions used in this crate
2510
//!

0 commit comments

Comments
 (0)