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

mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git

commit 754ea7dd9357dd44f70a6c4d4468c7deb46626c9
Author: Mingshen Sun <[email protected]>
AuthorDate: Wed Feb 26 17:28:49 2020 -0800

    [attestation] Polish AttestationAlgorithm
---
 attestation/src/lib.rs | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/attestation/src/lib.rs b/attestation/src/lib.rs
index 70029d8..26f234a 100644
--- a/attestation/src/lib.rs
+++ b/attestation/src/lib.rs
@@ -50,6 +50,16 @@ pub(crate) enum AttestationAlgorithm {
     SgxEcdsa,
 }
 
+impl AttestationAlgorithm {
+    pub(crate) fn from_str(s: &str) -> Option<Self> {
+        match s {
+            "sgx_epid" => Some(AttestationAlgorithm::SgxEpid),
+            "sgx_ecdsa" => Some(AttestationAlgorithm::SgxEcdsa),
+            _ => None,
+        }
+    }
+}
+
 #[derive(Clone)]
 pub struct AttestationServiceConfig {
     algo: AttestationAlgorithm,
@@ -76,11 +86,8 @@ impl AttestationConfig {
         let hex = hex::decode(spid_str).expect("Illegal SPID provided");
         spid.id = <[u8; 16]>::try_from(hex.as_slice()).expect("Illegal SPID 
provided");
 
-        let algo = match algorithm {
-            "sgx_epid" => AttestationAlgorithm::SgxEpid,
-            "sgx_ecdsa" => AttestationAlgorithm::SgxEcdsa,
-            _ => panic!("Unsupported remote attestation algorithm"),
-        };
+        let algo = AttestationAlgorithm::from_str(algorithm)
+            .unwrap_or_else(|| panic!("Unsupported remote attestation 
algorithm"));
 
         let att_service_cfg = AttestationServiceConfig {
             algo,


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

Reply via email to