1#ifndef SOURCEMETA_CORE_JOSE_JWK_H_
2#define SOURCEMETA_CORE_JOSE_JWK_H_
4#ifndef SOURCEMETA_CORE_JOSE_EXPORT
5#include <sourcemeta/core/jose_export.h>
9#include <sourcemeta/core/jose_algorithm.h>
10#include <sourcemeta/core/jose_error.h>
13#include <sourcemeta/core/crypto.h>
14#include <sourcemeta/core/json.h>
21namespace sourcemeta::core {
40class SOURCEMETA_CORE_JOSE_EXPORT
JWK {
43 enum class Type : std::uint8_t {
62 auto operator=(
JWK &&other)
noexcept ->
JWK & =
default;
64 auto operator=(
const JWK &) ->
JWK & =
delete;
68 [[nodiscard]]
static auto from(
const JSON &value) -> std::optional<JWK>;
72 [[nodiscard]]
static auto from(
JSON &&value) -> std::optional<JWK>;
90 [[nodiscard]]
auto type() const noexcept ->
Type {
return this->type_; }
93 [[nodiscard]]
auto key_id() const noexcept
94 -> std::optional<std::string_view> {
95 if (this->key_id_.has_value()) {
96 return std::string_view{*this->key_id_};
104 return this->algorithm_;
111 [[nodiscard]]
auto curve() const noexcept -> std::string_view {
121 return this->public_key_.has_value() ? &*this->public_key_ :
nullptr;
128 [[nodiscard]]
auto secret() const noexcept -> std::string_view {
129 return this->secret_;
138 [[nodiscard]] auto
thumbprint() const -> std::optional<std::
string>;
142 static auto parse(const
JSON &value,
JWK &result) ->
bool;
145#pragma warning(disable : 4251)
148 std::optional<std::string> key_id_;
149 std::optional<JWSAlgorithm> algorithm_;
151 std::optional<PublicKey> public_key_;
153 std::string modulus_;
154 std::string exponent_;
155 std::string coordinate_x_;
156 std::string coordinate_y_;
157 std::string public_point_;
159#pragma warning(default : 4251)
EllipticCurve
Definition crypto_verify.h:28
Type
The family of key material a key holds.
Definition jose_jwk.h:43
@ RSA
The RSA key type.
Definition jose_jwk.h:45
auto public_jwk() const -> std::optional< JSON >
JWK(JSON &&value)
Parse a JSON Web Key from a JSON value, throwing on invalid input.
static auto from_octets(const std::string_view secret) -> JWK
static auto from(JSON &&value) -> std::optional< JWK >
auto key_id() const noexcept -> std::optional< std::string_view >
The key identifier used to select this key, if present.
Definition jose_jwk.h:93
auto secret() const noexcept -> std::string_view
The raw symmetric secret, empty for asymmetric keys.
Definition jose_jwk.h:128
auto type() const noexcept -> Type
The family of key material this key holds.
Definition jose_jwk.h:90
static auto from(const JSON &value) -> std::optional< JWK >
auto thumbprint() const -> std::optional< std::string >
auto algorithm() const noexcept -> std::optional< JWSAlgorithm >
The algorithm this key is intended for, if present.
Definition jose_jwk.h:103
JWK(JWK &&other) noexcept=default
A key exclusively owns its parsed public key, so it is move-only.
auto public_key() const noexcept -> const PublicKey *
Definition jose_jwk.h:120
JWK(const JSON &value)
Parse a JSON Web Key from a JSON value, throwing on invalid input.
auto curve() const noexcept -> std::string_view
The curve this key is pinned to, empty when it carries none.
Definition jose_jwk.h:111
JWSAlgorithm
Definition jose_algorithm.h:21