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
//! Encoding functionality.
//!
//! This module provides functions to encode data to Base64.
//!
//! There are also [`try_length`] and [`length`] functions to calculate the
//! length of the encoded data.
//!
//! # Examples
//!
//! ```
//! use pkce_std::encoding::{encode, length};
//!
//! let data = "Hello, world!";
//!
//! let encoded = encode(data);
//!
//! assert_eq!(encoded.len(), length(data.len()));
//! ```
use ;
/// Encodes given data into Base64.
///
/// This function uses the URL-safe and no-padding variant of Base64.
///
/// # Examples
///
/// ```
/// use pkce_std::encoding::encode;
///
/// let data = "Hello, world!";
///
/// assert_eq!(encode(data), "SGVsbG8sIHdvcmxkIQ");
/// ```
/// Computes the length of the Base64 encoded data from the given length.
///
/// # Examples
///
/// ```
/// use pkce_std::encoding::try_length;
///
/// assert_eq!(try_length(32), Some(43));
///
/// assert_eq!(try_length(usize::MAX), None);
/// ```
pub const
/// The `overflow` literal.
pub const OVERFLOW: &str = "overflow";
/// Calls [`try_length`] and panics if the result is [`None`].
///
/// The only reason for this function to panic is an overflow.
///
/// # Panics
///
/// This function panics if the result of [`try_length`] is [`None`].
///
/// # Examples
///
/// Regular usage:
///
/// ```
/// use pkce_std::encoding::length;
///
/// assert_eq!(length(96), 128);
/// ```
///
/// Overflow:
///
/// ```should_panic
/// use pkce_std::encoding::length;
///
/// length(usize::MAX);
/// ```
pub const