AXIAM C++ SDK 1.0.0-alpha8
Authentication, authorization, JWKS & route guards (REST + mTLS)
Loading...
Searching...
No Matches
sensitive.hpp
Go to the documentation of this file.
1// §7 Sensitive<T> — token / key material wrapper that never reveals its value
2// through any public display, logging, or serialization path.
3#pragma once
4
5#include <ostream>
6#include <string>
7#include <utility>
8
9namespace axiam {
10
11template <typename T>
12class Sensitive; // primary template, defined below
13
14namespace detail {
15// Module-private reveal. Not part of the public API surface — SDK internals that
16// genuinely need the raw value call this; application code cannot reach it without
17// naming the axiam::detail namespace, and it is documented as internal-only.
18template <typename T>
19const T& reveal(const Sensitive<T>& s) noexcept;
20} // namespace detail
21
25template <typename T>
26class Sensitive {
27public:
28 Sensitive() = default;
29 explicit Sensitive(T value) : value_(std::move(value)) {}
30
31 Sensitive(const Sensitive&) = default;
32 Sensitive(Sensitive&&) noexcept = default;
33 Sensitive& operator=(const Sensitive&) = default;
34 Sensitive& operator=(Sensitive&&) noexcept = default;
35
37 std::string to_string() const { return "[SENSITIVE]"; }
38
40 bool empty() const { return is_empty(value_); }
41
42private:
43 static bool is_empty(const std::string& v) { return v.empty(); }
44 template <typename U>
45 static bool is_empty(const U&) { return false; }
46
47 T value_{};
48
49 friend const T& detail::reveal<T>(const Sensitive<T>& s) noexcept;
50};
51
52template <typename T>
53std::ostream& operator<<(std::ostream& os, const Sensitive<T>& s) {
54 return os << s.to_string();
55}
56
57namespace detail {
58template <typename T>
59const T& reveal(const Sensitive<T>& s) noexcept {
60 return s.value_;
61}
62} // namespace detail
63
64} // namespace axiam
Wraps secret material (access tokens, mTLS private keys).
Definition sensitive.hpp:26
std::string to_string() const
Redacted textual form. Never emits the wrapped value.
Definition sensitive.hpp:37
Sensitive()=default
Sensitive(const Sensitive &)=default
bool empty() const
True when no secret is held (default-constructed / empty string).
Definition sensitive.hpp:40
Sensitive(T value)
Definition sensitive.hpp:29
Sensitive(Sensitive &&) noexcept=default
friend const T & detail::reveal(const Sensitive< T > &s) noexcept
const T & reveal(const Sensitive< T > &s) noexcept
Definition sensitive.hpp:59
Definition authenticator.hpp:40
std::ostream & operator<<(std::ostream &os, const Sensitive< T > &s)
Definition sensitive.hpp:53