This is an automated email from the ASF dual-hosted git repository.

yuanz pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/incubator-teaclave-trustzone-sdk.git

commit 7978b74e73fe0ba0d64d6349e8742daeb23c8d86
Author: Yuan Zhuang <[email protected]>
AuthorDate: Fri Aug 22 12:24:57 2025 +0000

    lint: Fix clippy errors in host apps
---
 examples/build_with_optee_utee_sys-rs/host/src/main.rs |  6 +++---
 examples/diffie_hellman-rs/host/src/main.rs            | 14 +++++++-------
 examples/digest-rs/host/src/main.rs                    |  4 ++--
 examples/error_handling-rs/host/src/main.rs            | 16 +++++++++++-----
 examples/hello_world-rs/host/src/main.rs               |  2 +-
 examples/hotp-rs/host/src/main.rs                      |  9 +++------
 examples/message_passing_interface-rs/host/src/main.rs |  4 +---
 examples/mnist-rs/host/src/commands/infer.rs           |  4 ++--
 examples/mnist-rs/host/src/commands/serve.rs           | 15 ++++++---------
 examples/mnist-rs/host/src/commands/train.rs           |  9 +++------
 examples/mnist-rs/host/src/tee.rs                      |  6 +++---
 examples/serde-rs/host/Cargo.toml                      |  1 -
 examples/serde-rs/host/src/main.rs                     |  9 +--------
 examples/signature_verification-rs/host/src/main.rs    |  4 ++--
 examples/supp_plugin-rs/plugin/build.rs                |  2 +-
 examples/tcp_client-rs/host/src/main.rs                |  3 +--
 optee-teec/macros/src/lib.rs                           |  4 ++++
 projects/web3/eth_wallet/host/Makefile                 |  1 -
 18 files changed, 51 insertions(+), 62 deletions(-)

diff --git a/examples/build_with_optee_utee_sys-rs/host/src/main.rs 
b/examples/build_with_optee_utee_sys-rs/host/src/main.rs
index 5b7e272..de5612e 100644
--- a/examples/build_with_optee_utee_sys-rs/host/src/main.rs
+++ b/examples/build_with_optee_utee_sys-rs/host/src/main.rs
@@ -28,10 +28,10 @@ fn inc_value(session: &mut Session) -> 
optee_teec::Result<u32> {
 
 fn main() -> optee_teec::Result<()> {
     let mut ctx = Context::new()?;
-    let uuid = Uuid::parse_str(UUID).map_err(|_|ErrorKind::BadParameters)?;
+    let uuid = Uuid::parse_str(UUID).map_err(|_| ErrorKind::BadParameters)?;
     // Ensure that multiple sessions can be opened concurrently.
-    let mut session1= ctx.open_session(uuid.clone())?;
-    let mut session2= ctx.open_session(uuid)?;
+    let mut session1 = ctx.open_session(uuid.clone())?;
+    let mut session2 = ctx.open_session(uuid)?;
     // Ensure that each session can successfully perform a call.
     println!("result is: {}", inc_value(&mut session1)?);
     println!("result is: {}", inc_value(&mut session2)?);
diff --git a/examples/diffie_hellman-rs/host/src/main.rs 
b/examples/diffie_hellman-rs/host/src/main.rs
index 687b6bb..ba30b2d 100644
--- a/examples/diffie_hellman-rs/host/src/main.rs
+++ b/examples/diffie_hellman-rs/host/src/main.rs
@@ -21,11 +21,11 @@ use proto::{Command, KEY_SIZE, UUID};
 
 fn generate_key(session: &mut Session) -> Result<(Vec<u8>, Vec<u8>)> {
     // Pass in the prime and base
-    let prime_base_vec = [0xB6, 0x73, 0x91, 0xB5, 0xD6, 0xBC, 0x95, 0x73, 
-                          0x0D, 0x53, 0x64, 0x13, 0xB0, 0x51, 0xC6, 0xB4, 
-                          0xEB, 0x9D, 0x74, 0x57, 0x8D, 0x65, 0x3A, 0x4B, 
-                          0x7A, 0xB2, 0x93, 0x27, 0xA6, 0xC1, 0xBC, 0xAB, 
-                          5];
+    let prime_base_vec = [
+        0xB6, 0x73, 0x91, 0xB5, 0xD6, 0xBC, 0x95, 0x73, 0x0D, 0x53, 0x64, 
0x13, 0xB0, 0x51, 0xC6,
+        0xB4, 0xEB, 0x9D, 0x74, 0x57, 0x8D, 0x65, 0x3A, 0x4B, 0x7A, 0xB2, 
0x93, 0x27, 0xA6, 0xC1,
+        0xBC, 0xAB, 5,
+    ];
     let p0 = ParamTmpRef::new_input(&prime_base_vec);
     // Save public and private key size
     let p1 = ParamValue::new(0, 0, ParamType::ValueOutput);
@@ -69,7 +69,7 @@ fn main() -> Result<()> {
     let uuid = Uuid::parse_str(UUID).unwrap();
     let mut session = ctx.open_session(uuid)?;
 
-    let (mut key0_public, key0_private) = generate_key(&mut session).unwrap();
+    let (key0_public, key0_private) = generate_key(&mut session).unwrap();
     let (key1_public, key1_private) = generate_key(&mut session).unwrap();
     println!(
         "get key 0 pair as public: {:?}, private: {:?}",
@@ -79,7 +79,7 @@ fn main() -> Result<()> {
         "get key 1 pair as public: {:?}, private: {:?}",
         key1_public, key1_private
     );
-    derive_key(&mut key0_public, &mut session)?;
+    derive_key(&key0_public, &mut session)?;
 
     println!("Success");
     Ok(())
diff --git a/examples/digest-rs/host/src/main.rs 
b/examples/digest-rs/host/src/main.rs
index 2375a4e..0ca384d 100644
--- a/examples/digest-rs/host/src/main.rs
+++ b/examples/digest-rs/host/src/main.rs
@@ -56,8 +56,8 @@ fn main() -> optee_teec::Result<()> {
     let mut hash: [u8; 32] = [0u8; 32];
     let mut session = ctx.open_session(uuid)?;
 
-    for i in 1..args_len - 1 {
-        update(&mut session, args[i].as_bytes())?;
+    for arg in &args[1..args_len - 1] {
+        update(&mut session, arg.as_bytes())?;
     }
 
     let hash_length = do_final(&mut session, args[args_len - 1].as_bytes(), 
&mut hash).unwrap();
diff --git a/examples/error_handling-rs/host/src/main.rs 
b/examples/error_handling-rs/host/src/main.rs
index a16825f..b9a4fca 100644
--- a/examples/error_handling-rs/host/src/main.rs
+++ b/examples/error_handling-rs/host/src/main.rs
@@ -15,9 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use optee_teec::{Context, ErrorKind, Operation, ParamType, Session, Uuid};
 use optee_teec::ParamNone;
-use proto::{UUID, Command};
+use optee_teec::{Context, ErrorKind, Operation, Uuid};
+use proto::{Command, UUID};
 
 fn main() -> optee_teec::Result<()> {
     test_error_handling();
@@ -31,14 +31,20 @@ fn test_error_handling() {
     let mut operation = Operation::new(0, ParamNone, ParamNone, ParamNone, 
ParamNone);
 
     // Test successful invocation return Ok().
-    session.invoke_command(Command::ReturnSuccess as u32, &mut 
operation).expect("success");
+    session
+        .invoke_command(Command::ReturnSuccess as u32, &mut operation)
+        .expect("success");
 
     // Test error invocation returns the requested error.
-    let e = session.invoke_command(Command::ReturnGenericError as u32, &mut 
operation).expect_err("generic error");
+    let e = session
+        .invoke_command(Command::ReturnGenericError as u32, &mut operation)
+        .expect_err("generic error");
     assert_eq!(e.kind(), ErrorKind::Generic);
 
     // Test repeated error invocation also returns the requested error.
-    let e = session.invoke_command(Command::ReturnGenericError as u32, &mut 
operation).expect_err("generic error");
+    let e = session
+        .invoke_command(Command::ReturnGenericError as u32, &mut operation)
+        .expect_err("generic error");
     assert_eq!(e.kind(), ErrorKind::Generic);
 
     println!("Test passed");
diff --git a/examples/hello_world-rs/host/src/main.rs 
b/examples/hello_world-rs/host/src/main.rs
index cfa0e0c..ab88127 100644
--- a/examples/hello_world-rs/host/src/main.rs
+++ b/examples/hello_world-rs/host/src/main.rs
@@ -17,7 +17,7 @@
 
 use optee_teec::{Context, Operation, ParamType, Session, Uuid};
 use optee_teec::{ParamNone, ParamValue};
-use proto::{UUID, Command};
+use proto::{Command, UUID};
 
 fn hello_world(session: &mut Session) -> optee_teec::Result<()> {
     let p0 = ParamValue::new(29, 0, ParamType::ValueInout);
diff --git a/examples/hotp-rs/host/src/main.rs 
b/examples/hotp-rs/host/src/main.rs
index 855660e..d7dc3ce 100644
--- a/examples/hotp-rs/host/src/main.rs
+++ b/examples/hotp-rs/host/src/main.rs
@@ -44,18 +44,15 @@ fn get_hotp(session: &mut Session) -> 
optee_teec::Result<()> {
     let p0 = ParamValue::new(0, 0, ParamType::ValueOutput);
     let mut operation = Operation::new(0, p0, ParamNone, ParamNone, ParamNone);
 
-    for i in 0..TEST_SIZE {
+    for &expected_value in &RFC4226_TEST_VALUES {
         session.invoke_command(Command::GetHOTP as u32, &mut operation)?;
         let (p0, _, _, _) = operation.parameters();
         let hotp_value = p0.a();
 
         println!("Get HOTP: {}", hotp_value);
 
-        if hotp_value != RFC4226_TEST_VALUES[i] {
-            println!(
-                "Wrong value get! Expected value: {}",
-                RFC4226_TEST_VALUES[i]
-            );
+        if hotp_value != expected_value {
+            println!("Wrong value get! Expected value: {}", expected_value);
             return Err(Error::new(ErrorKind::Generic));
         }
     }
diff --git a/examples/message_passing_interface-rs/host/src/main.rs 
b/examples/message_passing_interface-rs/host/src/main.rs
index 0ba6b8e..3fa4c4a 100644
--- a/examples/message_passing_interface-rs/host/src/main.rs
+++ b/examples/message_passing_interface-rs/host/src/main.rs
@@ -16,8 +16,6 @@
 // under the License.
 
 use optee_teec::{Context, Operation, ParamNone, ParamTmpRef, ParamType, 
ParamValue, Uuid};
-use proto;
-use url;
 
 type Result<T> = optee_teec::Result<T>;
 
@@ -40,7 +38,7 @@ impl EnclaveClient {
         let context = Context::new()?;
         Ok(Self {
             uuid: uuid.to_string(),
-            context: context,
+            context,
             buffer: vec![0; 128],
         })
     }
diff --git a/examples/mnist-rs/host/src/commands/infer.rs 
b/examples/mnist-rs/host/src/commands/infer.rs
index 8c3b339..0123469 100644
--- a/examples/mnist-rs/host/src/commands/infer.rs
+++ b/examples/mnist-rs/host/src/commands/infer.rs
@@ -48,7 +48,7 @@ pub fn execute(args: &Args) -> anyhow::Result<()> {
             anyhow::ensure!(data.len() == IMAGE_SIZE);
 
             TryInto::<Image>::try_into(data)
-                .map_err(|err| anyhow::Error::msg(format!("cannot convert {:?} 
into Image", err)))
+                .map_err(|err| anyhow::Error::msg(format!("cannot convert 
{err:?} into Image")))
         })
         .collect::<Result<Vec<_>, anyhow::Error>>()?;
     let images: Vec<Image> = args
@@ -59,7 +59,7 @@ pub fn execute(args: &Args) -> anyhow::Result<()> {
             let bytes = img.as_bytes();
             anyhow::ensure!(bytes.len() == IMAGE_SIZE);
             TryInto::<Image>::try_into(bytes)
-                .map_err(|err| anyhow::Error::msg(format!("cannot convert {:?} 
into Image", err)))
+                .map_err(|err| anyhow::Error::msg(format!("cannot convert 
{err:?} into Image")))
         })
         .collect::<Result<Vec<_>, anyhow::Error>>()?;
     binaries.extend(images);
diff --git a/examples/mnist-rs/host/src/commands/serve.rs 
b/examples/mnist-rs/host/src/commands/serve.rs
index 99ef605..620e2d3 100644
--- a/examples/mnist-rs/host/src/commands/serve.rs
+++ b/examples/mnist-rs/host/src/commands/serve.rs
@@ -40,17 +40,17 @@ pub fn execute(args: &Args) -> anyhow::Result<()> {
     let mut caller = crate::tee::InferenceTaConnector::new(&mut ctx, &record)?;
 
     let addr = format!("0.0.0.0:{}", args.port);
-    println!("Server runs on: {}", addr);
+    println!("Server runs on: {addr}");
 
     let server = Server::http(&addr)
-        .map_err(|err| anyhow::Error::msg(format!("cannot start server: {:?}", 
err)))?;
+        .map_err(|err| anyhow::Error::msg(format!("cannot start server: 
{err:?}")))?;
 
     loop {
         let mut request = server.recv()?;
         let response = match handle(&mut caller, &mut request) {
             Ok(v) => v,
             Err(err) => {
-                eprintln!("unexpected error: {:#?}", err);
+                eprintln!("unexpected error: {err:#?}");
                 Response::from_string("Internal Error").with_status_code(500)
             }
         };
@@ -88,7 +88,7 @@ fn handle_image(
     }
     let result = handle_infer(caller, img.as_bytes())?;
 
-    println!("Performing Inference with Image, Result is {}", result);
+    println!("Performing Inference with Image, Result is {result}");
     Ok(Response::from_data(result.to_string()))
 }
 
@@ -103,14 +103,11 @@ fn handle_binary(
     }
 
     let result = handle_infer(caller, &data)?;
-    println!("Performing Inference with Binary, Result is {}", result);
+    println!("Performing Inference with Binary, Result is {result}");
     Ok(Response::from_data(result.to_string()))
 }
 
-fn handle_infer(
-    caller: &mut crate::tee::InferenceTaConnector,
-    image: &[u8],
-) -> anyhow::Result<u8> {
+fn handle_infer(caller: &mut crate::tee::InferenceTaConnector, image: &[u8]) 
-> anyhow::Result<u8> {
     let result = caller.infer_batch(bytemuck::cast_slice(image))?;
     Ok(result[0])
 }
diff --git a/examples/mnist-rs/host/src/commands/train.rs 
b/examples/mnist-rs/host/src/commands/train.rs
index 4e8fac0..ab1d214 100644
--- a/examples/mnist-rs/host/src/commands/train.rs
+++ b/examples/mnist-rs/host/src/commands/train.rs
@@ -79,7 +79,7 @@ pub fn execute(args: &Args) -> anyhow::Result<()> {
     // Export the model to the given path
     if let Some(output_path) = args.output.as_ref() {
         let record = trainer.export()?;
-        println!("Export record to \"{}\"", output_path);
+        println!("Export record to \"{output_path}\"");
         std::fs::write(output_path, &record)?;
     }
     println!("Train Success");
@@ -111,11 +111,8 @@ fn check_download_mnist_data() -> 
anyhow::Result<rust_mnist::Mnist> {
             continue;
         }
 
-        let url = format!(
-            "https://storage.googleapis.com/cvdf-datasets/mnist/{}.gz";,
-            filename
-        );
-        println!("Download {} from {}", filename, url);
+        let url = 
format!("https://storage.googleapis.com/cvdf-datasets/mnist/{filename}.gz";);
+        println!("Download {filename} from {url}");
         let body = ureq::get(&url).call()?.body_mut().read_to_vec()?;
 
         anyhow::ensure!(body.len() == *compressed_size as usize);
diff --git a/examples/mnist-rs/host/src/tee.rs 
b/examples/mnist-rs/host/src/tee.rs
index a3ff51c..34ae91b 100644
--- a/examples/mnist-rs/host/src/tee.rs
+++ b/examples/mnist-rs/host/src/tee.rs
@@ -18,7 +18,7 @@
 use optee_teec::{Context, ErrorKind, Operation, ParamNone, ParamTmpRef, 
Session, Uuid};
 use proto::{inference, train, Image};
 
-const MAX_OUTPUT_SERIALIZE_SIZE: usize = 1 * 1024;
+const MAX_OUTPUT_SERIALIZE_SIZE: usize = 1024;
 const MAX_MODEL_RECORD_SIZE: usize = 10 * 1024 * 1024;
 
 pub struct TrainerTaConnector {
@@ -60,7 +60,7 @@ impl TrainerTaConnector {
             op.parameters().2.updated_size()
         };
         let result = serde_json::from_slice(&buffer[0..size]).map_err(|err| {
-            println!("proto error: {:?}", err);
+            println!("proto error: {err:?}");
             ErrorKind::BadFormat
         })?;
         Ok(result)
@@ -81,7 +81,7 @@ impl TrainerTaConnector {
             op.parameters().2.updated_size()
         };
         let result = serde_json::from_slice(&buffer[0..size]).map_err(|err| {
-            println!("proto error: {:?}", err);
+            println!("proto error: {err:?}");
             ErrorKind::BadFormat
         })?;
         Ok(result)
diff --git a/examples/serde-rs/host/Cargo.toml 
b/examples/serde-rs/host/Cargo.toml
index 73fa781..290278d 100644
--- a/examples/serde-rs/host/Cargo.toml
+++ b/examples/serde-rs/host/Cargo.toml
@@ -25,7 +25,6 @@ description = "An example of Rust OP-TEE TrustZone SDK."
 edition = "2018"
 
 [dependencies]
-serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 proto = { path = "../proto" }
 optee-teec = { path = "../../../optee-teec" }
diff --git a/examples/serde-rs/host/src/main.rs 
b/examples/serde-rs/host/src/main.rs
index cdeaab0..c557dfa 100644
--- a/examples/serde-rs/host/src/main.rs
+++ b/examples/serde-rs/host/src/main.rs
@@ -16,14 +16,7 @@
 // under the License.
 
 use optee_teec::{Context, Operation, ParamNone, ParamTmpRef, Session, Uuid};
-use proto::{Command, UUID};
-use serde::Deserialize;
-
-#[derive(Deserialize, Debug)]
-struct Point {
-    x: i32,
-    y: i32,
-}
+use proto::{Command, Point, UUID};
 
 fn serde(session: &mut Session) -> optee_teec::Result<()> {
     let mut buffer = [0u8; 128];
diff --git a/examples/signature_verification-rs/host/src/main.rs 
b/examples/signature_verification-rs/host/src/main.rs
index 73c480c..b76fa02 100644
--- a/examples/signature_verification-rs/host/src/main.rs
+++ b/examples/signature_verification-rs/host/src/main.rs
@@ -65,11 +65,11 @@ fn main() -> optee_teec::Result<()> {
     let mut public_key = [0x00u8; PUBLIC_KEY_SIZE];
     let mut signature = [0x00u8; SIGNATURE_SIZE];
 
-    sign(&mut session, &message, &mut public_key, &mut signature)?;
+    sign(&mut session, message, &mut public_key, &mut signature)?;
     println!("CA: public key: {:?}", &public_key);
     println!("CA: signature: {:?}", &signature);
 
-    verify(&mut session, &message, &public_key, &signature)?;
+    verify(&mut session, message, &public_key, &signature)?;
     println!("Success");
 
     Ok(())
diff --git a/examples/supp_plugin-rs/plugin/build.rs 
b/examples/supp_plugin-rs/plugin/build.rs
index 3f01ec7..d7140c5 100644
--- a/examples/supp_plugin-rs/plugin/build.rs
+++ b/examples/supp_plugin-rs/plugin/build.rs
@@ -29,7 +29,7 @@ fn main() -> std::io::Result<()> {
     let plugin_uuid = Uuid::parse_str(proto::PLUGIN_UUID).unwrap();
     let (time_low, time_mid, time_hi_and_version, clock_seq_and_node) = 
plugin_uuid.as_fields();
 
-    write!(buffer, "\n")?;
+    writeln!(buffer)?;
     write!(
         buffer,
         "const PLUGIN_UUID_STRUCT: optee_teec::raw::TEEC_UUID = 
optee_teec::raw::TEEC_UUID {{
diff --git a/examples/tcp_client-rs/host/src/main.rs 
b/examples/tcp_client-rs/host/src/main.rs
index 6a0acdf..4e48fbf 100644
--- a/examples/tcp_client-rs/host/src/main.rs
+++ b/examples/tcp_client-rs/host/src/main.rs
@@ -63,7 +63,7 @@ fn main() -> optee_teec::Result<()> {
     let port = listen_addr.port();
 
     let child = thread::spawn(move || {
-        for request in server.incoming_requests() {
+        if let Some(request) = server.incoming_requests().next() {
             println!(
                 "received request! method: {:?}, url: {:?}, headers: {:?}",
                 request.method(),
@@ -73,7 +73,6 @@ fn main() -> optee_teec::Result<()> {
 
             let response = tiny_http::Response::from_string("hello world");
             request.respond(response).unwrap();
-            break;
         }
     });
     // Use the IP address directly to ensure we're actually trying an IPv6
diff --git a/optee-teec/macros/src/lib.rs b/optee-teec/macros/src/lib.rs
index 0c958bb..b337352 100644
--- a/optee-teec/macros/src/lib.rs
+++ b/optee-teec/macros/src/lib.rs
@@ -129,6 +129,10 @@ pub fn plugin_invoke(_args: TokenStream, input: 
TokenStream) -> TokenStream {
         .into_token_stream();
 
     quote!(
+        // temporary workaround for this error:
+        // error: this public function might dereference a raw pointer but is 
not marked `unsafe`
+        // should remove this allow macro when fix clippy errors of optee-* 
crates
+        #[allow(clippy::not_unsafe_ptr_arg_deref)]
         pub fn _plugin_invoke(
             cmd: u32,
             sub_cmd: u32,
diff --git a/projects/web3/eth_wallet/host/Makefile 
b/projects/web3/eth_wallet/host/Makefile
index 1e4d8b8..3faa2dd 100644
--- a/projects/web3/eth_wallet/host/Makefile
+++ b/projects/web3/eth_wallet/host/Makefile
@@ -23,7 +23,6 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
 LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
 
 OUT_DIR := $(CURDIR)/target/$(TARGET)/release
-
 all: host strip
 
 host:


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to