ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • error_code 정의 참고 코드 조각
    프로그래밍/코드 조각 2018. 10. 28. 00:59
    반응형
    enum class VerificationErrc
    {
    //Algorithms provided does not match with header
    InvalidAlgorithm = 1,
    //Token is expired at the time of decoding
    TokenExpired,
    //The issuer specified does not match with payload
    InvalidIssuer,
    //The subject specified does not match with payload
    InvalidSubject,
    //The field IAT is not present or is of invalid type
    InvalidIAT,
    //Checks for the existence of JTI
    //if validate_jti is passed in decode
    InvalidJTI,
    //The audience specified does not match with payload
    InvalidAudience,
    //Decoded before nbf time
    ImmatureSignature,
    //Signature match error
    InvalidSignature,
    // Invalid value type used for known claims
    TypeConversionError,
    };

    namespace std
    {
    template <>
    struct is_error_code_enum<jwt::VerificationErrc>: true_type {};
    }

    struct VerificationErrorCategory: std::error_category
    {
    const char* name() const noexcept override
    {
    return "verification";
    }

    std::string message(int ev) const override
    {
    switch (static_cast<VerificationErrc>(ev))
    {
    case VerificationErrc::InvalidAlgorithm:
    return "invalid algorithm";
    case VerificationErrc::TokenExpired:
    return "token expired";
    case VerificationErrc::InvalidIssuer:
    return "invalid issuer";
    case VerificationErrc::InvalidSubject:
    return "invalid subject";
    case VerificationErrc::InvalidAudience:
    return "invalid audience";
    case VerificationErrc::InvalidIAT:
    return "invalid iat";
    case VerificationErrc::InvalidJTI:
    return "invalid jti";
    case VerificationErrc::ImmatureSignature:
    return "immature signature";
    case VerificationErrc::InvalidSignature:
    return "invalid signature";
    case VerificationErrc::TypeConversionError:
    return "type conversion error";
    };
    return "unknown verification error";
    assert (0 && "Code not reached");
    }
    };

    const VerificationErrorCategory theVerificationErrorCategory {};

    // Create the AlgorithmErrc error code
    inline std::error_code make_error_code(VerificationErrc err)
    {
    return { static_cast<int>(err), theVerificationErrorCategory };
    }


    반응형
Designed by Tistory.