Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clippy gh action and linting #531

Merged
merged 32 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3818c35
fix: miscellaneous fixes on documentation, notary-server.
yuroitaki Jul 1, 2024
aafb5b7
Apply clippy fix.
yuroitaki Jul 1, 2024
0aae4cd
Apply clippy fix.
yuroitaki Jul 1, 2024
54a4eb9
Apply clippy fix.
yuroitaki Jul 1, 2024
e302537
Apply clippy fix.
yuroitaki Jul 1, 2024
5439517
Apply clippy fix.
yuroitaki Jul 1, 2024
885dd7c
Apply clippy fix.
yuroitaki Jul 1, 2024
9eef733
Apply clippy fix.
yuroitaki Jul 1, 2024
4d78e00
Apply clippy fix.
yuroitaki Jul 1, 2024
e361a86
Apply clippy fix.
yuroitaki Jul 1, 2024
74bdb4a
Merge branch 'fix/misc-fixes' into fix/gh-clippy-action
yuroitaki Jul 1, 2024
fb46708
Correct ci.yml and build script.
yuroitaki Jul 1, 2024
0ae5ba2
Apply clippy fix.
yuroitaki Jul 1, 2024
13f7722
Apply fmt.
yuroitaki Jul 1, 2024
33234df
Correct clippy fix for tls-mpc.
yuroitaki Jul 2, 2024
df60fec
Correct clippy fix for tls-client.
yuroitaki Jul 3, 2024
b873088
Correct clippy fix for tls-client.
yuroitaki Jul 4, 2024
bc24a98
Update ci and local build.
yuroitaki Jul 4, 2024
7370848
Revert "Merge branch 'fix/misc-fixes' into fix/gh-clippy-action"
yuroitaki Jul 4, 2024
65cb093
Apply clippy fix.
yuroitaki Jul 4, 2024
0ec4967
Correct spacing and extra changes.
yuroitaki Jul 4, 2024
12e30ec
Apply fmt.
yuroitaki Jul 4, 2024
146c48d
Change cargo hack install logic.
yuroitaki Jul 4, 2024
999703a
Merge branch 'dev' into fix/gh-clippy-action
yuroitaki Jul 12, 2024
ec7222b
Revert clippy change client buffer len.
yuroitaki Jul 12, 2024
0f269b0
Merge branch 'fix/gh-clippy-action' of github.com:tlsnotary/tlsn into…
yuroitaki Jul 12, 2024
6bca631
Revert clippy ignore.
yuroitaki Jul 16, 2024
dc170b5
Merge branch 'dev' into fix/gh-clippy-action
yuroitaki Jul 16, 2024
53b70f1
remove cargo hack, relax clippy lints
sinui0 Jul 22, 2024
00bf845
remove unused features and dead tests
sinui0 Jul 22, 2024
dd253c4
appease clippy again
sinui0 Jul 22, 2024
820a13c
remove dead features
sinui0 Jul 22, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- components/prf
- components/tls
- components/tls/tls-mpc
- tlsn
- notary
- tlsn
- tlsn/tests-integration
include:
- package: components/tls/tls-mpc
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
components: clippy

- name: "Clippy"
run: cargo clippy --all-features --examples -- -D warnings
run: cargo clippy --all-features --all-targets -- -D warnings

- name: Use caching
uses: Swatinem/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions build_all.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

for package in components/uid-mux components/actors/actor-ot components/cipher components/universal-hash components/aead components/key-exchange components/point-addition components/prf components/tls tlsn; do
for package in components/tls components/cipher components/universal-hash components/aead components/key-exchange components/prf tlsn notary; do
pushd $package
# cargo update
cargo clean
cargo build
cargo test
cargo clippy --all-features -- -D warnings || exit
cargo build || exit
cargo test || exit
popd
done
1 change: 1 addition & 0 deletions components/aead/src/aes_gcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl<Ctx: Context> MpcAesGcm<Ctx> {
}

#[async_trait]
#[allow(clippy::blocks_in_conditions)]
Copy link
Member Author

@yuroitaki yuroitaki Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be declared due to this upstream issue rust-lang/rust-clippy#12281 — we shall file a ticket to remove this declaration once the upstream fix is released

impl<Ctx: Context> Aead for MpcAesGcm<Ctx> {
type Error = AesGcmError;

Expand Down
1 change: 1 addition & 0 deletions components/aead/src/aes_gcm/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub(crate) async fn compute_tag<
/// Without it, the party which receives the other's tag share first could trivially compute
/// a tag share which would cause an invalid message to be accepted.
#[instrument(level = "debug", skip_all, err)]
#[allow(clippy::too_many_arguments)]
pub(crate) async fn verify_tag<
Ctx: Context,
C: StreamCipher<Aes128Ctr> + ?Sized,
Expand Down
9 changes: 5 additions & 4 deletions components/cipher/block-cipher/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ where
}

#[async_trait]
#[allow(clippy::blocks_in_conditions)]
impl<C, E> BlockCipher<C> for MpcBlockCipher<C, E>
where
C: BlockCipherCircuit,
Expand All @@ -138,7 +139,7 @@ where
.state
.key
.clone()
.ok_or_else(|| BlockCipherError::key_not_set())?;
.ok_or_else(BlockCipherError::key_not_set)?;

for _ in 0..count {
let vars = self.define_block(visibility);
Expand Down Expand Up @@ -173,7 +174,7 @@ where
.state
.key
.clone()
.ok_or_else(|| BlockCipherError::key_not_set())?;
.ok_or_else(BlockCipherError::key_not_set)?;

let BlockVars { msg, ciphertext } =
if let Some(vars) = self.state.preprocessed_private.pop_front() {
Expand Down Expand Up @@ -209,7 +210,7 @@ where
.state
.key
.clone()
.ok_or_else(|| BlockCipherError::key_not_set())?;
.ok_or_else(BlockCipherError::key_not_set)?;

let BlockVars { msg, ciphertext } =
if let Some(vars) = self.state.preprocessed_private.pop_front() {
Expand Down Expand Up @@ -248,7 +249,7 @@ where
.state
.key
.clone()
.ok_or_else(|| BlockCipherError::key_not_set())?;
.ok_or_else(BlockCipherError::key_not_set)?;

let BlockVars { msg, ciphertext } =
if let Some(vars) = self.state.preprocessed_public.pop_front() {
Expand Down
12 changes: 6 additions & 6 deletions components/cipher/stream-cipher/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ pub(crate) enum ExecutionMode {
}

pub(crate) fn is_valid_mode(mode: &ExecutionMode, input_text: &InputText) -> bool {
match (mode, input_text) {
(ExecutionMode::Mpc, _) => true,
(ExecutionMode::Prove, InputText::Private { .. }) => true,
(ExecutionMode::Verify, InputText::Blind { .. }) => true,
_ => false,
}
matches!(
(mode, input_text),
(ExecutionMode::Mpc, _)
| (ExecutionMode::Prove, InputText::Private { .. })
| (ExecutionMode::Verify, InputText::Blind { .. })
)
}
3 changes: 2 additions & 1 deletion components/cipher/stream-cipher/src/keystream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl BlockVars {
self.blocks
.iter()
.flat_map(|block| block.iter())
.cloned()
.take(len)
.cloned()
.map(|byte| ValueRef::Value { id: byte })
.collect()
}
Expand Down Expand Up @@ -132,6 +132,7 @@ impl<C: CtrCircuit> KeyStream<C> {
}

#[instrument(level = "debug", skip_all, err)]
#[allow(clippy::too_many_arguments)]
pub(crate) async fn compute<T>(
&mut self,
thread: &mut T,
Expand Down
13 changes: 7 additions & 6 deletions components/cipher/stream-cipher/src/stream_cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ where
.state
.encoded_key_iv
.as_ref()
.ok_or_else(|| StreamCipherError::key_not_set())?;
.ok_or_else(StreamCipherError::key_not_set)?;

let keystream = self
.state
Expand Down Expand Up @@ -260,6 +260,7 @@ where
}

#[async_trait]
#[allow(clippy::blocks_in_conditions)]
impl<C, E> StreamCipher<C> for MpcStreamCipher<C, E>
where
C: CtrCircuit,
Expand All @@ -275,7 +276,7 @@ where
.state
.encoded_key_iv
.clone()
.ok_or_else(|| StreamCipherError::key_not_set())?;
.ok_or_else(StreamCipherError::key_not_set)?;

let [key, iv]: [_; 2] = self
.thread
Expand All @@ -298,7 +299,7 @@ where
.state
.encoded_key_iv
.clone()
.ok_or_else(|| StreamCipherError::key_not_set())?;
.ok_or_else(StreamCipherError::key_not_set)?;

self.thread.decode_blind(&[key, iv]).await?;

Expand Down Expand Up @@ -327,7 +328,7 @@ where
.state
.encoded_key_iv
.as_ref()
.ok_or_else(|| StreamCipherError::key_not_set())?;
.ok_or_else(StreamCipherError::key_not_set)?;

self.state
.keystream
Expand Down Expand Up @@ -567,7 +568,7 @@ where
.state
.key_iv
.clone()
.ok_or_else(|| StreamCipherError::key_not_set())?;
.ok_or_else(StreamCipherError::key_not_set)?;

let plaintext = C::apply_keystream(
&key,
Expand Down Expand Up @@ -643,7 +644,7 @@ where
.state
.encoded_key_iv
.as_ref()
.ok_or_else(|| StreamCipherError::key_not_set())?;
.ok_or_else(StreamCipherError::key_not_set)?;

let key_block = self
.state
Expand Down
2 changes: 2 additions & 0 deletions components/key-exchange/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ where
}

#[async_trait]
#[allow(clippy::blocks_in_conditions)]
impl<Ctx, C0, C1, E> KeyExchange for MpcKeyExchange<Ctx, C0, C1, E>
where
Ctx: Context,
Expand Down Expand Up @@ -457,6 +458,7 @@ mod tests {
use rand_core::SeedableRng;
use serio::channel::MemoryDuplex;

#[allow(clippy::type_complexity)]
fn create_pair() -> (
MpcKeyExchange<
STExecutor<MemoryDuplex>,
Expand Down
1 change: 1 addition & 0 deletions components/prf/hmac-sha256/src/prf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ where
}

#[async_trait]
#[allow(clippy::blocks_in_conditions)]
impl<E> Prf for MpcPrf<E>
where
E: Memory + Load + Execute + Decode + Send,
Expand Down
6 changes: 2 additions & 4 deletions components/tls/tls-client-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ pub fn bind_client<T: AsyncRead + AsyncWrite + Send + Unpin + 'static>(
tx_recv_fut = tx_receiver.next().fuse();
}

if server_closed && client.plaintext_is_empty() {
if client.buffer_len().await? == 0 {
break 'conn;
}
if server_closed && client.plaintext_is_empty() && client.buffer_len().await? == 0 {
break 'conn;
Comment on lines +145 to +146
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want to create the client.buffer_len() future unless the first two conditions are met.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@th4s you're right! so we can follow clippy's advice actually @sinui0 :)

}

select_biased! {
Expand Down
6 changes: 0 additions & 6 deletions components/tls/tls-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ license = "MIT OR Apache-2.0"
version = "0.1.0-alpha.6"
edition = "2021"
autobenches = false
build = "build.rs"

[lib]
name = "tls_client"

[build-dependencies]
rustversion = { version = "1", optional = true }

[dependencies]
tlsn-tls-backend = { path = "../tls-backend" }
tlsn-tls-core = { path = "../tls-core" }
Expand All @@ -37,9 +33,7 @@ web-time.workspace = true
[features]
default = ["logging", "tls12"]
logging = ["log"]
dangerous_configuration = []
tls12 = []
read_buf = ["rustversion"]

[dev-dependencies]
env_logger.workspace = true
Expand Down
13 changes: 0 additions & 13 deletions components/tls/tls-client/build.rs

This file was deleted.

16 changes: 0 additions & 16 deletions components/tls/tls-client/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ impl ConfigBuilder<WantsVerifier> {
},
}
}

#[cfg(feature = "dangerous_configuration")]
/// Set a custom certificate verifier.
pub fn with_custom_certificate_verifier(
self,
verifier: Arc<dyn verify::ServerCertVerifier>,
) -> ConfigBuilder<WantsClientCert> {
ConfigBuilder {
state: WantsClientCert {
cipher_suites: self.state.cipher_suites,
kx_groups: self.state.kx_groups,
versions: self.state.versions,
verifier,
},
}
}
}

/// A config builder state where the caller needs to supply a certificate transparency policy or
Expand Down
28 changes: 0 additions & 28 deletions components/tls/tls-client/src/client/client_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@ impl ClientConfig {
.any(|cs| cs.version().version == v)
}

/// Access configuration options whose use is dangerous and requires
/// extra care.
#[cfg(feature = "dangerous_configuration")]
pub fn dangerous(&mut self) -> danger::DangerousClientConfig {
danger::DangerousClientConfig { cfg: self }
}

pub(super) fn find_cipher_suite(&self, suite: CipherSuite) -> Option<SupportedCipherSuite> {
self.cipher_suites
.iter()
Expand All @@ -186,27 +179,6 @@ impl ClientConfig {
}
}

/// Container for unsafe APIs
#[cfg(feature = "dangerous_configuration")]
pub(super) mod danger {
use std::sync::Arc;

use super::{verify::ServerCertVerifier, ClientConfig};

/// Accessor for dangerous configuration options.
pub struct DangerousClientConfig<'a> {
/// The underlying ClientConfig
pub cfg: &'a mut ClientConfig,
}

impl<'a> DangerousClientConfig<'a> {
/// Overrides the default `ServerCertVerifier` with something else.
pub fn set_certificate_verifier(&mut self, verifier: Arc<dyn ServerCertVerifier>) {
self.cfg.verifier = verifier;
}
}
}

#[derive(Debug, PartialEq)]
enum EarlyDataState {
Disabled,
Expand Down
43 changes: 0 additions & 43 deletions components/tls/tls-client/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,49 +111,6 @@ impl<'a> io::Read for Reader<'a> {

Ok(len)
}

/// Obtain plaintext data received from the peer over this TLS connection.
///
/// If the peer closes the TLS session, this returns `Ok(())` without filling
/// any more of the buffer once all the pending data has been read. No further
/// data can be received on that connection, so the underlying TCP connection
/// should be half-closed too.
///
/// If the peer closes the TLS session uncleanly (a TCP EOF without sending a
/// `close_notify` alert) this function returns `Err(ErrorKind::UnexpectedEof.into())`
/// once any pending data has been read.
///
/// Note that support for `close_notify` varies in peer TLS libraries: many do not
/// support it and uncleanly close the TCP connection (this might be
/// vulnerable to truncation attacks depending on the application protocol).
/// This means applications using rustls must both handle EOF
/// from this function, *and* unexpected EOF of the underlying TCP connection.
///
/// If there are no bytes to read, this returns `Err(ErrorKind::WouldBlock.into())`.
///
/// You may learn the number of bytes available at any time by inspecting
/// the return of [`Connection::process_new_packets`].
#[cfg(read_buf)]
fn read_buf(&mut self, buf: &mut io::ReadBuf<'_>) -> io::Result<()> {
let before = buf.filled_len();
self.received_plaintext.read_buf(buf)?;
let len = buf.filled_len() - before;

if len == 0 && buf.capacity() > 0 {
// No bytes available:
match (self.peer_cleanly_closed, self.has_seen_eof) {
// cleanly closed; don't care about TCP EOF: express this as Ok(0)
(true, _) => {}
// unclean closure
(false, true) => return Err(io::ErrorKind::UnexpectedEof.into()),
// connection still going, but need more data: signal `WouldBlock` so that
// the caller knows this
(false, false) => return Err(io::ErrorKind::WouldBlock.into()),
}
}

Ok(())
}
}

#[derive(Copy, Clone, Eq, PartialEq)]
Expand Down
Loading
Loading