Goby3  3.1.5a
2024.05.23
jwt.h File Reference
#include "goby/util/thirdparty/jwt-cpp/picojson/picojson.h"
#include "base.h"
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <algorithm>
#include <chrono>
#include <codecvt>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <set>
#include <system_error>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include "traits/kazuho-picojson/defaults.h"

Go to the source code of this file.

Classes

struct  jwt::error::signature_verification_exception
 
struct  jwt::error::signature_generation_exception
 
struct  jwt::error::rsa_exception
 
struct  jwt::error::ecdsa_exception
 
struct  jwt::error::token_verification_exception
 
struct  std::is_error_code_enum< jwt::error::rsa_error >
 
struct  std::is_error_code_enum< jwt::error::ecdsa_error >
 
struct  std::is_error_code_enum< jwt::error::signature_verification_error >
 
struct  std::is_error_code_enum< jwt::error::signature_generation_error >
 
struct  std::is_error_code_enum< jwt::error::token_verification_error >
 
struct  jwt::algorithm::none
 "none" algorithm. More...
 
struct  jwt::algorithm::hmacsha
 Base class for HMAC family of algorithms. More...
 
struct  jwt::algorithm::rsa
 Base class for RSA family of algorithms. More...
 
struct  jwt::algorithm::ecdsa
 Base class for ECDSA family of algorithms. More...
 
struct  jwt::algorithm::eddsa
 Base class for EdDSA family of algorithms. More...
 
struct  jwt::algorithm::pss
 Base class for PSS-RSA family of algorithms. More...
 
struct  jwt::algorithm::hs256
 
struct  jwt::algorithm::hs384
 
struct  jwt::algorithm::hs512
 
struct  jwt::algorithm::rs256
 
struct  jwt::algorithm::rs384
 
struct  jwt::algorithm::rs512
 
struct  jwt::algorithm::es256
 
struct  jwt::algorithm::es384
 
struct  jwt::algorithm::es512
 
struct  jwt::algorithm::es256k
 
struct  jwt::algorithm::ed25519
 
struct  jwt::algorithm::ed448
 
struct  jwt::algorithm::ps256
 
struct  jwt::algorithm::ps384
 
struct  jwt::algorithm::ps512
 
struct  jwt::details::make_void< Ts >
 
struct  jwt::details::nonesuch
 
struct  jwt::details::detector< Default, AlwaysVoid, Op, Args >
 
struct  jwt::details::detector< Default, void_t< Op< Args... > >, Op, Args... >
 
struct  jwt::details::supports_get_type< traits_type, value_type >
 
struct  jwt::details::supports_as_object< traits_type, value_type, object_type >
 
struct  jwt::details::supports_as_array< traits_type, value_type, array_type >
 
struct  jwt::details::supports_as_string< traits_type, value_type, string_type >
 
struct  jwt::details::supports_as_number< traits_type, value_type, number_type >
 
struct  jwt::details::supports_as_integer< traits_type, value_type, integer_type >
 
struct  jwt::details::supports_as_boolean< traits_type, value_type, boolean_type >
 
struct  jwt::details::is_valid_traits< traits >
 
struct  jwt::details::is_valid_json_value< value_type >
 
struct  jwt::details::supports_begin< object_type >
 
struct  jwt::details::supports_end< object_type >
 
struct  jwt::details::has_subcription_operator< object_type, string_type >
 
struct  jwt::details::has_subcription_operator< object_type, string_type >::sfinae_true< class >
 
struct  jwt::details::is_subcription_operator_signature< object_type, value_type, string_type >
 
struct  jwt::details::is_valid_json_object< value_type, string_type, object_type >
 
struct  jwt::details::is_valid_json_array< value_type, array_type >
 
struct  jwt::details::has_operate_plus_method< string_type >
 
struct  jwt::details::has_operate_plus_method< string_type >::sfinae_true< class >
 
struct  jwt::details::is_valid_json_string< string_type, integer_type >
 
struct  jwt::details::is_valid_json_types< value_type, string_type, integer_type, object_type, array_type >
 
class  jwt::basic_claim< json_traits >
 a class to store a generic JSON value as claim More...
 
struct  jwt::error::invalid_json_exception
 
struct  jwt::error::claim_not_present_exception
 
class  jwt::details::map_of_claims< json_traits >
 
class  jwt::payload< json_traits >
 
class  jwt::header< json_traits >
 
class  jwt::decoded_jwt< json_traits >
 
class  jwt::builder< json_traits >
 
struct  jwt::verify_ops::verify_context< json_traits >
 
struct  jwt::verify_ops::equals_claim< json_traits, in_header >
 
struct  jwt::verify_ops::date_before_claim< json_traits, in_header >
 
struct  jwt::verify_ops::date_after_claim< json_traits, in_header >
 
struct  jwt::verify_ops::is_subset_claim< json_traits, in_header >
 
struct  jwt::verify_ops::insensitive_string_claim< json_traits, in_header >
 
class  jwt::verifier< Clock, json_traits >
 
class  jwt::jwk< json_traits >
 JSON Web Key. More...
 
class  jwt::jwks< json_traits >
 JWK Set. More...
 
struct  jwt::default_clock
 

Namespaces

 jwt
 JSON Web Token.
 
 jwt::error
 Everything related to error codes issued by the library.
 
 jwt::helper
 A collection for working with certificates.
 
 jwt::algorithm
 Various cryptographic algorithms when working with JWT.
 
 jwt::json
 JSON Abstractions for working with any library.
 
 jwt::details
 
 jwt::verify_ops
 

Macros

#define PICOJSON_USE_INT64
 
#define JWT_CLAIM_EXPLICIT   explicit
 

Typedefs

using jwt::date = std::chrono::system_clock::time_point
 
template<typename... Ts>
using jwt::details::void_t = typename make_void< Ts... >::type
 
template<template< class... > class Op, class... Args>
using jwt::details::is_detected = typename detector< nonesuch, void, Op, Args... >::value
 
template<template< class... > class Op, class... Args>
using jwt::details::is_detected_t = typename detector< nonesuch, void, Op, Args... >::type
 
template<typename traits_type >
using jwt::details::get_type_function = decltype(traits_type::get_type)
 
template<typename traits_type , typename value_type >
using jwt::details::is_get_type_signature = typename std::is_same< get_type_function< traits_type >, json::type(const value_type &)>
 
template<typename traits_type >
using jwt::details::as_object_function = decltype(traits_type::as_object)
 
template<typename traits_type , typename value_type , typename object_type >
using jwt::details::is_as_object_signature = typename std::is_same< as_object_function< traits_type >, object_type(const value_type &)>
 
template<typename traits_type >
using jwt::details::as_array_function = decltype(traits_type::as_array)
 
template<typename traits_type , typename value_type , typename array_type >
using jwt::details::is_as_array_signature = typename std::is_same< as_array_function< traits_type >, array_type(const value_type &)>
 
template<typename traits_type >
using jwt::details::as_string_function = decltype(traits_type::as_string)
 
template<typename traits_type , typename value_type , typename string_type >
using jwt::details::is_as_string_signature = typename std::is_same< as_string_function< traits_type >, string_type(const value_type &)>
 
template<typename traits_type >
using jwt::details::as_number_function = decltype(traits_type::as_number)
 
template<typename traits_type , typename value_type , typename number_type >
using jwt::details::is_as_number_signature = typename std::is_same< as_number_function< traits_type >, number_type(const value_type &)>
 
template<typename traits_type >
using jwt::details::as_integer_function = decltype(traits_type::as_int)
 
template<typename traits_type , typename value_type , typename integer_type >
using jwt::details::is_as_integer_signature = typename std::is_same< as_integer_function< traits_type >, integer_type(const value_type &)>
 
template<typename traits_type >
using jwt::details::as_boolean_function = decltype(traits_type::as_bool)
 
template<typename traits_type , typename value_type , typename boolean_type >
using jwt::details::is_as_boolean_signature = typename std::is_same< as_boolean_function< traits_type >, boolean_type(const value_type &)>
 
template<typename traits_type >
using jwt::details::has_mapped_type = typename traits_type::mapped_type
 
template<typename traits_type >
using jwt::details::has_key_type = typename traits_type::key_type
 
template<typename traits_type >
using jwt::details::has_value_type = typename traits_type::value_type
 
template<typename object_type >
using jwt::details::has_iterator = typename object_type::iterator
 
template<typename object_type >
using jwt::details::has_const_iterator = typename object_type::const_iterator
 
template<typename object_type >
using jwt::details::is_begin_signature = typename std::is_same< decltype(std::declval< object_type >().begin()), has_iterator< object_type > >
 
template<typename object_type >
using jwt::details::is_begin_const_signature = typename std::is_same< decltype(std::declval< const object_type >().begin()), has_const_iterator< object_type > >
 
template<typename object_type >
using jwt::details::is_end_signature = typename std::is_same< decltype(std::declval< object_type >().end()), has_iterator< object_type > >
 
template<typename object_type >
using jwt::details::is_end_const_signature = typename std::is_same< decltype(std::declval< const object_type >().end()), has_const_iterator< object_type > >
 
template<typename object_type , typename string_type >
using jwt::details::is_count_signature = typename std::is_integral< decltype(std::declval< const object_type >().count(std::declval< const string_type >()))>
 
template<typename object_type , typename value_type , typename string_type >
using jwt::details::is_at_const_signature = typename std::is_same< decltype(std::declval< const object_type >().at(std::declval< const string_type >())), const value_type & >
 
template<typename string_type , typename integer_type >
using jwt::details::is_substr_start_end_index_signature = typename std::is_same< decltype(std::declval< string_type >().substr(std::declval< integer_type >(), std::declval< integer_type >())), string_type >
 
template<typename string_type , typename integer_type >
using jwt::details::is_substr_start_index_signature = typename std::is_same< decltype(std::declval< string_type >().substr(std::declval< integer_type >())), string_type >
 
template<typename string_type >
using jwt::details::is_std_operate_plus_signature = typename std::is_same< decltype(std::operator+(std::declval< string_type >(), std::declval< string_type >())), string_type >
 

Enumerations

enum  jwt::error::rsa_error {
  jwt::error::rsa_error::ok = 0, jwt::error::rsa_error::cert_load_failed = 10, jwt::error::rsa_error::get_key_failed, jwt::error::rsa_error::write_key_failed,
  jwt::error::rsa_error::write_cert_failed, jwt::error::rsa_error::convert_to_pem_failed, jwt::error::rsa_error::load_key_bio_write, jwt::error::rsa_error::load_key_bio_read,
  jwt::error::rsa_error::create_mem_bio_failed, jwt::error::rsa_error::no_key_provided
}
 Errors related to processing of RSA signatures. More...
 
enum  jwt::error::ecdsa_error {
  jwt::error::ecdsa_error::ok = 0, jwt::error::ecdsa_error::load_key_bio_write = 10, jwt::error::ecdsa_error::load_key_bio_read, jwt::error::ecdsa_error::create_mem_bio_failed,
  jwt::error::ecdsa_error::no_key_provided, jwt::error::ecdsa_error::invalid_key_size, jwt::error::ecdsa_error::invalid_key, jwt::error::ecdsa_error::create_context_failed
}
 Errors related to processing of RSA signatures. More...
 
enum  jwt::error::signature_verification_error {
  jwt::error::signature_verification_error::ok = 0, jwt::error::signature_verification_error::invalid_signature = 10, jwt::error::signature_verification_error::create_context_failed, jwt::error::signature_verification_error::verifyinit_failed,
  jwt::error::signature_verification_error::verifyupdate_failed, jwt::error::signature_verification_error::verifyfinal_failed, jwt::error::signature_verification_error::get_key_failed, jwt::error::signature_verification_error::set_rsa_pss_saltlen_failed,
  jwt::error::signature_verification_error::signature_encoding_failed
}
 Errors related to verification of signatures. More...
 
enum  jwt::error::signature_generation_error {
  jwt::error::signature_generation_error::ok = 0, jwt::error::signature_generation_error::hmac_failed = 10, jwt::error::signature_generation_error::create_context_failed, jwt::error::signature_generation_error::signinit_failed,
  jwt::error::signature_generation_error::signupdate_failed, jwt::error::signature_generation_error::signfinal_failed, jwt::error::signature_generation_error::ecdsa_do_sign_failed, jwt::error::signature_generation_error::digestinit_failed,
  jwt::error::signature_generation_error::digestupdate_failed, jwt::error::signature_generation_error::digestfinal_failed, jwt::error::signature_generation_error::rsa_padding_failed, jwt::error::signature_generation_error::rsa_private_encrypt_failed,
  jwt::error::signature_generation_error::get_key_failed, jwt::error::signature_generation_error::set_rsa_pss_saltlen_failed, jwt::error::signature_generation_error::signature_decoding_failed
}
 Errors related to signature generation errors. More...
 
enum  jwt::error::token_verification_error {
  jwt::error::token_verification_error::ok = 0, jwt::error::token_verification_error::wrong_algorithm = 10, jwt::error::token_verification_error::missing_claim, jwt::error::token_verification_error::claim_type_missmatch,
  jwt::error::token_verification_error::claim_value_missmatch, jwt::error::token_verification_error::token_expired, jwt::error::token_verification_error::audience_missmatch
}
 Errors related to token verification errors. More...
 
enum  jwt::json::type {
  jwt::json::type::boolean, jwt::json::type::integer, jwt::json::type::number, jwt::json::type::string,
  jwt::json::type::array, jwt::json::type::object
}
 Generic JSON types used in JWTs. More...
 

Functions

std::error_category & jwt::error::rsa_error_category ()
 Error category for RSA errors. More...
 
std::error_code jwt::error::make_error_code (rsa_error e)
 
std::error_category & jwt::error::ecdsa_error_category ()
 Error category for ECDSA errors. More...
 
std::error_code jwt::error::make_error_code (ecdsa_error e)
 
std::error_category & jwt::error::signature_verification_error_category ()
 Error category for verification errors. More...
 
std::error_code jwt::error::make_error_code (signature_verification_error e)
 
std::error_category & jwt::error::signature_generation_error_category ()
 Error category for signature generation errors. More...
 
std::error_code jwt::error::make_error_code (signature_generation_error e)
 
std::error_category & jwt::error::token_verification_error_category ()
 Error category for token verification errors. More...
 
std::error_code jwt::error::make_error_code (token_verification_error e)
 
void jwt::error::throw_if_error (std::error_code ec)
 
std::string jwt::helper::extract_pubkey_from_cert (const std::string &certstr, const std::string &pw, std::error_code &ec)
 Extract the public key of a pem certificate. More...
 
std::string jwt::helper::extract_pubkey_from_cert (const std::string &certstr, const std::string &pw="")
 Extract the public key of a pem certificate. More...
 
template<typename Decode >
std::string jwt::helper::convert_base64_der_to_pem (const std::string &cert_base64_der_str, Decode decode, std::error_code &ec)
 Convert the certificate provided as base64 DER to PEM. More...
 
template<typename Decode >
std::string jwt::helper::convert_base64_der_to_pem (const std::string &cert_base64_der_str, Decode decode)
 Convert the certificate provided as base64 DER to PEM. More...
 
std::string jwt::helper::convert_base64_der_to_pem (const std::string &cert_base64_der_str, std::error_code &ec)
 Convert the certificate provided as base64 DER to PEM. More...
 
std::string jwt::helper::convert_base64_der_to_pem (const std::string &cert_base64_der_str)
 Convert the certificate provided as base64 DER to PEM. More...
 
std::shared_ptr< EVP_PKEY > jwt::helper::load_public_key_from_string (const std::string &key, const std::string &password, std::error_code &ec)
 Load a public key from a string. More...
 
std::shared_ptr< EVP_PKEY > jwt::helper::load_public_key_from_string (const std::string &key, const std::string &password="")
 Load a public key from a string. More...
 
std::shared_ptr< EVP_PKEY > jwt::helper::load_private_key_from_string (const std::string &key, const std::string &password, std::error_code &ec)
 Load a private key from a string. More...
 
std::shared_ptr< EVP_PKEY > jwt::helper::load_private_key_from_string (const std::string &key, const std::string &password="")
 Load a private key from a string. More...
 
std::shared_ptr< EVP_PKEY > jwt::helper::load_public_ec_key_from_string (const std::string &key, const std::string &password, std::error_code &ec)
 Load a public key from a string. More...
 
std::shared_ptr< EVP_PKEY > jwt::helper::load_public_ec_key_from_string (const std::string &key, const std::string &password="")
 Load a public key from a string. More...
 
std::shared_ptr< EVP_PKEY > jwt::helper::load_private_ec_key_from_string (const std::string &key, const std::string &password, std::error_code &ec)
 Load a private key from a string. More...
 
std::shared_ptr< EVP_PKEY > jwt::helper::load_private_ec_key_from_string (const std::string &key, const std::string &password="")
 Load a private key from a string. More...
 
std::string jwt::helper::bn2raw (const BIGNUM *bn)
 
std::unique_ptr< BIGNUM, decltype(&BN_free)> jwt::helper::raw2bn (const std::string &raw)
 
template<typename Clock , typename json_traits >
verifier< Clock, json_traits > jwt::verify (Clock c)
 
template<typename json_traits >
verifier< default_clock, json_traits > jwt::verify (default_clock c={})
 
template<typename json_traits >
builder< json_traits > jwt::create ()
 
template<typename json_traits , typename Decode >
decoded_jwt< json_traits > jwt::decode (const typename json_traits::string_type &token, Decode decode)
 
template<typename json_traits >
decoded_jwt< json_traits > jwt::decode (const typename json_traits::string_type &token)
 
template<typename json_traits >
jwk< json_traits > jwt::parse_jwk (const typename json_traits::string_type &token)
 
template<typename json_traits >
jwks< json_traits > jwt::parse_jwks (const typename json_traits::string_type &token)
 
template<typename json_traits >
std::istream & operator>> (std::istream &is, jwt::basic_claim< json_traits > &c)
 
template<typename json_traits >
std::ostream & operator<< (std::ostream &os, const jwt::basic_claim< json_traits > &c)
 

Macro Definition Documentation

◆ JWT_CLAIM_EXPLICIT

#define JWT_CLAIM_EXPLICIT   explicit

Definition at line 64 of file jwt.h.

◆ PICOJSON_USE_INT64

#define PICOJSON_USE_INT64

Definition at line 6 of file jwt.h.

Function Documentation

◆ operator<<()

template<typename json_traits >
std::ostream& operator<< ( std::ostream &  os,
const jwt::basic_claim< json_traits > &  c 
)

Definition at line 4217 of file jwt.h.

◆ operator>>()

template<typename json_traits >
std::istream& operator>> ( std::istream &  is,
jwt::basic_claim< json_traits > &  c 
)

Definition at line 4211 of file jwt.h.