mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-06-02 18:07:42 +00:00
Added exception handling and test for key/secret not present
This commit is contained in:
parent
99f3c1db86
commit
a5e18cc4f4
4 changed files with 42 additions and 12 deletions
|
@ -581,15 +581,6 @@ jwt_object decode(const string_view enc_str,
|
|||
ec = DecodeErrc::SignatureFormatError;
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (!dparams.has_secret) {
|
||||
ec = DecodeErrc::KeyNotPresent;
|
||||
return obj;
|
||||
}
|
||||
} else {
|
||||
if (dparams.has_secret) {
|
||||
ec = DecodeErrc::KeyNotRequiredForNoneAlg;
|
||||
}
|
||||
}
|
||||
|
||||
//throws decode error
|
||||
|
@ -607,7 +598,12 @@ jwt_object decode(const string_view enc_str,
|
|||
}
|
||||
|
||||
//Verify the signature only if some algorithm was used
|
||||
if (obj.header().algo() != algorithm::NONE) {
|
||||
if (obj.header().algo() != algorithm::NONE)
|
||||
{
|
||||
if (!dparams.has_secret) {
|
||||
ec = DecodeErrc::KeyNotPresent;
|
||||
return obj;
|
||||
}
|
||||
jwt_signature jsign{dparams.secret};
|
||||
|
||||
// Length of the encoded header and payload only.
|
||||
|
@ -698,6 +694,10 @@ void jwt_throw_exception(const std::error_code& ec)
|
|||
{
|
||||
throw SignatureFormatError(ec.message());
|
||||
}
|
||||
case DecodeErrc::KeyNotPresent:
|
||||
{
|
||||
throw KeyNotPresentError(ec.message());
|
||||
}
|
||||
case DecodeErrc::KeyNotRequiredForNoneAlg:
|
||||
{
|
||||
// Not an error. Just to be ignored.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue