@@ -271,7 +271,7 @@ fn pad_plaintext(msg: &mut Vec<u8>, padded_length: usize) -> Result<&[u8], HpkeE
271271/// Error from de/encrypting a v2 Hybrid Public Key Encryption payload.
272272#[ derive( Debug , PartialEq ) ]
273273pub enum HpkeError {
274- Secp256k1 ( secp256k1 :: Error ) ,
274+ InvalidPublicKey ,
275275 Hpke ( hpke:: HpkeError ) ,
276276 InvalidKeyLength ,
277277 PayloadTooLarge { actual : usize , max : usize } ,
@@ -283,7 +283,14 @@ impl From<hpke::HpkeError> for HpkeError {
283283}
284284
285285impl From < secp256k1:: Error > for HpkeError {
286- fn from ( value : secp256k1:: Error ) -> Self { Self :: Secp256k1 ( value) }
286+ fn from ( value : secp256k1:: Error ) -> Self {
287+ match & value {
288+ // As of writing, this is the only relevant variant that could arise here.
289+ // This may need to be updated if relevant variants are added to secp256k1
290+ secp256k1:: Error :: InvalidPublicKey => Self :: InvalidPublicKey ,
291+ _ => panic ! ( "Unsupported variant of secp256k1::Error" ) ,
292+ }
293+ }
287294}
288295
289296impl fmt:: Display for HpkeError {
@@ -301,7 +308,7 @@ impl fmt::Display for HpkeError {
301308 )
302309 }
303310 PayloadTooShort => write ! ( f, "Payload too small" ) ,
304- Secp256k1 ( e ) => e . fmt ( f ) ,
311+ InvalidPublicKey => write ! ( f , "Invalid public key" ) ,
305312 }
306313 }
307314}
@@ -314,7 +321,7 @@ impl error::Error for HpkeError {
314321 Hpke ( e) => Some ( e) ,
315322 PayloadTooLarge { .. } => None ,
316323 InvalidKeyLength | PayloadTooShort => None ,
317- Secp256k1 ( e ) => Some ( e ) ,
324+ InvalidPublicKey => None ,
318325 }
319326 }
320327}
0 commit comments