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