1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright 2020-2025 Velithris
// SPDX-License-Identifier: MIT
// No guarantees about following semver there.
// Both modules are public for benchmarks and fuzzing.
use crate;
/// Encode `input` as base64 into the provided slice without validating its length.
///
/// Returns the amount of bytes written. Written bytes are guaranteed to be ASCII.
///
/// # Safety
///
/// * `output`'s length must be AT LEAST `(input.len() * 4 + 2) / 3`.
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::encode;
///
/// let input = b"Hello, world!";
/// let required_capacity = encode::calculate_encoded_len(input).unwrap();
/// let mut output = Vec::with_capacity(required_capacity);
///
/// // SAFETY:
/// // - buffer's capacity is enough for storing base64-encoded input;
/// // - encode_into_unchecked returns the amount of bytes written,
/// // thus it is safe to call set_len using its return value.
/// unsafe {
/// let bytes_written = encode::encode_into_unchecked(input, output.spare_capacity_mut());
/// output.set_len(bytes_written);
/// }
///
/// assert_eq!(output, b"ivgBS9glGC3BYXgzHa");
/// ```
pub use encode_into_unchecked;
use MaybeUninit;
use ;
/// Calculate the amount of bytes required to store `input`
/// after encoding it as base64.
///
/// `None` indicates an overflow.
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::encode;
///
/// assert_eq!(encode::calculate_encoded_len(b"Hello, world!").unwrap(), 18);
/// ```
/// Encode `input` as base64 into a new `String` with the supplied prefix.
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::{encode::encode_to_string_with_prefix, error::EncodeError};
///
/// fn main() -> Result<(), EncodeError> {
/// assert_eq!(
/// encode_to_string_with_prefix(b"Hello, world!", "!WA:2!")?,
/// "!WA:2!ivgBS9glGC3BYXgzHa"
/// );
/// Ok(())
/// }
/// ```
/// Encode `input` as base64 into a new `String`.
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::{encode::encode_to_string, error::EncodeError};
///
/// fn main() -> Result<(), EncodeError> {
/// assert_eq!(encode_to_string(b"Hello, world!")?, "ivgBS9glGC3BYXgzHa");
/// Ok(())
/// }
/// ```
/// Encode `input` as base64 into the provided slice.
///
/// Returns the amount of bytes written. Written bytes are guaranteed to be ASCII.
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::{encode, error::EncodeIntoSliceError};
///
/// fn main() -> Result<(), EncodeIntoSliceError> {
/// let input = b"Hello, world!";
/// let required_capacity = encode::calculate_encoded_len(input).unwrap();
/// let mut output = Vec::with_capacity(required_capacity);
///
/// let bytes_written = encode::encode_into(input, output.spare_capacity_mut())?;
/// unsafe {
/// output.set_len(bytes_written);
/// }
/// assert_eq!(output, b"ivgBS9glGC3BYXgzHa");
/// Ok(())
/// }
/// ```
pub