Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
jose_jwe.h
1#ifndef SOURCEMETA_CORE_JOSE_JWE_H_
2#define SOURCEMETA_CORE_JOSE_JWE_H_
3
4#ifndef SOURCEMETA_CORE_JOSE_EXPORT
5#include <sourcemeta/core/jose_export.h>
6#endif
7
8// NOLINTBEGIN(misc-include-cleaner)
9#include <sourcemeta/core/jose_algorithm.h>
10#include <sourcemeta/core/jose_error.h>
11// NOLINTEND(misc-include-cleaner)
12
13#include <sourcemeta/core/json.h>
14
15#include <optional> // std::optional
16#include <string> // std::string
17#include <string_view> // std::string_view
18
19namespace sourcemeta::core {
20
34class SOURCEMETA_CORE_JOSE_EXPORT JWE {
35public:
38 explicit JWE(const std::string_view input);
39
42 [[nodiscard]] static auto from(const std::string_view input)
43 -> std::optional<JWE>;
44
45 // Protected header (RFC 7516 Section 4)
46
49 [[nodiscard]] auto algorithm() const noexcept -> std::optional<JWEAlgorithm> {
50 return this->algorithm_;
51 }
52
55 [[nodiscard]] auto encryption() const noexcept
56 -> std::optional<JWEEncryption> {
57 return this->encryption_;
58 }
59
61 [[nodiscard]] auto key_id() const noexcept -> std::optional<std::string_view>;
62
64 [[nodiscard]] auto header() const noexcept -> const JSON & {
65 return this->header_;
66 }
67
68 // Wire segments (RFC 7516 Section 7.1), consumed by jwe_decrypt
69
72 [[nodiscard]] auto protected_header() const noexcept -> std::string_view {
73 return this->protected_header_;
74 }
75
78 [[nodiscard]] auto encrypted_key() const noexcept -> std::string_view {
79 return this->encrypted_key_;
80 }
81
83 [[nodiscard]] auto initialization_vector() const noexcept
84 -> std::string_view {
85 return this->initialization_vector_;
86 }
87
89 [[nodiscard]] auto ciphertext() const noexcept -> std::string_view {
90 return this->ciphertext_;
91 }
92
94 [[nodiscard]] auto tag() const noexcept -> std::string_view {
95 return this->tag_;
96 }
97
98private:
99 JWE() = default;
100 static auto parse(const std::string_view input, JWE &result) -> bool;
101
102#if defined(_MSC_VER)
103#pragma warning(disable : 4251)
104#endif
105 std::string protected_header_;
106 std::string encrypted_key_;
107 std::string initialization_vector_;
108 std::string ciphertext_;
109 std::string tag_;
110 JSON header_{nullptr};
111 std::optional<JWEAlgorithm> algorithm_;
112 std::optional<JWEEncryption> encryption_;
113#if defined(_MSC_VER)
114#pragma warning(default : 4251)
115#endif
116};
117
118} // namespace sourcemeta::core
119
120#endif
auto encrypted_key() const noexcept -> std::string_view
Definition jose_jwe.h:78
auto header() const noexcept -> const JSON &
The decoded protected header.
Definition jose_jwe.h:64
auto initialization_vector() const noexcept -> std::string_view
The decoded JWE Initialization Vector.
Definition jose_jwe.h:83
auto tag() const noexcept -> std::string_view
The decoded JWE Authentication Tag.
Definition jose_jwe.h:94
auto encryption() const noexcept -> std::optional< JWEEncryption >
Definition jose_jwe.h:55
auto ciphertext() const noexcept -> std::string_view
The decoded JWE Ciphertext.
Definition jose_jwe.h:89
auto key_id() const noexcept -> std::optional< std::string_view >
The key identifier from the protected header, if present.
static auto from(const std::string_view input) -> std::optional< JWE >
JWE(const std::string_view input)
auto protected_header() const noexcept -> std::string_view
Definition jose_jwe.h:72
auto algorithm() const noexcept -> std::optional< JWEAlgorithm >
Definition jose_jwe.h:49
Definition jose_jwe.h:34
JWEAlgorithm
Definition jose_algorithm.h:125
JWEEncryption
Definition jose_algorithm.h:152
Definition json_value.h:39