Skip to content

Commit

Permalink
Change HpkeError::Secp256k1 into the opaque InvalidPublicKey error
Browse files Browse the repository at this point in the history
Making this into an opaque error will prevent leaking implementation
details
  • Loading branch information
shinghim committed Jan 25, 2025
1 parent 27f7813 commit d5077ca
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions payjoin/src/hpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn pad_plaintext(msg: &mut Vec<u8>, padded_length: usize) -> Result<&[u8], HpkeE
/// Error from de/encrypting a v2 Hybrid Public Key Encryption payload.
#[derive(Debug, PartialEq)]
pub enum HpkeError {
Secp256k1(secp256k1::Error),
InvalidPublicKey,
Hpke(hpke::HpkeError),
InvalidKeyLength,
PayloadTooLarge { actual: usize, max: usize },
Expand All @@ -283,7 +283,7 @@ impl From<hpke::HpkeError> for HpkeError {
}

impl From<secp256k1::Error> for HpkeError {
fn from(value: secp256k1::Error) -> Self { Self::Secp256k1(value) }
fn from(_: secp256k1::Error) -> Self { Self::InvalidPublicKey }
}

impl fmt::Display for HpkeError {
Expand All @@ -301,7 +301,7 @@ impl fmt::Display for HpkeError {
)
}
PayloadTooShort => write!(f, "Payload too small"),
Secp256k1(e) => e.fmt(f),
InvalidPublicKey => write!(f, "Invalid public key"),
}
}
}
Expand All @@ -314,7 +314,7 @@ impl error::Error for HpkeError {
Hpke(e) => Some(e),
PayloadTooLarge { .. } => None,
InvalidKeyLength | PayloadTooShort => None,
Secp256k1(e) => Some(e),
InvalidPublicKey => None,
}
}
}
Expand Down

0 comments on commit d5077ca

Please sign in to comment.