From 20849df6b64d9af955b4971e4ffd622e51c06258 Mon Sep 17 00:00:00 2001 From: Arnaud Brousseau Date: Mon, 24 Jun 2024 12:50:20 -0500 Subject: [PATCH] Fix lints --- src/Cargo.lock | 95 +++++++++++++++++++-- src/integration/src/bin/pivot_remote_tls.rs | 8 +- src/integration/tests/borsh_serialize.rs | 72 +++++++++------- src/integration/tests/remote_tls.rs | 6 +- src/qos_net/src/proxy.rs | 2 +- 5 files changed, 133 insertions(+), 50 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 12d2e695..9d244008 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -52,6 +52,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -317,16 +328,39 @@ dependencies = [ "generic-array", ] +[[package]] +name = "borsh" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +dependencies = [ + "borsh-derive 0.10.3", + "hashbrown 0.12.3", +] + [[package]] name = "borsh" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" dependencies = [ - "borsh-derive", + "borsh-derive 1.5.1", "cfg_aliases", ] +[[package]] +name = "borsh-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" +dependencies = [ + "borsh-derive-internal", + "borsh-schema-derive-internal", + "proc-macro-crate 0.1.5", + "proc-macro2", + "syn 1.0.109", +] + [[package]] name = "borsh-derive" version = "1.5.1" @@ -334,13 +368,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" dependencies = [ "once_cell", - "proc-macro-crate", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", "syn 2.0.68", "syn_derive", ] +[[package]] +name = "borsh-derive-internal" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "borsh-schema-derive-internal" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -896,6 +952,9 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] [[package]] name = "hashbrown" @@ -1139,7 +1198,7 @@ name = "integration" version = "0.1.0" dependencies = [ "aws-nitro-enclaves-nsm-api", - "borsh", + "borsh 1.5.1", "nix", "qos_client", "qos_core", @@ -1678,6 +1737,15 @@ dependencies = [ "elliptic-curve", ] +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -1725,7 +1793,7 @@ name = "qos_client" version = "0.1.0" dependencies = [ "aws-nitro-enclaves-nsm-api", - "borsh", + "borsh 1.5.1", "lazy_static", "p256 0.12.0", "qos_core", @@ -1748,7 +1816,7 @@ name = "qos_core" version = "0.1.0" dependencies = [ "aws-nitro-enclaves-nsm-api", - "borsh", + "borsh 1.5.1", "libc", "nix", "qos_crypto", @@ -1783,7 +1851,7 @@ name = "qos_host" version = "0.1.0" dependencies = [ "axum", - "borsh", + "borsh 1.5.1", "qos_core", "qos_hex", "serde", @@ -1795,7 +1863,7 @@ dependencies = [ name = "qos_net" version = "0.1.0" dependencies = [ - "borsh", + "borsh 0.10.3", "hickory-resolver", "qos_core", "qos_test_primitives", @@ -1811,7 +1879,7 @@ version = "0.1.0" dependencies = [ "aws-nitro-enclaves-cose", "aws-nitro-enclaves-nsm-api", - "borsh", + "borsh 1.5.1", "hex-literal", "p384 0.12.0", "qos_hex", @@ -1827,7 +1895,7 @@ name = "qos_p256" version = "0.1.0" dependencies = [ "aes-gcm", - "borsh", + "borsh 1.5.1", "hkdf", "hmac", "p256 0.12.0", @@ -2446,6 +2514,15 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + [[package]] name = "toml_datetime" version = "0.6.6" diff --git a/src/integration/src/bin/pivot_remote_tls.rs b/src/integration/src/bin/pivot_remote_tls.rs index e3c5ece2..747ad25b 100644 --- a/src/integration/src/bin/pivot_remote_tls.rs +++ b/src/integration/src/bin/pivot_remote_tls.rs @@ -4,7 +4,7 @@ use std::{ sync::Arc, }; -use borsh::{BorshDeserialize, BorshSerialize}; +use borsh::BorshDeserialize; use integration::PivotRemoteTlsMsg; use qos_core::{ io::{SocketAddress, TimeVal}, @@ -73,10 +73,10 @@ impl RequestProcessor for Processor { let fetched_content = std::str::from_utf8(&response_bytes).unwrap(); - PivotRemoteTlsMsg::RemoteTlsResponse(format!( + + borsh::to_vec(&PivotRemoteTlsMsg::RemoteTlsResponse(format!( "Content fetched successfully ({read_to_end_result} bytes): {fetched_content}" - )) - .try_to_vec() + ))) .expect("RemoteTlsResponse is valid borsh") } PivotRemoteTlsMsg::RemoteTlsResponse(_) => { diff --git a/src/integration/tests/borsh_serialize.rs b/src/integration/tests/borsh_serialize.rs index 3f7f44f7..b4452f25 100644 --- a/src/integration/tests/borsh_serialize.rs +++ b/src/integration/tests/borsh_serialize.rs @@ -1,42 +1,50 @@ #[cfg(test)] mod tests { - use borsh::{BorshSerialize, BorshDeserialize}; + use borsh::{BorshDeserialize, BorshSerialize}; - #[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq)] - struct TestSerializable { - a: u32, - b: String, - c: Vec, - } + #[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq)] + struct TestSerializable { + a: u32, + b: String, + c: Vec, + } - #[test] - fn test_serializable_to_vec() { - let inst = TestSerializable { - a: 42, - b: "Hello, world!".to_string(), - c: vec![1, 2, 3, 4, 5], - }; + #[test] + fn test_serializable_to_vec() { + let inst = TestSerializable { + a: 42, + b: "Hello, world!".to_string(), + c: vec![1, 2, 3, 4, 5], + }; - // Expected serialized output - let expected_serialized: Vec = vec![ - 42, 0, 0, 0, // a: u32 (little-endian) - 13, 0, 0, 0, // Length of the string b (13) - 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, // "Hello, world!" as bytes - 5, 0, 0, 0, // Length of the vector c (5) - 1, 2, 3, 4, 5 // c: Vec - ]; + // Expected serialized output + let expected_serialized: Vec = vec![ + 42, 0, 0, 0, // a: u32 (little-endian) + 13, 0, 0, 0, // Length of the string b (13) + 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, + 33, // "Hello, world!" as bytes + 5, 0, 0, 0, // Length of the vector c (5) + 1, 2, 3, 4, 5, // c: Vec + ]; - // Serialize the instance - let serialized = borsh::to_vec(&inst).expect("Serialization failed"); + // Serialize the instance + let serialized = borsh::to_vec(&inst).expect("Serialization failed"); - // Assert that the serialized output matches the expected value - assert_eq!(serialized, expected_serialized, "Serialized bytes differ from the expected value"); + // Assert that the serialized output matches the expected value + assert_eq!( + serialized, expected_serialized, + "Serialized bytes differ from the expected value" + ); - // Deserialize the serialized data back to a new instance - let deserialized_inst: TestSerializable = borsh::BorshDeserialize::try_from_slice(&serialized) - .expect("Deserialization failed"); + // Deserialize the serialized data back to a new instance + let deserialized_inst: TestSerializable = + borsh::BorshDeserialize::try_from_slice(&serialized) + .expect("Deserialization failed"); - // Assert that the deserialized instance matches the original instance - assert_eq!(deserialized_inst, inst, "Deserialized instance differs from the original"); - } + // Assert that the deserialized instance matches the original instance + assert_eq!( + deserialized_inst, inst, + "Deserialized instance differs from the original" + ); + } } diff --git a/src/integration/tests/remote_tls.rs b/src/integration/tests/remote_tls.rs index ec6e6c82..db8b1745 100644 --- a/src/integration/tests/remote_tls.rs +++ b/src/integration/tests/remote_tls.rs @@ -1,6 +1,5 @@ use std::{process::Command, str}; -use borsh::BorshSerialize; use integration::{PivotRemoteTlsMsg, PIVOT_REMOTE_TLS_PATH, QOS_NET_PATH}; use qos_core::{ client::Client, @@ -34,11 +33,10 @@ fn fetch_remote_tls_content() { TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS), ); - let app_request = PivotRemoteTlsMsg::RemoteTlsRequest { + let app_request = borsh::to_vec(&PivotRemoteTlsMsg::RemoteTlsRequest { host: "api.turnkey.com".to_string(), path: "/health".to_string(), - } - .try_to_vec() + }) .unwrap(); let response = enclave_client.send(&app_request).unwrap(); diff --git a/src/qos_net/src/proxy.rs b/src/qos_net/src/proxy.rs index d5cde7d5..59332a56 100644 --- a/src/qos_net/src/proxy.rs +++ b/src/qos_net/src/proxy.rs @@ -220,7 +220,7 @@ impl server::RequestProcessor for Proxy { dns_resolvers, dns_port, ) - }, + } ProxyMsg::ConnectByIpRequest { ip, port } => { println!("Proxy connecting to {ip}:{port}"); self.connect_by_ip(ip, port)