Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
base-nix-32.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include <array>
5
#include <cstdint>
6
#include <optional>
7
#include <string>
8
#include <span>
9
10
#include "
nix/util/array-from-string-literal.hh
"
11
12
namespace
nix {
13
14
struct
BaseNix32
15
{
17
constexpr
static
std::array<char, 32>
characters
=
"0123456789abcdfghijklmnpqrsvwxyz"
_arrayNoNull;
18
19
private
:
20
static
const
std::array<uint8_t, 256> reverseMap;
21
22
static
constexpr
const
uint8_t invalid = 0xFF;
23
24
public
:
25
static
inline
std::optional<uint8_t> lookupReverse(
char
base32)
26
{
27
uint8_t digit = reverseMap[
static_cast<
unsigned
char
>
(base32)];
28
if
(digit == invalid)
29
return
std::nullopt;
30
else
31
return
digit;
32
}
33
37
[[nodiscard]]
constexpr
static
inline
size_t
encodedLength
(
size_t
originalLength)
38
{
39
return
(originalLength * 8 - 1) / 5 + 1;
40
}
41
42
static
std::string encode(std::span<const std::byte> originalData);
43
44
static
std::string decode(std::string_view s);
45
};
46
47
}
// namespace nix
array-from-string-literal.hh
nix::BaseNix32
Definition
base-nix-32.hh:15
nix::BaseNix32::encodedLength
static constexpr size_t encodedLength(size_t originalLength)
Definition
base-nix-32.hh:37
nix::BaseNix32::characters
static constexpr std::array< char, 32 > characters
omitted: E O U T
Definition
base-nix-32.hh:17
libutil
include
nix
util
base-nix-32.hh
Generated by
1.18.0