From 7815a874acd9c0478b5babee9cc87b3c7ba9c9f1 Mon Sep 17 00:00:00 2001 From: peg Date: Thu, 3 Oct 2024 16:03:05 +0200 Subject: [PATCH] Error handling --- pallets/staking/src/lib.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index 73e7bc757..30062696c 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -133,11 +133,6 @@ pub mod pallet { pub pck_certificate_chain: Vec>, } - // impl From for ServerInfo { - // fn from(joining_server_info: JoiningServerInfo) -> Self { - // } - // } - /// Info that is requiered to do a proactive refresh #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, Default)] pub struct RefreshInfo { @@ -362,6 +357,10 @@ pub mod pallet { NoUnnominatingWhenSigner, NoUnnominatingWhenNextSigner, NoChangingThresholdAccountWhenSigner, + PckCertificateParse, + PckCertificateVerify, + PckCertificateBadPublicKey, + PckCertificateNoCertificate, } #[pallet::event] @@ -572,7 +571,16 @@ pub mod pallet { T::PckCertChainVerifier::verify_pck_certificate_chain( joining_server_info.pck_certificate_chain, ) - .unwrap(); + .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 + }, + })?; let server_info = ServerInfo:: { tss_account: joining_server_info.tss_account, x25519_public_key: joining_server_info.x25519_public_key,