Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Hex.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Cryptography_Encoding_Algorithm_Hex_h_
5#define _Stroika_Foundation_Cryptography_Encoding_Algorithm_Hex_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <span>
10#include <string>
11#include <string_view>
12
15
16/**
17 * \file
18 *
19 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
20 */
21
22/**
23 * Hex - base16 (RFC 4648, section 8): bytes as text, two hexadecimal digits a byte, and back.
24 *
25 * Like Base64, VERY WEAK encryption (Cryptography's ReadMe.md): the bytes made opaque - to a parser, and to most readers -
26 * and kept intact through a channel that would mangle them; but secret from no one who recognizes it.
27 *
28 * Memory::BLOB's AsHex and FromHex, and Cryptography::Format, use it.
29 */
31
32 /**
33 * \brief The bytes as hex: two digits a byte, lower case - {0x29, 0x14} as "2914"
34 *
35 * \par Example Usage
36 * \code
37 * EXPECT_EQ (Hex::Encode (BLOB{0x29, 0x14, 0x4a}), "29144a");
38 * \endcode
39 */
40 string Encode (span<const byte> from);
41 string Encode (const Memory::BLOB& from); ///< \brief The bytes as hex: two digits a byte, lower case
42
43 /**
44 * \brief Hex read back into bytes: digits of either case; spaces before a byte's two digits skipped (so "29 14 4a" too).
45 * Throws DataExchange::BadFormatException on a character not a hex digit, or a byte's second digit missing.
46 *
47 * \par Example Usage
48 * \code
49 * EXPECT_EQ (Hex::Decode ("29144A"sv), (BLOB{0x29, 0x14, 0x4a}));
50 * \endcode
51 */
52 Memory::BLOB Decode (span<const char> s);
53 Memory::BLOB Decode (const char* s); ///< \brief Hex read back into bytes
54 Memory::BLOB Decode (string_view s); ///< \brief Hex read back into bytes
55 Memory::BLOB Decode (const string& s); ///< \brief Hex read back into bytes
56 Memory::BLOB Decode (const Characters::String& s); ///< \brief Hex read back into bytes
57
58}
59
60#endif /*_Stroika_Foundation_Cryptography_Encoding_Algorithm_Hex_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
string Encode(span< const byte > from)
The bytes as hex: two digits a byte, lower case - {0x29, 0x14} as "2914".
Definition Hex.cpp:24
Memory::BLOB Decode(span< const char > s)
Hex read back into bytes: digits of either case; spaces before a byte's two digits skipped (so "29 14...
Definition Hex.cpp:41