mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-16 09:48:30 +00:00
Ad more exceptions
This commit is contained in:
parent
c484ced63d
commit
77c11e8eb9
2 changed files with 134 additions and 1 deletions
|
@ -45,7 +45,7 @@ public:
|
|||
|
||||
/**
|
||||
*/
|
||||
class VerificationError final: public std::runtime_error
|
||||
class VerificationError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -56,6 +56,84 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
class InvalidAlgorithmError final: public VerificationError
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*/
|
||||
InvalidAlgorithmError(std::string msg)
|
||||
: VerificationError(std::move(msg))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
class TokenExpiredError final: public VerificationError
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*/
|
||||
TokenExpiredError(std::string msg)
|
||||
: VerificationError(std::move(msg))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
class InvalidIssuerError final: public VerificationError
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*/
|
||||
InvalidIssuerError(std::string msg)
|
||||
: VerificationError(std::move(msg))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
class InvalidAudienceError final: public VerificationError
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*/
|
||||
InvalidAudienceError(std::string msg)
|
||||
: VerificationError(std::move(msg))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
class ImmatureSignatureError final: public VerificationError
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*/
|
||||
ImmatureSignatureError(std::string msg)
|
||||
: VerificationError(std::move(msg))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
class InvalidSignatureError final: public VerificationError
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*/
|
||||
InvalidSignatureError(std::string msg)
|
||||
: VerificationError(std::move(msg))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // END namespace jwt
|
||||
|
||||
#endif
|
||||
|
|
|
@ -557,6 +557,61 @@ jwt_object decode(const string_view enc_str,
|
|||
return jwt_obj;
|
||||
}
|
||||
|
||||
|
||||
void jwt_throw_exception(const std::error_code& ec)
|
||||
{
|
||||
const auto& cat = ec.category();
|
||||
|
||||
if (&cat == &theVerificationErrorCategory)
|
||||
{
|
||||
switch (ec.value()) {
|
||||
case VerificationErrc::InvalidAlgorithm:
|
||||
{
|
||||
throw InvalidAlgorithmError(ec.message());
|
||||
}
|
||||
case VerificationErrc::TokenExpired:
|
||||
{
|
||||
throw TokenExpiredError(ec.message());
|
||||
}
|
||||
case VerificationErrc::InvalidIssuer:
|
||||
{
|
||||
throw InvalidIssuerError(ec.message());
|
||||
}
|
||||
case VerificationErrc::InvalidAudience:
|
||||
{
|
||||
throw InvalidAudienceError(ec.message());
|
||||
}
|
||||
case VerificationErrc::ImmatureSignature:
|
||||
{
|
||||
throw ImmatureSignatureError(ec.message());
|
||||
}
|
||||
case VerificationErrc::InvalidSignature:
|
||||
{
|
||||
throw InvalidSignatureError(ec.message());
|
||||
}
|
||||
default:
|
||||
assert (0 && "Unknown error code");
|
||||
};
|
||||
}
|
||||
|
||||
if (&cat == &theDecodeErrorCategory)
|
||||
{
|
||||
throw DecodeError(ec.message());
|
||||
}
|
||||
|
||||
if (&cat == &theAlgorithmErrCategory)
|
||||
{
|
||||
switch (ec.value()) {
|
||||
case AlgorithmErrc::VerificationErr:
|
||||
throw InvalidSignatureError(ec.message());
|
||||
default:
|
||||
assert (0 && "Unknown error code or not to be treated as an error");
|
||||
};
|
||||
}
|
||||
|
||||
assert (0 && "Unknown error code category");
|
||||
}
|
||||
|
||||
} // END namespace jwt
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue