You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by iv...@apache.org on 2026/10/16 03:51:11 UTC
(teaclave-trustzone-sdk) 02/02: optee-teec: use explicit TEEC_LOGIN_* codes for ConnectionMethods
This is an automated email from the ASF dual-hosted git repository.
ivila pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git
commit 9561be0394a6d393d44f8e3aeb367fcdcd8cbd4a
Author: ivila <iv...@apache.org>
AuthorDate: Thu Oct 15 17:53:38 2026 +0800
optee-teec: use explicit TEEC_LOGIN_* codes for ConnectionMethods
---
crates/optee-teec/src/session.rs | 60 ++++++++++++++++++++++++++++++++++------
1 file changed, 52 insertions(+), 8 deletions(-)
diff --git a/crates/optee-teec/src/session.rs b/crates/optee-teec/src/session.rs
index 805648e..9d33377 100644
--- a/crates/optee-teec/src/session.rs
+++ b/crates/optee-teec/src/session.rs
@@ -17,26 +17,31 @@
use super::context::InnerContext;
use crate::{Context, Operation, Param, Result, Uuid, raw, teec_check_with_origin};
+use num_enum::{FromPrimitive, IntoPrimitive};
use std::{
ptr,
sync::{Arc, Mutex},
};
/// Session login methods.
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Debug, PartialEq, FromPrimitive, IntoPrimitive)]
+#[repr(u32)]
pub enum ConnectionMethods {
/// No login data is provided.
- LoginPublic,
+ LoginPublic = raw::TEEC_LOGIN_PUBLIC,
/// Login data about the user running the Client Application process is provided.
- LoginUser,
+ LoginUser = raw::TEEC_LOGIN_USER,
/// Login data about the group running the Client Application process is provided.
- LoginGroup,
+ LoginGroup = raw::TEEC_LOGIN_GROUP,
/// Login data about the running Client Application itself is provided.
- LoginApplication,
+ LoginApplication = raw::TEEC_LOGIN_APPLICATION,
/// Login data about the user and the running Client Application itself is provided.
- LoginUserApplication,
+ LoginUserApplication = raw::TEEC_LOGIN_USER_APPLICATION,
/// Login data about the group and the running Client Application itself is provided.
- LoginGroupApplication,
+ LoginGroupApplication = raw::TEEC_LOGIN_GROUP_APPLICATION,
+ /// An unnamed or implementation-defined login type.
+ #[num_enum(catch_all)]
+ Unknown(u32),
}
/// An opaque, thread-movable OP-TEE session handle.
@@ -110,7 +115,7 @@ impl Session {
raw_ctx,
&mut raw_session,
raw_uuid,
- login as u32,
+ u32::from(login),
ptr::null(),
raw_operation,
&mut err_origin,
@@ -152,3 +157,42 @@ impl Drop for Session {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::ConnectionMethods;
+ use super::raw;
+
+ /// Guarantee: every `ConnectionMethods` variant converts to the matching
+ /// `TEEC_LOGIN_*` constant and the conversion round-trips through the
+ /// primitive login code, so a wrong discriminant can never be sent to
+ /// `TEEC_OpenSession`.
+ #[test]
+ fn connection_methods_round_trip_to_tee_constants() {
+ let cases = [
+ (ConnectionMethods::LoginPublic, raw::TEEC_LOGIN_PUBLIC),
+ (ConnectionMethods::LoginUser, raw::TEEC_LOGIN_USER),
+ (ConnectionMethods::LoginGroup, raw::TEEC_LOGIN_GROUP),
+ (
+ ConnectionMethods::LoginApplication,
+ raw::TEEC_LOGIN_APPLICATION,
+ ),
+ (
+ ConnectionMethods::LoginUserApplication,
+ raw::TEEC_LOGIN_USER_APPLICATION,
+ ),
+ (
+ ConnectionMethods::LoginGroupApplication,
+ raw::TEEC_LOGIN_GROUP_APPLICATION,
+ ),
+ ];
+
+ for (method, expected) in cases {
+ let code = u32::from(method);
+ assert_eq!(code, expected, "variant {method:?} has wrong TEEC code");
+
+ let round_tripped = ConnectionMethods::from(code);
+ assert_eq!(round_tripped, method);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org