Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
fusiondirectory
constant_time_encoding
Commits
5ebee1a2
Commit
5ebee1a2
authored
3 years ago
by
Paragon Initiative Enterprises
Browse files
Options
Download
Patches
Plain Diff
Clean up unnecessary annotations
parent
0fe5aaec
master
v2.6.3
v2.6.2
v2.6.1
v2.6.0
v2.5.0
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Base32.php
+0
-1
src/Base32.php
src/Base64.php
+1
-2
src/Base64.php
src/Binary.php
+2
-2
src/Binary.php
src/Hex.php
+0
-18
src/Hex.php
with
3 additions
and
23 deletions
+3
-23
src/Base32.php
+
0
−
1
View file @
5ebee1a2
...
@@ -367,7 +367,6 @@ abstract class Base32 implements EncoderInterface
...
@@ -367,7 +367,6 @@ abstract class Base32 implements EncoderInterface
$err
|=
(
$c0
)
>>
8
;
$err
|=
(
$c0
)
>>
8
;
}
}
}
}
/** @var bool $check */
$check
=
(
$err
===
0
);
$check
=
(
$err
===
0
);
if
(
!
$check
)
{
if
(
!
$check
)
{
throw
new
\
RangeException
(
throw
new
\
RangeException
(
...
...
This diff is collapsed.
Click to expand it.
src/Base64.php
+
1
−
2
View file @
5ebee1a2
...
@@ -196,11 +196,10 @@ abstract class Base64 implements EncoderInterface
...
@@ -196,11 +196,10 @@ abstract class Base64 implements EncoderInterface
(((
$c0
<<
2
)
|
(
$c1
>>
4
))
&
0xff
)
(((
$c0
<<
2
)
|
(
$c1
>>
4
))
&
0xff
)
);
);
$err
|=
(
$c0
|
$c1
)
>>
8
;
$err
|=
(
$c0
|
$c1
)
>>
8
;
}
elseif
(
$i
<
$srcLen
&&
$strictPadding
)
{
}
elseif
(
$strictPadding
)
{
$err
|=
1
;
$err
|=
1
;
}
}
}
}
/** @var bool $check */
$check
=
(
$err
===
0
);
$check
=
(
$err
===
0
);
if
(
!
$check
)
{
if
(
!
$check
)
{
throw
new
\
RangeException
(
throw
new
\
RangeException
(
...
...
This diff is collapsed.
Click to expand it.
src/Binary.php
+
2
−
2
View file @
5ebee1a2
...
@@ -62,14 +62,14 @@ abstract class Binary
...
@@ -62,14 +62,14 @@ abstract class Binary
* @staticvar boolean $exists
* @staticvar boolean $exists
* @param string $str
* @param string $str
* @param int $start
* @param int $start
* @param int $length
* @param
?
int $length
* @return string
* @return string
* @throws \TypeError
* @throws \TypeError
*/
*/
public
static
function
safeSubstr
(
public
static
function
safeSubstr
(
string
$str
,
string
$str
,
int
$start
=
0
,
int
$start
=
0
,
$length
=
null
int
$length
=
null
):
string
{
):
string
{
if
(
$length
===
0
)
{
if
(
$length
===
0
)
{
return
''
;
return
''
;
...
...
This diff is collapsed.
Click to expand it.
src/Hex.php
+
0
−
18
View file @
5ebee1a2
...
@@ -41,15 +41,12 @@ abstract class Hex implements EncoderInterface
...
@@ -41,15 +41,12 @@ abstract class Hex implements EncoderInterface
*/
*/
public
static
function
encode
(
string
$binString
):
string
public
static
function
encode
(
string
$binString
):
string
{
{
/** @var string $hex */
$hex
=
''
;
$hex
=
''
;
$len
=
Binary
::
safeStrlen
(
$binString
);
$len
=
Binary
::
safeStrlen
(
$binString
);
for
(
$i
=
0
;
$i
<
$len
;
++
$i
)
{
for
(
$i
=
0
;
$i
<
$len
;
++
$i
)
{
/** @var array<int, int> $chunk */
/** @var array<int, int> $chunk */
$chunk
=
\
unpack
(
'C'
,
Binary
::
safeSubstr
(
$binString
,
$i
,
1
));
$chunk
=
\
unpack
(
'C'
,
Binary
::
safeSubstr
(
$binString
,
$i
,
1
));
/** @var int $c */
$c
=
$chunk
[
1
]
&
0xf
;
$c
=
$chunk
[
1
]
&
0xf
;
/** @var int $b */
$b
=
$chunk
[
1
]
>>
4
;
$b
=
$chunk
[
1
]
>>
4
;
$hex
.
=
pack
(
$hex
.
=
pack
(
...
@@ -71,17 +68,13 @@ abstract class Hex implements EncoderInterface
...
@@ -71,17 +68,13 @@ abstract class Hex implements EncoderInterface
*/
*/
public
static
function
encodeUpper
(
string
$binString
):
string
public
static
function
encodeUpper
(
string
$binString
):
string
{
{
/** @var string $hex */
$hex
=
''
;
$hex
=
''
;
/** @var int $len */
$len
=
Binary
::
safeStrlen
(
$binString
);
$len
=
Binary
::
safeStrlen
(
$binString
);
for
(
$i
=
0
;
$i
<
$len
;
++
$i
)
{
for
(
$i
=
0
;
$i
<
$len
;
++
$i
)
{
/** @var array<int, int> $chunk */
/** @var array<int, int> $chunk */
$chunk
=
\
unpack
(
'C'
,
Binary
::
safeSubstr
(
$binString
,
$i
,
2
));
$chunk
=
\
unpack
(
'C'
,
Binary
::
safeSubstr
(
$binString
,
$i
,
2
));
/** @var int $c */
$c
=
$chunk
[
1
]
&
0xf
;
$c
=
$chunk
[
1
]
&
0xf
;
/** @var int $b */
$b
=
$chunk
[
1
]
>>
4
;
$b
=
$chunk
[
1
]
>>
4
;
$hex
.
=
pack
(
$hex
.
=
pack
(
...
@@ -104,15 +97,10 @@ abstract class Hex implements EncoderInterface
...
@@ -104,15 +97,10 @@ abstract class Hex implements EncoderInterface
*/
*/
public
static
function
decode
(
string
$encodedString
,
bool
$strictPadding
=
false
):
string
public
static
function
decode
(
string
$encodedString
,
bool
$strictPadding
=
false
):
string
{
{
/** @var int $hex_pos */
$hex_pos
=
0
;
$hex_pos
=
0
;
/** @var string $bin */
$bin
=
''
;
$bin
=
''
;
/** @var int $c_acc */
$c_acc
=
0
;
$c_acc
=
0
;
/** @var int $hex_len */
$hex_len
=
Binary
::
safeStrlen
(
$encodedString
);
$hex_len
=
Binary
::
safeStrlen
(
$encodedString
);
/** @var int $state */
$state
=
0
;
$state
=
0
;
if
((
$hex_len
&
1
)
!==
0
)
{
if
((
$hex_len
&
1
)
!==
0
)
{
if
(
$strictPadding
)
{
if
(
$strictPadding
)
{
...
@@ -129,15 +117,10 @@ abstract class Hex implements EncoderInterface
...
@@ -129,15 +117,10 @@ abstract class Hex implements EncoderInterface
$chunk
=
\
unpack
(
'C*'
,
$encodedString
);
$chunk
=
\
unpack
(
'C*'
,
$encodedString
);
while
(
$hex_pos
<
$hex_len
)
{
while
(
$hex_pos
<
$hex_len
)
{
++
$hex_pos
;
++
$hex_pos
;
/** @var int $c */
$c
=
$chunk
[
$hex_pos
];
$c
=
$chunk
[
$hex_pos
];
/** @var int $c_num */
$c_num
=
$c
^
48
;
$c_num
=
$c
^
48
;
/** @var int $c_num0 */
$c_num0
=
(
$c_num
-
10
)
>>
8
;
$c_num0
=
(
$c_num
-
10
)
>>
8
;
/** @var int $c_alpha */
$c_alpha
=
(
$c
&
~
32
)
-
55
;
$c_alpha
=
(
$c
&
~
32
)
-
55
;
/** @var int $c_alpha0 */
$c_alpha0
=
((
$c_alpha
-
10
)
^
(
$c_alpha
-
16
))
>>
8
;
$c_alpha0
=
((
$c_alpha
-
10
)
^
(
$c_alpha
-
16
))
>>
8
;
if
((
$c_num0
|
$c_alpha0
)
===
0
)
{
if
((
$c_num0
|
$c_alpha0
)
===
0
)
{
...
@@ -145,7 +128,6 @@ abstract class Hex implements EncoderInterface
...
@@ -145,7 +128,6 @@ abstract class Hex implements EncoderInterface
'Expected hexadecimal character'
'Expected hexadecimal character'
);
);
}
}
/** @var int $c_val */
$c_val
=
(
$c_num0
&
$c_num
)
|
(
$c_alpha
&
$c_alpha0
);
$c_val
=
(
$c_num0
&
$c_num
)
|
(
$c_alpha
&
$c_alpha0
);
if
(
$state
===
0
)
{
if
(
$state
===
0
)
{
$c_acc
=
$c_val
*
16
;
$c_acc
=
$c_val
*
16
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets