public inbox for tpm-protocol@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] refactor!(TpmRc): remove unnecessary Result wrapper
@ 2025-08-31  9:54 Jarkko Sakkinen
  2025-08-31 13:12 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Jarkko Sakkinen @ 2025-08-31  9:54 UTC (permalink / raw)
  To: tpm-protocol; +Cc: Jarkko Sakkinen

`Result` wrapper in the return value of `TpmRc::base()` exists only to
retain API backwards compatibility in 0.10.x branch. Remove the wrapper
in the main branch.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 src/data/tpm_rc.rs | 20 +++++++-------------
 tests/runner.rs    |  2 +-
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/data/tpm_rc.rs b/src/data/tpm_rc.rs
index c7fa71a..fa8756f 100644
--- a/src/data/tpm_rc.rs
+++ b/src/data/tpm_rc.rs
@@ -165,12 +165,9 @@ pub struct TpmRc {
 impl TpmRc {
     /// Returns the base error code, with handle, parameter, or session index
     /// stripped out.
-    ///
-    /// # Errors
-    ///
-    /// This method returns a `Result` in order to retain API compatibility.
-    pub fn base(self) -> Result<TpmRcBase, TpmErrorKind> {
-        Ok(self.base)
+    #[must_use]
+    pub fn base(self) -> TpmRcBase {
+        self.base
     }
 
     #[must_use]
@@ -250,14 +247,11 @@ impl From<TpmRcBase> for TpmRc {
 
 impl Display for TpmRc {
     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
-        if let Ok(base) = self.base() {
-            if let Some(index) = self.index() {
-                write!(f, "[{base}, {index}]")
-            } else {
-                write!(f, "{base}")
-            }
+        let base = self.base();
+        if let Some(index) = self.index() {
+            write!(f, "[{base}, {index}]")
         } else {
-            write!(f, "TPM_RC_UNKNOWN(0x{:08X})", self.value())
+            write!(f, "{base}")
         }
     }
 }
diff --git a/tests/runner.rs b/tests/runner.rs
index 83fc209..218d813 100644
--- a/tests/runner.rs
+++ b/tests/runner.rs
@@ -239,7 +239,7 @@ fn test_tpm_rc_base_from_raw() {
 
     for (description, raw_rc, expected_base) in cases {
         let rc = TpmRc::try_from(raw_rc).unwrap();
-        assert_eq!(rc.base(), Ok(expected_base), "{description}");
+        assert_eq!(rc.base(), expected_base, "{description}");
     }
 }
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-31 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-31  9:54 [PATCH] refactor!(TpmRc): remove unnecessary Result wrapper Jarkko Sakkinen
2025-08-31 13:12 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox