]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/ParagonIE/ConstantTime/Encoding.php
extlib required by phpseclib (ParagonIE/ConstantTime)
[quix0rs-gnu-social.git] / extlib / ParagonIE / ConstantTime / Encoding.php
1 <?php
2 declare(strict_types=1);
3 namespace ParagonIE\ConstantTime;
4
5 /**
6  *  Copyright (c) 2016 Paragon Initiative Enterprises.
7  *  Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
8  *
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:
15  *
16  *  The above copyright notice and this permission notice shall be included in all
17  *  copies or substantial portions of the Software.
18  *
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
25  *  SOFTWARE.
26  */
27
28 /**
29  * Class Encoding
30  * @package ParagonIE\ConstantTime
31  */
32 abstract class Encoding
33 {
34     /**
35      * RFC 4648 Base32 encoding
36      *
37      * @param $str
38      * @return string
39      */
40     public static function base32Encode(string $str): string
41     {
42         return Base32::encode($str);
43     }
44
45     /**
46      * RFC 4648 Base32 encoding
47      *
48      * @param $str
49      * @return string
50      */
51     public static function base32EncodeUpper(string $str): string
52     {
53         return Base32::encodeUpper($str);
54     }
55
56     /**
57      * RFC 4648 Base32 decoding
58      *
59      * @param $str
60      * @return string
61      */
62     public static function base32Decode(string $str): string
63     {
64         return Base32::decode($str);
65     }
66
67     /**
68      * RFC 4648 Base32 decoding
69      *
70      * @param $str
71      * @return string
72      */
73     public static function base32DecodeUpper(string $str): string
74     {
75         return Base32::decodeUpper($str);
76     }
77
78     /**
79      * RFC 4648 Base32 encoding
80      *
81      * @param $str
82      * @return string
83      */
84     public static function base32HexEncode(string $str): string
85     {
86         return Base32Hex::encode($str);
87     }
88
89
90     /**
91      * RFC 4648 Base32 encoding
92      *
93      * @param $str
94      * @return string
95      */
96     public static function base32HexEncodeUpper(string $str): string
97     {
98         return Base32Hex::encodeUpper($str);
99     }
100
101     /**
102      * RFC 4648 Base32 decoding
103      *
104      * @param $str
105      * @return string
106      */
107     public static function base32HexDecode(string $str): string
108     {
109         return Base32Hex::decode($str);
110     }
111
112     /**
113      * RFC 4648 Base32 decoding
114      *
115      * @param $str
116      * @return string
117      */
118     public static function base32HexDecodeUpper(string $str): string
119     {
120         return Base32Hex::decodeUpper($str);
121     }
122
123     /**
124      * RFC 4648 Base64 encoding
125      *
126      * @param $str
127      * @return string
128      */
129     public static function base64Encode(string $str): string
130     {
131         return Base64::encode($str);
132     }
133
134     /**
135      * RFC 4648 Base32 decoding
136      *
137      * @param $str
138      * @return string
139      */
140     public static function base64Decode(string $str): string
141     {
142         return Base64::decode($str);
143     }
144
145     /**
146      * Encode into Base64
147      *
148      * Base64 character set "./[A-Z][a-z][0-9]"
149      * @param $src
150      * @return string
151      */
152     public static function base64EncodeDotSlash(string $str): string
153     {
154         return Base64DotSlash::encode($str);
155     }
156
157     /**
158      * Decode from base64 to raw binary
159      *
160      * Base64 character set "./[A-Z][a-z][0-9]"
161      *
162      * @param $src
163      * @return bool|string
164      * @throws \RangeException
165      */
166     public static function base64DecodeDotSlash(string $str): string
167     {
168         return Base64DotSlash::decode($str);
169     }
170
171     /**
172      * Encode into Base64
173      *
174      * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
175      * @param $src
176      * @return string
177      */
178     public static function base64EncodeDotSlashOrdered(string $str): string
179     {
180         return Base64DotSlashOrdered::encode($str);
181     }
182
183     /**
184      * Decode from base64 to raw binary
185      *
186      * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
187      *
188      * @param $src
189      * @return bool|string
190      * @throws \RangeException
191      */
192     public static function base64DecodeDotSlashOrdered(string $str): string
193     {
194         return Base64DotSlashOrdered::decode($str);
195     }
196
197     /**
198      * Convert a binary string into a hexadecimal string without cache-timing
199      * leaks
200      *
201      * @param string $bin_string (raw binary)
202      * @return string
203      */
204     public static function hexEncode(string $bin_string): string
205     {
206         return Hex::encode($bin_string);
207     }
208
209     /**
210      * Convert a hexadecimal string into a binary string without cache-timing
211      * leaks
212      *
213      * @param string $hex_string
214      * @return string (raw binary)
215      * @throws \RangeException
216      */
217     public static function hexDecode(string $hex_string): string
218     {
219         return Hex::decode($hex_string);
220     }
221
222     /**
223      * Convert a binary string into a hexadecimal string without cache-timing
224      * leaks
225      *
226      * @param string $bin_string (raw binary)
227      * @return string
228      */
229     public static function hexEncodeUpper(string $bin_string): string
230     {
231         return Hex::encodeUpper($bin_string);
232     }
233
234     /**
235      * Convert a binary string into a hexadecimal string without cache-timing
236      * leaks
237      *
238      * @param string $bin_string (raw binary)
239      * @return string
240      */
241     public static function hexDecodeUpper(string $bin_string): string
242     {
243         return Hex::decode($bin_string);
244     }
245 }