From 944f9313b3228370d2a985044d471bea55f4383c Mon Sep 17 00:00:00 2001 From: peg Date: Mon, 28 Oct 2024 10:25:07 +0100 Subject: [PATCH] Slightly improve error conversion --- pallets/staking/src/lib.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index 36db71dc0..954b1f3a4 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -345,6 +345,17 @@ pub mod pallet { FailedAttestationCheck, } + impl From for Error { + fn from(error: pck::PckParseVerifyError) -> Self { + match error { + pck::PckParseVerifyError::Parse => Error::::PckCertificateParse, + pck::PckParseVerifyError::Verify => Error::::PckCertificateVerify, + pck::PckParseVerifyError::BadPublicKey => Error::::PckCertificateBadPublicKey, + pck::PckParseVerifyError::NoCertificate => Error::::PckCertificateNoCertificate, + } + } + } + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -545,16 +556,11 @@ pub mod pallet { T::PckCertChainVerifier::verify_pck_certificate_chain( joining_server_info.pck_certificate_chain, ) - .map_err(|error| match error { - pck::PckParseVerifyError::Parse => Error::::PckCertificateParse, - pck::PckParseVerifyError::Verify => Error::::PckCertificateVerify, - pck::PckParseVerifyError::BadPublicKey => { - Error::::PckCertificateBadPublicKey - }, - pck::PckParseVerifyError::NoCertificate => { - Error::::PckCertificateNoCertificate - }, + .map_err(|error| { + let e: Error = error.into(); + e })?; + let server_info = ServerInfo:: { tss_account: joining_server_info.tss_account, x25519_public_key: joining_server_info.x25519_public_key,