mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-16 17:58:32 +00:00
Add error codes for signing error checks
This commit is contained in:
parent
2290c8733a
commit
53a281640f
6 changed files with 275 additions and 70 deletions
48
include/jwt/impl/error_codes.ipp
Normal file
48
include/jwt/impl/error_codes.ipp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef CPP_JWT_ERROR_CODES_IPP
|
||||
#define CPP_JWT_ERROR_CODES_IPP
|
||||
|
||||
namespace jwt {
|
||||
// Anonymous namespace
|
||||
namespace {
|
||||
|
||||
/**
|
||||
*/
|
||||
struct AlgorithmErrCategory: std::error_category
|
||||
{
|
||||
const char* name() const noexcept override
|
||||
{
|
||||
return "algorithms";
|
||||
}
|
||||
|
||||
std::string message(int ev) const override
|
||||
{
|
||||
switch (static_cast<AlgorithmErrc>(ev))
|
||||
{
|
||||
case AlgorithmErrc::SigningErr:
|
||||
return "signing failed";
|
||||
case AlgorithmErrc::VerificationErr:
|
||||
return "verification failed";
|
||||
case AlgorithmErrc::NoneAlgorithmUsed:
|
||||
return "none algorithm used";
|
||||
};
|
||||
|
||||
assert (0 && "Code not reached");
|
||||
}
|
||||
};
|
||||
|
||||
// Create global object for the error categories
|
||||
const AlgorithmErrCategory theAlgorithmErrCategory {};
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create the AlgorithmErrc error code
|
||||
std::error_code make_error_code(AlgorithmErrc err)
|
||||
{
|
||||
return { static_cast<int>(err), theAlgorithmErrCategory };
|
||||
}
|
||||
|
||||
|
||||
} // END namespace jwt
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue