|
13 | 13 | #include <vector> |
14 | 14 |
|
15 | 15 | #include "oxen/log/catlogger.hpp" |
| 16 | +#include "oxenc/base64.h" |
16 | 17 | #include "oxenc/hex.h" |
17 | 18 | #include "session/config/namespaces.hpp" |
18 | 19 | #include "session/config/profile_pic.hpp" |
@@ -43,6 +44,7 @@ void assertInfoMinLength(const Napi::CallbackInfo& info, const int minLength); |
43 | 44 |
|
44 | 45 | void assertIsStringOrNull(const Napi::Value& value, const std::string& identifier = ""); |
45 | 46 | void assertIsNumber(const Napi::Value& value, const std::string& identifier); |
| 47 | +void assertIsNumberOrNull(const Napi::Value& val, const std::string& identifier); |
46 | 48 | void assertIsBigint(const Napi::Value& val, const std::string& identifier); |
47 | 49 | void assertIsArray(const Napi::Value& value, const std::string& identifier); |
48 | 50 | void assertIsObject(const Napi::Value& value); |
@@ -80,10 +82,15 @@ int64_t toCppInteger(Napi::Value x, const std::string& identifier, bool allowUnd |
80 | 82 | int64_t toCppIntegerB(Napi::Value x, const std::string& identifier, bool allowUndefined = false); |
81 | 83 |
|
82 | 84 | std::optional<int64_t> maybeNonemptyInt(Napi::Value x, const std::string& identifier); |
| 85 | +std::optional<int64_t> maybeNonemptyIntB(Napi::Value x, const std::string& identifier); |
| 86 | + |
83 | 87 | std::optional<bool> maybeNonemptyBoolean(Napi::Value x, const std::string& identifier); |
84 | 88 | std::optional<std::chrono::sys_seconds> maybeNonemptySysSeconds( |
85 | 89 | Napi::Value x, const std::string& identifier); |
86 | 90 |
|
| 91 | +std::optional<std::chrono::sys_time<std::chrono::milliseconds>> maybeNonemptyTimeMs( |
| 92 | + Napi::Value x, const std::string& identifier); |
| 93 | + |
87 | 94 | std::chrono::sys_seconds toCppSysSeconds(Napi::Value x, const std::string& identifier); |
88 | 95 | std::chrono::sys_time<std::chrono::milliseconds> toCppSysMs( |
89 | 96 | Napi::Value x, const std::string& identifier); |
@@ -425,6 +432,21 @@ std::array<uint8_t, N> from_hex_to_array(std::string x) { |
425 | 432 | return result; |
426 | 433 | } |
427 | 434 |
|
| 435 | +template <std::size_t N> |
| 436 | +std::array<uint8_t, N> from_base64_to_array(std::string x) { |
| 437 | + std::string as_b64 = oxenc::from_base64(x); |
| 438 | + if (as_b64.size() != N) { |
| 439 | + throw std::invalid_argument(fmt::format( |
| 440 | + "from_base64_to_array: Decoded v64 size mismatch: expected {}, got {}", |
| 441 | + N, |
| 442 | + as_b64.size())); |
| 443 | + } |
| 444 | + |
| 445 | + std::array<uint8_t, N> result; |
| 446 | + std::memcpy(result.data(), as_b64.data(), N); |
| 447 | + return result; |
| 448 | +} |
| 449 | + |
428 | 450 | std::vector<unsigned char> from_hex_to_vector(std::string_view x); |
429 | 451 |
|
430 | 452 | std::span<const uint8_t> from_base64_to_span(std::string_view x); |
|
0 commit comments