]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/ParagonIE/ConstantTime/RFC4648.php
Merge remote-tracking branch 'upstream/master' into nightly
[quix0rs-gnu-social.git] / extlib / ParagonIE / ConstantTime / RFC4648.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 RFC4648
29  *
30  * This class conforms strictly to the RFC
31  *
32  * @package ParagonIE\ConstantTime
33  */
34 abstract class RFC4648
35 {
36     /**
37      * RFC 4648 Base64 encoding
38      *
39      * "foo" -> "Zm9v"
40      *
41      * @param string $str
42      * @return string
43      */
44     public function base64Encode($str)
45     {
46         return Base64::encode($str);
47     }
48
49     /**
50      * RFC 4648 Base64 decoding
51      *
52      * "Zm9v" -> "foo"
53      *
54      * @param string $str
55      * @return string
56      */
57     public function base64Decode($str)
58     {
59         return Base64::decode($str);
60     }
61
62     /**
63      * RFC 4648 Base64 (URL Safe) encoding
64      *
65      * "foo" -> "Zm9v"
66      *
67      * @param string $str
68      * @return string
69      */
70     public function base64UrlSafeEncode($str)
71     {
72         return Base64UrlSafe::encode($str);
73     }
74
75     /**
76      * RFC 4648 Base64 (URL Safe) decoding
77      *
78      * "Zm9v" -> "foo"
79      *
80      * @param string $str
81      * @return string
82      */
83     public function base64UrlSafeDecode($str)
84     {
85         return Base64UrlSafe::decode($str);
86     }
87
88     /**
89      * RFC 4648 Base32 encoding
90      *
91      * "foo" -> "MZXW6==="
92      *
93      * @param string $str
94      * @return string
95      */
96     public function base32Encode($str)
97     {
98         return Base32::encodeUpper($str);
99     }
100
101     /**
102      * RFC 4648 Base32 encoding
103      *
104      * "MZXW6===" -> "foo"
105      *
106      * @param string $str
107      * @return string
108      */
109     public function base32Decode($str)
110     {
111         return Base32::decodeUpper($str);
112     }
113
114     /**
115      * RFC 4648 Base32-Hex encoding
116      *
117      * "foo" -> "CPNMU==="
118      *
119      * @param string $str
120      * @return string
121      */
122     public function base32HexEncode($str)
123     {
124         return Base32::encodeUpper($str);
125     }
126
127     /**
128      * RFC 4648 Base32-Hex decoding
129      *
130      * "CPNMU===" -> "foo"
131      *
132      * @param string $str
133      * @return string
134      */
135     public function base32HexDecode($str)
136     {
137         return Base32::decodeUpper($str);
138     }
139
140     /**
141      * RFC 4648 Base16 decoding
142      *
143      * "foo" -> "666F6F"
144      *
145      * @param string $str
146      * @return string
147      */
148     public function base16Encode($str)
149     {
150         return Hex::encodeUpper($str);
151     }
152
153     /**
154      * RFC 4648 Base16 decoding
155      *
156      * "666F6F" -> "foo"
157      *
158      * @param string $str
159      * @return string
160      */
161     public function base16Decode($str)
162     {
163         return Hex::decode($str);
164     }
165 }