mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-15 09:18:33 +00:00
Merge pull request #67 from wiebeytec/master
Clarify public key documentation and errors
This commit is contained in:
commit
f74e010207
5 changed files with 19 additions and 2 deletions
|
@ -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>
|
||||||
|
|
|
@ -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!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue