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
// Copyright 2020-2025 Velithris
// SPDX-License-Identifier: MIT
// No guarantees about following semver there.
// Both modules are public for benchmarks and fuzzing.
use crate;
/// Decode base64-encoded `input` into the provided slice without validating its length.
///
/// On success `Result::Ok` containing the amount of bytes written is returned.
/// Otherwise, `Result::Err` containing the offset of the first invalid input byte is returned.
///
/// # Safety
///
/// * `output`'s length must be AT LEAST `input.len() * 3 / 4`
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::decode;
///
/// let input = b"ivgBS9glGC3BYXgzHa";
/// let required_capacity = decode::calculate_decoded_len(input).unwrap();
/// let mut output = Vec::with_capacity(required_capacity);
///
/// // SAFETY:
/// // - buffer's capacity is enough for storing decoded base64-input;
/// // - decode_into_unchecked returns the amount of bytes written,
/// // thus it is safe to call set_len using its return value.
/// unsafe {
/// let bytes_written =
/// decode::decode_into_unchecked(input, output.spare_capacity_mut()).unwrap();
/// output.set_len(bytes_written);
/// }
///
/// assert_eq!(output, b"Hello, world!");
/// ```
pub use decode_into_unchecked;
use MaybeUninit;
use Vec;
/// Calculate the amount of bytes required to store base64-encoded `input`
/// after decoding it.
///
/// `None` indicates an invalid length of the `input`.
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::decode;
///
/// assert_eq!(
/// decode::calculate_decoded_len(b"ivgBS9glGC3BYXgzHa").unwrap(),
/// 13
/// );
/// ```
/// Decode base64-encoded `input` into a new `Vec<u8>`.
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::{decode::decode_to_vec, error::DecodeError};
///
/// fn main() -> Result<(), DecodeError> {
/// assert_eq!(decode_to_vec(b"ivgBS9glGC3BYXgzHa")?, b"Hello, world!");
/// Ok(())
/// }
/// ```
/// Decode base64-encoded `input` into the provided slice.
///
/// Returns the amount of bytes written.
///
/// # Example
///
/// ```
/// use weakauras_codec_base64::{decode, error::DecodeIntoSliceError};
///
/// fn main() -> Result<(), DecodeIntoSliceError> {
/// let input = b"ivgBS9glGC3BYXgzHa";
/// let required_capacity = decode::calculate_decoded_len(input).unwrap();
/// let mut output = Vec::with_capacity(required_capacity);
///
/// let bytes_written = decode::decode_into(input, output.spare_capacity_mut())?;
/// unsafe {
/// output.set_len(bytes_written);
/// }
/// assert_eq!(output, b"Hello, world!");
/// Ok(())
/// }
/// ```
pub