1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 11:25:07 +00:00

LibCrypto: Use ErrorOr error handling for parsing DER

This replaces a mixture of `Result`, `Optional`, and a custom error enum
with our usual `ErrorOr`-based error handling.
This commit is contained in:
Tim Schumacher 2023-02-07 23:47:28 +01:00 committed by Linus Groh
parent e80eb09fe5
commit f5fb1396e8
4 changed files with 107 additions and 197 deletions

View file

@ -47,9 +47,9 @@ RSA::KeyPairType RSA::parse_rsa_key(ReadonlyBytes der)
// Then enter the sequence
{
auto error = decoder.enter();
if (error.has_value()) {
if (error.is_error()) {
// Something was weird with the input.
dbgln_if(RSA_PARSE_DEBUG, "RSA key parse failed: {}", error.value());
dbgln_if(RSA_PARSE_DEBUG, "RSA key parse failed: {}", error.error());
return keypair;
}
}
@ -74,16 +74,16 @@ RSA::KeyPairType RSA::parse_rsa_key(ReadonlyBytes der)
// It's a sequence, now let's see if it's actually an RSA key.
auto error = decoder.enter();
if (error.has_value()) {
if (error.is_error()) {
// Shenanigans!
dbgln_if(RSA_PARSE_DEBUG, "RSA PKCS#8 public key parse failed: {}", error.value());
dbgln_if(RSA_PARSE_DEBUG, "RSA PKCS#8 public key parse failed: {}", error.error());
return false;
}
ScopeGuard leave { [&] {
auto error = decoder.leave();
if (error.has_value()) {
dbgln_if(RSA_PARSE_DEBUG, "RSA key parse failed: {}", error.value());
if (error.is_error()) {
dbgln_if(RSA_PARSE_DEBUG, "RSA key parse failed: {}", error.error());
has_read_error = true;
}
} };