33namespace ParagonIE \ConstantTime ;
44
55use InvalidArgumentException ;
6+ use Override ;
67use RangeException ;
8+ use SensitiveParameter ;
79use TypeError ;
10+ use function pack ;
11+ use function rtrim ;
12+ use function strlen ;
13+ use function substr ;
14+ use function unpack ;
815
916/**
1017 * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
@@ -44,9 +51,9 @@ abstract class Base32 implements EncoderInterface
4451 * @param bool $strictPadding
4552 * @return string
4653 */
47- #[\ Override]
54+ #[Override]
4855 public static function decode (
49- #[\ SensitiveParameter]
56+ #[SensitiveParameter]
5057 string $ encodedString ,
5158 bool $ strictPadding = false
5259 ): string {
@@ -61,7 +68,7 @@ public static function decode(
6168 * @return string
6269 */
6370 public static function decodeUpper (
64- #[\ SensitiveParameter]
71+ #[SensitiveParameter]
6572 string $ src ,
6673 bool $ strictPadding = false
6774 ): string {
@@ -75,9 +82,9 @@ public static function decodeUpper(
7582 * @return string
7683 * @throws TypeError
7784 */
78- #[\ Override]
85+ #[Override]
7986 public static function encode (
80- #[\ SensitiveParameter]
87+ #[SensitiveParameter]
8188 string $ binString
8289 ): string {
8390 return static ::doEncode ($ binString , false , true );
@@ -92,7 +99,7 @@ public static function encode(
9299 * @api
93100 */
94101 public static function encodeUnpadded (
95- #[\ SensitiveParameter]
102+ #[SensitiveParameter]
96103 string $ src
97104 ): string {
98105 return static ::doEncode ($ src , false , false );
@@ -107,7 +114,7 @@ public static function encodeUnpadded(
107114 * @api
108115 */
109116 public static function encodeUpper (
110- #[\ SensitiveParameter]
117+ #[SensitiveParameter]
111118 string $ src
112119 ): string {
113120 return static ::doEncode ($ src , true , true );
@@ -122,7 +129,7 @@ public static function encodeUpper(
122129 * @api
123130 */
124131 public static function encodeUpperUnpadded (
125- #[\ SensitiveParameter]
132+ #[SensitiveParameter]
126133 string $ src
127134 ): string {
128135 return static ::doEncode ($ src , true , false );
@@ -187,7 +194,7 @@ protected static function encode5Bits(int $src): string
187194 // if ($src > 25) $ret -= 72;
188195 $ diff -= ((25 - $ src ) >> 8 ) & 73 ;
189196
190- return \ pack ('C ' , $ src + $ diff );
197+ return pack ('C ' , $ src + $ diff );
191198 }
192199
193200 /**
@@ -207,7 +214,7 @@ protected static function encode5BitsUpper(int $src): string
207214 // if ($src > 25) $ret -= 40;
208215 $ diff -= ((25 - $ src ) >> 8 ) & 41 ;
209216
210- return \ pack ('C ' , $ src + $ diff );
217+ return pack ('C ' , $ src + $ diff );
211218 }
212219
213220 /**
@@ -217,11 +224,11 @@ protected static function encode5BitsUpper(int $src): string
217224 * @api
218225 */
219226 public static function decodeNoPadding (
220- #[\ SensitiveParameter]
227+ #[SensitiveParameter]
221228 string $ encodedString ,
222229 bool $ upper = false
223230 ): string {
224- $ srcLen = \ strlen ($ encodedString );
231+ $ srcLen = strlen ($ encodedString );
225232 if ($ srcLen === 0 ) {
226233 return '' ;
227234 }
@@ -252,7 +259,7 @@ public static function decodeNoPadding(
252259 * @throws TypeError
253260 */
254261 protected static function doDecode (
255- #[\ SensitiveParameter]
262+ #[SensitiveParameter]
256263 string $ src ,
257264 bool $ upper = false ,
258265 bool $ strictPadding = false
@@ -263,7 +270,7 @@ protected static function doDecode(
263270 : 'decode5Bits ' ;
264271
265272 // Remove padding
266- $ srcLen = \ strlen ($ src );
273+ $ srcLen = strlen ($ src );
267274 if ($ srcLen === 0 ) {
268275 return '' ;
269276 }
@@ -283,16 +290,16 @@ protected static function doDecode(
283290 );
284291 }
285292 } else {
286- $ src = \ rtrim ($ src , '= ' );
287- $ srcLen = \ strlen ($ src );
293+ $ src = rtrim ($ src , '= ' );
294+ $ srcLen = strlen ($ src );
288295 }
289296
290297 $ err = 0 ;
291298 $ dest = '' ;
292299 // Main loop (no padding):
293300 for ($ i = 0 ; $ i + 8 <= $ srcLen ; $ i += 8 ) {
294301 /** @var array<int, int> $chunk */
295- $ chunk = \ unpack ('C* ' , \ substr ($ src , $ i , 8 ));
302+ $ chunk = unpack ('C* ' , substr ($ src , $ i , 8 ));
296303 /** @var int $c0 */
297304 $ c0 = static ::$ method ($ chunk [1 ]);
298305 /** @var int $c1 */
@@ -310,7 +317,7 @@ protected static function doDecode(
310317 /** @var int $c7 */
311318 $ c7 = static ::$ method ($ chunk [8 ]);
312319
313- $ dest .= \ pack (
320+ $ dest .= pack (
314321 'CCCCC ' ,
315322 (($ c0 << 3 ) | ($ c1 >> 2 ) ) & 0xff ,
316323 (($ c1 << 6 ) | ($ c2 << 1 ) | ($ c3 >> 4 )) & 0xff ,
@@ -323,7 +330,7 @@ protected static function doDecode(
323330 // The last chunk, which may have padding:
324331 if ($ i < $ srcLen ) {
325332 /** @var array<int, int> $chunk */
326- $ chunk = \ unpack ('C* ' , \ substr ($ src , $ i , $ srcLen - $ i ));
333+ $ chunk = unpack ('C* ' , substr ($ src , $ i , $ srcLen - $ i ));
327334 /** @var int $c0 */
328335 $ c0 = static ::$ method ($ chunk [1 ]);
329336
@@ -341,7 +348,7 @@ protected static function doDecode(
341348 /** @var int $c6 */
342349 $ c6 = static ::$ method ($ chunk [7 ]);
343350
344- $ dest .= \ pack (
351+ $ dest .= pack (
345352 'CCCC ' ,
346353 (($ c0 << 3 ) | ($ c1 >> 2 ) ) & 0xff ,
347354 (($ c1 << 6 ) | ($ c2 << 1 ) | ($ c3 >> 4 )) & 0xff ,
@@ -364,7 +371,7 @@ protected static function doDecode(
364371 /** @var int $c5 */
365372 $ c5 = static ::$ method ($ chunk [6 ]);
366373
367- $ dest .= \ pack (
374+ $ dest .= pack (
368375 'CCCC ' ,
369376 (($ c0 << 3 ) | ($ c1 >> 2 ) ) & 0xff ,
370377 (($ c1 << 6 ) | ($ c2 << 1 ) | ($ c3 >> 4 )) & 0xff ,
@@ -382,7 +389,7 @@ protected static function doDecode(
382389 /** @var int $c4 */
383390 $ c4 = static ::$ method ($ chunk [5 ]);
384391
385- $ dest .= \ pack (
392+ $ dest .= pack (
386393 'CCC ' ,
387394 (($ c0 << 3 ) | ($ c1 >> 2 ) ) & 0xff ,
388395 (($ c1 << 6 ) | ($ c2 << 1 ) | ($ c3 >> 4 )) & 0xff ,
@@ -400,7 +407,7 @@ protected static function doDecode(
400407 /** @var int $c3 */
401408 $ c3 = static ::$ method ($ chunk [4 ]);
402409
403- $ dest .= \ pack (
410+ $ dest .= pack (
404411 'CC ' ,
405412 (($ c0 << 3 ) | ($ c1 >> 2 ) ) & 0xff ,
406413 (($ c1 << 6 ) | ($ c2 << 1 ) | ($ c3 >> 4 )) & 0xff
@@ -415,7 +422,7 @@ protected static function doDecode(
415422 /** @var int $c2 */
416423 $ c2 = static ::$ method ($ chunk [3 ]);
417424
418- $ dest .= \ pack (
425+ $ dest .= pack (
419426 'CC ' ,
420427 (($ c0 << 3 ) | ($ c1 >> 2 ) ) & 0xff ,
421428 (($ c1 << 6 ) | ($ c2 << 1 ) ) & 0xff
@@ -428,7 +435,7 @@ protected static function doDecode(
428435 /** @var int $c1 */
429436 $ c1 = static ::$ method ($ chunk [2 ]);
430437
431- $ dest .= \ pack (
438+ $ dest .= pack (
432439 'C ' ,
433440 (($ c0 << 3 ) | ($ c1 >> 2 ) ) & 0xff
434441 );
@@ -437,7 +444,7 @@ protected static function doDecode(
437444 $ err |= ($ c1 << 6 ) & 0xff ;
438445 }
439446 } else {
440- $ dest .= \ pack (
447+ $ dest .= pack (
441448 'C ' ,
442449 (($ c0 << 3 ) ) & 0xff
443450 );
@@ -463,7 +470,7 @@ protected static function doDecode(
463470 * @throws TypeError
464471 */
465472 protected static function doEncode (
466- #[\ SensitiveParameter]
473+ #[SensitiveParameter]
467474 string $ src ,
468475 bool $ upper = false ,
469476 bool $ pad = true
@@ -474,12 +481,12 @@ protected static function doEncode(
474481 : 'encode5Bits ' ;
475482
476483 $ dest = '' ;
477- $ srcLen = \ strlen ($ src );
484+ $ srcLen = strlen ($ src );
478485
479486 // Main loop (no padding):
480487 for ($ i = 0 ; $ i + 5 <= $ srcLen ; $ i += 5 ) {
481488 /** @var array<int, int> $chunk */
482- $ chunk = \ unpack ('C* ' , \ substr ($ src , $ i , 5 ));
489+ $ chunk = unpack ('C* ' , substr ($ src , $ i , 5 ));
483490 $ b0 = $ chunk [1 ];
484491 $ b1 = $ chunk [2 ];
485492 $ b2 = $ chunk [3 ];
@@ -498,7 +505,7 @@ protected static function doEncode(
498505 // The last chunk, which may have padding:
499506 if ($ i < $ srcLen ) {
500507 /** @var array<int, int> $chunk */
501- $ chunk = \ unpack ('C* ' , \ substr ($ src , $ i , $ srcLen - $ i ));
508+ $ chunk = unpack ('C* ' , substr ($ src , $ i , $ srcLen - $ i ));
502509 $ b0 = $ chunk [1 ];
503510 if ($ i + 3 < $ srcLen ) {
504511 $ b1 = $ chunk [2 ];
0 commit comments