Skip to content

Commit 459b518

Browse files
committed
Change HpkeError::Secp256k1 into the opaque InvalidPublicKey error
Making this into an opaque error will prevent leaking implementation details
1 parent df30f3b commit 459b518

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

payjoin/src/hpke.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
273273
pub 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

285285
impl 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

289296
impl 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

Comments
 (0)