2 declare(strict_types=1);
3 namespace ParagonIE\ConstantTime;
6 * Copyright (c) 2016 Paragon Initiative Enterprises.
7 * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * @package ParagonIE\ConstantTime
32 abstract class Encoding
35 * RFC 4648 Base32 encoding
40 public static function base32Encode(string $str): string
42 return Base32::encode($str);
46 * RFC 4648 Base32 encoding
51 public static function base32EncodeUpper(string $str): string
53 return Base32::encodeUpper($str);
57 * RFC 4648 Base32 decoding
62 public static function base32Decode(string $str): string
64 return Base32::decode($str);
68 * RFC 4648 Base32 decoding
73 public static function base32DecodeUpper(string $str): string
75 return Base32::decodeUpper($str);
79 * RFC 4648 Base32 encoding
84 public static function base32HexEncode(string $str): string
86 return Base32Hex::encode($str);
91 * RFC 4648 Base32 encoding
96 public static function base32HexEncodeUpper(string $str): string
98 return Base32Hex::encodeUpper($str);
102 * RFC 4648 Base32 decoding
107 public static function base32HexDecode(string $str): string
109 return Base32Hex::decode($str);
113 * RFC 4648 Base32 decoding
118 public static function base32HexDecodeUpper(string $str): string
120 return Base32Hex::decodeUpper($str);
124 * RFC 4648 Base64 encoding
129 public static function base64Encode(string $str): string
131 return Base64::encode($str);
135 * RFC 4648 Base32 decoding
140 public static function base64Decode(string $str): string
142 return Base64::decode($str);
148 * Base64 character set "./[A-Z][a-z][0-9]"
152 public static function base64EncodeDotSlash(string $str): string
154 return Base64DotSlash::encode($str);
158 * Decode from base64 to raw binary
160 * Base64 character set "./[A-Z][a-z][0-9]"
163 * @return bool|string
164 * @throws \RangeException
166 public static function base64DecodeDotSlash(string $str): string
168 return Base64DotSlash::decode($str);
174 * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
178 public static function base64EncodeDotSlashOrdered(string $str): string
180 return Base64DotSlashOrdered::encode($str);
184 * Decode from base64 to raw binary
186 * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
189 * @return bool|string
190 * @throws \RangeException
192 public static function base64DecodeDotSlashOrdered(string $str): string
194 return Base64DotSlashOrdered::decode($str);
198 * Convert a binary string into a hexadecimal string without cache-timing
201 * @param string $bin_string (raw binary)
204 public static function hexEncode(string $bin_string): string
206 return Hex::encode($bin_string);
210 * Convert a hexadecimal string into a binary string without cache-timing
213 * @param string $hex_string
214 * @return string (raw binary)
215 * @throws \RangeException
217 public static function hexDecode(string $hex_string): string
219 return Hex::decode($hex_string);
223 * Convert a binary string into a hexadecimal string without cache-timing
226 * @param string $bin_string (raw binary)
229 public static function hexEncodeUpper(string $bin_string): string
231 return Hex::encodeUpper($bin_string);
235 * Convert a binary string into a hexadecimal string without cache-timing
238 * @param string $bin_string (raw binary)
241 public static function hexDecodeUpper(string $bin_string): string
243 return Hex::decode($bin_string);