Struct jwt_header
Defined in File jwt.hpp
Inheritance Relationships
Base Types
public jwt::write_interface
(Struct write_interface)public jwt::base64_enc_dec< jwt_header >
(Template Struct base64_enc_dec)
Struct Documentation
-
struct jwt_header : public jwt::write_interface, public jwt::base64_enc_dec<jwt_header>
Component class representing JWT Header.
Public Functions
-
inline jwt_header()
- inline jwt_header (SCOPED_ENUM algorithm alg, SCOPED_ENUM type typ=type::JWT)
Constructor taking specified algorithm type and JWT type.
-
inline jwt_header(const jwt::string_view enc_str)
Construct the header from an encoded string.
-
jwt_header(const jwt_header&) = default
Default Copy and assignment.
-
jwt_header &operator=(const jwt_header&) = default
-
~jwt_header() = default
- inline void algo (SCOPED_ENUM algorithm alg)
NOTE: Any previously saved json dump or the encoding of the header would not be valid after modifying the algorithm. Set the algorithm.
-
inline void algo(const jwt::string_view sv)
Set the algorithm. String overload.
- inline SCOPED_ENUM algorithm algo () const noexcept
Get the algorithm.
- inline void typ (SCOPED_ENUM type typ) noexcept
NOTE: Any previously saved json dump or the encoding of the header would not be valid after modifying the type. Set the JWT type.
-
inline void typ(const jwt::string_view sv)
Set the JWT type header. String overload.
- inline SCOPED_ENUM type typ () const noexcept
Get the JWT type.
-
template<typename T, typename = std::enable_if_t<!std::is_same<jwt::string_view, std::decay_t<T>>::value>>
inline bool add_header(const jwt::string_view hname, T &&hvalue, bool overwrite = false) Add a header to the JWT header.
-
inline bool add_header(const jwt::string_view cname, const jwt::string_view cvalue, bool overwrite = false)
Add a header to the JWT header. Overload which takes the header value as
jwt::string_view
-
inline bool remove_header(const jwt::string_view hname)
Remove the header from JWT. NOTE: Special handling for removing type field from header. The typ_ is set to NONE when removed.
-
inline bool has_header(const jwt::string_view hname)
Checks if header with the given name is present or not.
-
inline std::string encode(bool pprint = false)
Get the URL safe base64 encoded string of the header.
-
inline void decode(const jwt::string_view enc_str, std::error_code &ec)
Decodes the base64 encoded string to JWT header.
This API takes an error_code to set the error instead of throwing an exception.
Note
: Overwrites the data member of this instance with the decoded values.
Note
: Exceptions related to memory allocation failures are not translated to an error_code. The API would still throw an exception in those cases.
-
inline void decode(const jwt::string_view enc_str)
Exception throwing API version of decode. Throws
DecodeError
exception. Could also throw memory allocation failure exceptions.
-
inline const json_t &create_json_obj() const
Creates a
json_t
object this class instance.Note
: Presence of this member function is a requirement for some interfaces (Eg:
write_interface
).
-
inline jwt_header()