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

@ -299,7 +299,8 @@ All the parameters are basically a function which returns an instance of a type
- <strong>secret</strong> - <strong>secret</strong>
Used to pass the key which could be some random string or public certificate data as string. Used to pass the key which could be some random string or the bytes of the PEM encoded public key
file in PEM format (wrapped in -----BEGIN PUBLIC KEY----- block) as string.
The passed string type must be convertible to <code>jwt::string_view</code> The passed string type must be convertible to <code>jwt::string_view</code>
- <strong>algorithm</strong> - <strong>algorithm</strong>

View file

@ -34,6 +34,7 @@ enum class AlgorithmErrc
SigningErr = 1, SigningErr = 1,
VerificationErr, VerificationErr,
KeyNotFoundErr, KeyNotFoundErr,
InvalidKeyErr,
NoneAlgorithmUsed, // Not an actual error! 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. * Derived from VerificationError.
* Thrown when there type expectation mismatch * Thrown when there type expectation mismatch

View file

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

View file

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