Clarify public key documentation and errors

This commit is contained in:
Wiebe Cazemier 2020-07-16 17:28:46 +02:00
parent 42536e5f01
commit 11cb283483
5 changed files with 19 additions and 2 deletions

View file

@ -34,6 +34,7 @@ enum class AlgorithmErrc
SigningErr = 1,
VerificationErr,
KeyNotFoundErr,
InvalidKeyErr,
NoneAlgorithmUsed, // Not an actual error!
};

View file

@ -273,6 +273,17 @@ public:
}
};
class InvalidKeyError final: public VerificationError
{
public:
/**
*/
InvalidKeyError(std::string msg)
: VerificationError(std::move(msg))
{
}
};
/**
* Derived from VerificationError.
* Thrown when there type expectation mismatch

View file

@ -91,7 +91,7 @@ verify_result_t PEMSign<Hasher>::verify(
ev_pkey_deletor};
if (!pkey) {
ec = AlgorithmErrc::VerificationErr;
ec = AlgorithmErrc::InvalidKeyErr;
return { false, ec };
}

View file

@ -856,6 +856,10 @@ void jwt_throw_exception(const std::error_code& ec)
{
switch (static_cast<AlgorithmErrc>(ec.value()))
{
case AlgorithmErrc::InvalidKeyErr:
{
throw InvalidKeyError(ec.message());
}
case AlgorithmErrc::VerificationErr:
{
throw InvalidSignatureError(ec.message());