PluginProbe
Authorizer / 3.13.0
Authorizer v3.13.0
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
authorizer / vendor / paragonie / constant_time_encoding / src / Encoding.php

Encoding.php in Authorizer 3.13.0, at vendor/paragonie/constant_time_encoding/src/Encoding.php

300 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3 namespace ParagonIE\ConstantTime;
4
5 use SensitiveParameter;
6 use TypeError;
7
8 /**
9 * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
10 * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this software and associated documentation files (the "Software"), to deal
14 * in the Software without restriction, including without limitation the rights
15 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 * copies of the Software, and to permit persons to whom the Software is
17 * furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in all
20 * copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
29 */
30
31 /**
32 * Class Encoding
33 * @package ParagonIE\ConstantTime
34 */
35 abstract class Encoding
36 {
37 /**
38 * RFC 4648 Base32 encoding
39 *
40 * @param string $str
41 * @return string
42 * @throws TypeError
43 */
44 public static function base32Encode(
45 #[SensitiveParameter]
46 string $str
47 ): string {
48 return Base32::encode($str);
49 }
50
51 /**
52 * RFC 4648 Base32 encoding
53 *
54 * @param string $str
55 * @return string
56 * @throws TypeError
57 */
58 public static function base32EncodeUpper(
59 #[SensitiveParameter]
60 string $str
61 ): string {
62 return Base32::encodeUpper($str);
63 }
64
65 /**
66 * RFC 4648 Base32 decoding
67 *
68 * @param string $str
69 * @return string
70 * @throws TypeError
71 */
72 public static function base32Decode(
73 #[SensitiveParameter]
74 string $str
75 ): string {
76 return Base32::decode($str);
77 }
78
79 /**
80 * RFC 4648 Base32 decoding
81 *
82 * @param string $str
83 * @return string
84 * @throws TypeError
85 */
86 public static function base32DecodeUpper(
87 #[SensitiveParameter]
88 string $str
89 ): string {
90 return Base32::decodeUpper($str);
91 }
92
93 /**
94 * RFC 4648 Base32 encoding
95 *
96 * @param string $str
97 * @return string
98 * @throws TypeError
99 */
100 public static function base32HexEncode(
101 #[SensitiveParameter]
102 string $str
103 ): string {
104 return Base32Hex::encode($str);
105 }
106
107 /**
108 * RFC 4648 Base32Hex encoding
109 *
110 * @param string $str
111 * @return string
112 * @throws TypeError
113 */
114 public static function base32HexEncodeUpper(
115 #[SensitiveParameter]
116 string $str
117 ): string {
118 return Base32Hex::encodeUpper($str);
119 }
120
121 /**
122 * RFC 4648 Base32Hex decoding
123 *
124 * @param string $str
125 * @return string
126 * @throws TypeError
127 */
128 public static function base32HexDecode(
129 #[SensitiveParameter]
130 string $str
131 ): string {
132 return Base32Hex::decode($str);
133 }
134
135 /**
136 * RFC 4648 Base32Hex decoding
137 *
138 * @param string $str
139 * @return string
140 * @throws TypeError
141 */
142 public static function base32HexDecodeUpper(
143 #[SensitiveParameter]
144 string $str
145 ): string {
146 return Base32Hex::decodeUpper($str);
147 }
148
149 /**
150 * RFC 4648 Base64 encoding
151 *
152 * @param string $str
153 * @return string
154 * @throws TypeError
155 */
156 public static function base64Encode(
157 #[SensitiveParameter]
158 string $str
159 ): string {
160 return Base64::encode($str);
161 }
162
163 /**
164 * RFC 4648 Base64 decoding
165 *
166 * @param string $str
167 * @return string
168 * @throws TypeError
169 */
170 public static function base64Decode(
171 #[SensitiveParameter]
172 string $str
173 ): string {
174 return Base64::decode($str);
175 }
176
177 /**
178 * Encode into Base64
179 *
180 * Base64 character set "./[A-Z][a-z][0-9]"
181 * @param string $str
182 * @return string
183 * @throws TypeError
184 */
185 public static function base64EncodeDotSlash(
186 #[SensitiveParameter]
187 string $str
188 ): string {
189 return Base64DotSlash::encode($str);
190 }
191
192 /**
193 * Decode from base64 to raw binary
194 *
195 * Base64 character set "./[A-Z][a-z][0-9]"
196 *
197 * @param string $str
198 * @return string
199 * @throws \RangeException
200 * @throws TypeError
201 */
202 public static function base64DecodeDotSlash(
203 #[SensitiveParameter]
204 string $str
205 ): string {
206 return Base64DotSlash::decode($str);
207 }
208
209 /**
210 * Encode into Base64
211 *
212 * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
213 * @param string $str
214 * @return string
215 * @throws TypeError
216 */
217 public static function base64EncodeDotSlashOrdered(
218 #[SensitiveParameter]
219 string $str
220 ): string {
221 return Base64DotSlashOrdered::encode($str);
222 }
223
224 /**
225 * Decode from base64 to raw binary
226 *
227 * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
228 *
229 * @param string $str
230 * @return string
231 * @throws \RangeException
232 * @throws TypeError
233 */
234 public static function base64DecodeDotSlashOrdered(
235 #[SensitiveParameter]
236 string $str
237 ): string {
238 return Base64DotSlashOrdered::decode($str);
239 }
240
241 /**
242 * Convert a binary string into a hexadecimal string without cache-timing
243 * leaks
244 *
245 * @param string $bin_string (raw binary)
246 * @return string
247 * @throws TypeError
248 */
249 public static function hexEncode(
250 #[SensitiveParameter]
251 string $bin_string
252 ): string {
253 return Hex::encode($bin_string);
254 }
255
256 /**
257 * Convert a hexadecimal string into a binary string without cache-timing
258 * leaks
259 *
260 * @param string $hex_string
261 * @return string (raw binary)
262 * @throws \RangeException
263 */
264 public static function hexDecode(
265 #[SensitiveParameter]
266 string $hex_string
267 ): string {
268 return Hex::decode($hex_string);
269 }
270
271 /**
272 * Convert a binary string into a hexadecimal string without cache-timing
273 * leaks
274 *
275 * @param string $bin_string (raw binary)
276 * @return string
277 * @throws TypeError
278 */
279 public static function hexEncodeUpper(
280 #[SensitiveParameter]
281 string $bin_string
282 ): string {
283 return Hex::encodeUpper($bin_string);
284 }
285
286 /**
287 * Convert a binary string into a hexadecimal string without cache-timing
288 * leaks
289 *
290 * @param string $bin_string (raw binary)
291 * @return string
292 */
293 public static function hexDecodeUpper(
294 #[SensitiveParameter]
295 string $bin_string
296 ): string {
297 return Hex::decode($bin_string);
298 }
299 }
300