Added better error messages and context to `ESockSessionKey::from_ciphertext()`

Fortune for rsh's current commit: Small blessing − 小吉
master
Avril 3 years ago
parent 3991d82f93
commit 087a076b40
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -114,8 +114,7 @@ impl ESockSessionKey
.wrap_err(eyre!("Failed to encrypt session key with RSA public key")) .wrap_err(eyre!("Failed to encrypt session key with RSA public key"))
.with_section(|| self.clone().header("Session key was")) .with_section(|| self.clone().header("Session key was"))
.with_section({let temp = temp.len(); move || temp.header("Encoded data size was")}) .with_section({let temp = temp.len(); move || temp.header("Encoded data size was")})
.with_section(move || base64::encode(temp).header("Encoded data (base64) was")) .with_section(move || base64::encode(temp).header("Encoded data (base64) was"))?;
?;
debug_assert_eq!(_wr, output.len()); debug_assert_eq!(_wr, output.len());
Ok(output) Ok(output)
@ -126,8 +125,14 @@ impl ESockSessionKey
where <K as rsa::PublicKey>::KeyType: rsa::openssl::pkey::HasPrivate //ugh, why do we have to have this bound??? it should be implied ffs... :/ where <K as rsa::PublicKey>::KeyType: rsa::openssl::pkey::HasPrivate //ugh, why do we have to have this bound??? it should be implied ffs... :/
{ {
let mut temp = SmallVec::<[u8; RSA_CIPHERTEXT_SIZE]>::new(); let mut temp = SmallVec::<[u8; RSA_CIPHERTEXT_SIZE]>::new();
rsa::decrypt_slice_sync(data, rsa_key, &mut temp)?; rsa::decrypt_slice_sync(data, rsa_key, &mut temp)
Ok(serde_cbor::from_slice(&temp[..])?) .wrap_err(eyre!("Failed to decrypt ciphertext to session key"))
.with_section({let data = data.len(); move || data.header("Ciphertext length was")})
.with_section(|| base64::encode(data).header("Ciphertext was"))?;
Ok(serde_cbor::from_slice(&temp[..])
.wrap_err(eyre!("Failed to decode CBOR data to session key object"))
.with_section({let temp = temp.len(); move || temp.header("Encoded data size was")})
.with_section(move || base64::encode(temp).header("Encoded data (base64) was"))?)
} }
} }

Loading…
Cancel
Save