Merge pull request #67 from wiebeytec/master

Clarify public key documentation and errors
This commit is contained in:
Arun Muralidharan 2020-07-24 23:09:25 +05:30 committed by GitHub
commit f74e010207
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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>
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>
- <strong>algorithm</strong>

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());