Subversion Repositories oidplus

Rev

Rev 827 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 827 Rev 874
Line 1... Line 1...
1
<?php
1
<?php
2
declare(strict_types=1);
2
declare(strict_types=1);
3
namespace ParagonIE\ConstantTime;
3
namespace ParagonIE\ConstantTime;
4
 
4
 
-
 
5
use TypeError;
-
 
6
 
5
/**
7
/**
6
 *  Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
8
 *  Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
7
 *  Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
9
 *  Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
8
 *
10
 *
9
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
11
 *  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
12
 *  of this software and associated documentation files (the "Software"), to deal
11
 *  in the Software without restriction, including without limitation the rights
13
 *  in the Software without restriction, including without limitation the rights
Line 34... Line 36...
34
    /**
36
    /**
35
     * RFC 4648 Base32 encoding
37
     * RFC 4648 Base32 encoding
36
     *
38
     *
37
     * @param string $str
39
     * @param string $str
38
     * @return string
40
     * @return string
39
     * @throws \TypeError
41
     * @throws TypeError
40
     */
42
     */
41
    public static function base32Encode(string $str): string
43
    public static function base32Encode(string $str): string
42
    {
44
    {
43
        return Base32::encode($str);
45
        return Base32::encode($str);
44
    }
46
    }
Line 46... Line 48...
46
    /**
48
    /**
47
     * RFC 4648 Base32 encoding
49
     * RFC 4648 Base32 encoding
48
     *
50
     *
49
     * @param string $str
51
     * @param string $str
50
     * @return string
52
     * @return string
51
     * @throws \TypeError
53
     * @throws TypeError
52
     */
54
     */
53
    public static function base32EncodeUpper(string $str): string
55
    public static function base32EncodeUpper(string $str): string
54
    {
56
    {
55
        return Base32::encodeUpper($str);
57
        return Base32::encodeUpper($str);
56
    }
58
    }
Line 58... Line 60...
58
    /**
60
    /**
59
     * RFC 4648 Base32 decoding
61
     * RFC 4648 Base32 decoding
60
     *
62
     *
61
     * @param string $str
63
     * @param string $str
62
     * @return string
64
     * @return string
63
     * @throws \TypeError
65
     * @throws TypeError
64
     */
66
     */
65
    public static function base32Decode(string $str): string
67
    public static function base32Decode(string $str): string
66
    {
68
    {
67
        return Base32::decode($str);
69
        return Base32::decode($str);
68
    }
70
    }
Line 70... Line 72...
70
    /**
72
    /**
71
     * RFC 4648 Base32 decoding
73
     * RFC 4648 Base32 decoding
72
     *
74
     *
73
     * @param string $str
75
     * @param string $str
74
     * @return string
76
     * @return string
75
     * @throws \TypeError
77
     * @throws TypeError
76
     */
78
     */
77
    public static function base32DecodeUpper(string $str): string
79
    public static function base32DecodeUpper(string $str): string
78
    {
80
    {
79
        return Base32::decodeUpper($str);
81
        return Base32::decodeUpper($str);
80
    }
82
    }
Line 82... Line 84...
82
    /**
84
    /**
83
     * RFC 4648 Base32 encoding
85
     * RFC 4648 Base32 encoding
84
     *
86
     *
85
     * @param string $str
87
     * @param string $str
86
     * @return string
88
     * @return string
87
     * @throws \TypeError
89
     * @throws TypeError
88
     */
90
     */
89
    public static function base32HexEncode(string $str): string
91
    public static function base32HexEncode(string $str): string
90
    {
92
    {
91
        return Base32Hex::encode($str);
93
        return Base32Hex::encode($str);
92
    }
94
    }
Line 94... Line 96...
94
    /**
96
    /**
95
     * RFC 4648 Base32Hex encoding
97
     * RFC 4648 Base32Hex encoding
96
     *
98
     *
97
     * @param string $str
99
     * @param string $str
98
     * @return string
100
     * @return string
99
     * @throws \TypeError
101
     * @throws TypeError
100
     */
102
     */
101
    public static function base32HexEncodeUpper(string $str): string
103
    public static function base32HexEncodeUpper(string $str): string
102
    {
104
    {
103
        return Base32Hex::encodeUpper($str);
105
        return Base32Hex::encodeUpper($str);
104
    }
106
    }
Line 106... Line 108...
106
    /**
108
    /**
107
     * RFC 4648 Base32Hex decoding
109
     * RFC 4648 Base32Hex decoding
108
     *
110
     *
109
     * @param string $str
111
     * @param string $str
110
     * @return string
112
     * @return string
111
     * @throws \TypeError
113
     * @throws TypeError
112
     */
114
     */
113
    public static function base32HexDecode(string $str): string
115
    public static function base32HexDecode(string $str): string
114
    {
116
    {
115
        return Base32Hex::decode($str);
117
        return Base32Hex::decode($str);
116
    }
118
    }
Line 118... Line 120...
118
    /**
120
    /**
119
     * RFC 4648 Base32Hex decoding
121
     * RFC 4648 Base32Hex decoding
120
     *
122
     *
121
     * @param string $str
123
     * @param string $str
122
     * @return string
124
     * @return string
123
     * @throws \TypeError
125
     * @throws TypeError
124
     */
126
     */
125
    public static function base32HexDecodeUpper(string $str): string
127
    public static function base32HexDecodeUpper(string $str): string
126
    {
128
    {
127
        return Base32Hex::decodeUpper($str);
129
        return Base32Hex::decodeUpper($str);
128
    }
130
    }
Line 130... Line 132...
130
    /**
132
    /**
131
     * RFC 4648 Base64 encoding
133
     * RFC 4648 Base64 encoding
132
     *
134
     *
133
     * @param string $str
135
     * @param string $str
134
     * @return string
136
     * @return string
135
     * @throws \TypeError
137
     * @throws TypeError
136
     */
138
     */
137
    public static function base64Encode(string $str): string
139
    public static function base64Encode(string $str): string
138
    {
140
    {
139
        return Base64::encode($str);
141
        return Base64::encode($str);
140
    }
142
    }
Line 142... Line 144...
142
    /**
144
    /**
143
     * RFC 4648 Base64 decoding
145
     * RFC 4648 Base64 decoding
144
     *
146
     *
145
     * @param string $str
147
     * @param string $str
146
     * @return string
148
     * @return string
147
     * @throws \TypeError
149
     * @throws TypeError
148
     */
150
     */
149
    public static function base64Decode(string $str): string
151
    public static function base64Decode(string $str): string
150
    {
152
    {
151
        return Base64::decode($str);
153
        return Base64::decode($str);
152
    }
154
    }
Line 155... Line 157...
155
     * Encode into Base64
157
     * Encode into Base64
156
     *
158
     *
157
     * Base64 character set "./[A-Z][a-z][0-9]"
159
     * Base64 character set "./[A-Z][a-z][0-9]"
158
     * @param string $str
160
     * @param string $str
159
     * @return string
161
     * @return string
160
     * @throws \TypeError
162
     * @throws TypeError
161
     */
163
     */
162
    public static function base64EncodeDotSlash(string $str): string
164
    public static function base64EncodeDotSlash(string $str): string
163
    {
165
    {
164
        return Base64DotSlash::encode($str);
166
        return Base64DotSlash::encode($str);
165
    }
167
    }
Line 170... Line 172...
170
     * Base64 character set "./[A-Z][a-z][0-9]"
172
     * Base64 character set "./[A-Z][a-z][0-9]"
171
     *
173
     *
172
     * @param string $str
174
     * @param string $str
173
     * @return string
175
     * @return string
174
     * @throws \RangeException
176
     * @throws \RangeException
175
     * @throws \TypeError
177
     * @throws TypeError
176
     */
178
     */
177
    public static function base64DecodeDotSlash(string $str): string
179
    public static function base64DecodeDotSlash(string $str): string
178
    {
180
    {
179
        return Base64DotSlash::decode($str);
181
        return Base64DotSlash::decode($str);
180
    }
182
    }
Line 183... Line 185...
183
     * Encode into Base64
185
     * Encode into Base64
184
     *
186
     *
185
     * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
187
     * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
186
     * @param string $str
188
     * @param string $str
187
     * @return string
189
     * @return string
188
     * @throws \TypeError
190
     * @throws TypeError
189
     */
191
     */
190
    public static function base64EncodeDotSlashOrdered(string $str): string
192
    public static function base64EncodeDotSlashOrdered(string $str): string
191
    {
193
    {
192
        return Base64DotSlashOrdered::encode($str);
194
        return Base64DotSlashOrdered::encode($str);
193
    }
195
    }
Line 198... Line 200...
198
     * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
200
     * Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
199
     *
201
     *
200
     * @param string $str
202
     * @param string $str
201
     * @return string
203
     * @return string
202
     * @throws \RangeException
204
     * @throws \RangeException
203
     * @throws \TypeError
205
     * @throws TypeError
204
     */
206
     */
205
    public static function base64DecodeDotSlashOrdered(string $str): string
207
    public static function base64DecodeDotSlashOrdered(string $str): string
206
    {
208
    {
207
        return Base64DotSlashOrdered::decode($str);
209
        return Base64DotSlashOrdered::decode($str);
208
    }
210
    }
Line 211... Line 213...
211
     * Convert a binary string into a hexadecimal string without cache-timing
213
     * Convert a binary string into a hexadecimal string without cache-timing
212
     * leaks
214
     * leaks
213
     *
215
     *
214
     * @param string $bin_string (raw binary)
216
     * @param string $bin_string (raw binary)
215
     * @return string
217
     * @return string
216
     * @throws \TypeError
218
     * @throws TypeError
217
     */
219
     */
218
    public static function hexEncode(string $bin_string): string
220
    public static function hexEncode(string $bin_string): string
219
    {
221
    {
220
        return Hex::encode($bin_string);
222
        return Hex::encode($bin_string);
221
    }
223
    }
Line 237... Line 239...
237
     * Convert a binary string into a hexadecimal string without cache-timing
239
     * Convert a binary string into a hexadecimal string without cache-timing
238
     * leaks
240
     * leaks
239
     *
241
     *
240
     * @param string $bin_string (raw binary)
242
     * @param string $bin_string (raw binary)
241
     * @return string
243
     * @return string
242
     * @throws \TypeError
244
     * @throws TypeError
243
     */
245
     */
244
    public static function hexEncodeUpper(string $bin_string): string
246
    public static function hexEncodeUpper(string $bin_string): string
245
    {
247
    {
246
        return Hex::encodeUpper($bin_string);
248
        return Hex::encodeUpper($bin_string);
247
    }
249
    }