JWTXX
C++ library for JWT
Loading...
Searching...
No Matches
JWTXX::Key Class Reference

Represents signature algorithm Signs tokens and verifies token signatures. More...

#include <jwt.h>

Classes

class  Error
 Key-specific exception. More...
 

Public Types

using PasswordCallback = std::function<std::string ()>
 Callback function for password-protected keys. Should return password in plain text.
 

Public Member Functions

 Key (Algorithm alg, const std::string &keyData, const PasswordCallback &cb=noPasswordCallback)
 Constructs key using the specified algorithm and data.
 
 ~Key ()
 Destructor.
 
 Key (Key &&) noexcept
 Move constructor.
 
Keyoperator= (Key &&) noexcept
 Move assignment.
 
Algorithm alg () const noexcept
 Returns algorithm code used by the key.
 
std::string sign (const void *data, size_t size) const
 Signs a chunk of memory.
 
bool verify (const void *data, size_t size, const std::string &signature) const
 Verifies a signature of a chunk of memory.
 

Static Public Member Functions

static std::string noPasswordCallback ()
 Always throws exception, reports about missing callback.
 

Detailed Description

Represents signature algorithm Signs tokens and verifies token signatures.

Constructor & Destructor Documentation

◆ Key()

JWTXX::Key::Key ( Algorithm alg,
const std::string & keyData,
const PasswordCallback & cb = noPasswordCallback )

Constructs key using the specified algorithm and data.

Parameters
algsignature algorithm;
keyDataa shared secret, a path to a key file or PEM data for public keys;
cbpassword callabck for password-protected keys.

Member Function Documentation

◆ noPasswordCallback()

static std::string JWTXX::Key::noPasswordCallback ( )
static

Always throws exception, reports about missing callback.

Returns
doesn't return.
Exceptions
Error

◆ sign()

std::string JWTXX::Key::sign ( const void * data,
size_t size ) const

Signs a chunk of memory.

Parameters
dataa pointer to data for signing;
sizea size of data for signing.

◆ verify()

bool JWTXX::Key::verify ( const void * data,
size_t size,
const std::string & signature ) const

Verifies a signature of a chunk of memory.

Parameters
dataa pointer to signed data;
sizea size of signed data;
signaturea signature to verify.
Exceptions
Error

The documentation for this class was generated from the following file: