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
otphp
Commits
c7051644
Commit
c7051644
authored
2 years ago
by
Filippo Tessarotto
Committed by
Florent Morselli
2 years ago
Browse files
Options
Download
Patches
Plain Diff
Single point of secret creation
parent
8c05e668
11.2.x
11.0.x
11.1.x
dependabot/composer/phpunit/phpunit-tw-9.5.26or-tw-10.0.0
11.1.0
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
phpstan.neon
+1
-0
phpstan.neon
src/HOTP.php
+1
-4
src/HOTP.php
src/OTP.php
+8
-0
src/OTP.php
src/TOTP.php
+1
-4
src/TOTP.php
with
11 additions
and
8 deletions
+11
-8
phpstan.neon
+
1
−
0
View file @
c7051644
...
@@ -5,6 +5,7 @@ parameters:
...
@@ -5,6 +5,7 @@ parameters:
- tests
- tests
ignoreErrors:
ignoreErrors:
- '#Variable property access on \$this\(OTPHP\\OTP\)\.#'
- '#Variable property access on \$this\(OTPHP\\OTP\)\.#'
- '#^Method OTPHP\\OTP::generateSecret\(\) should return non-empty-string but returns string\.$#'
includes:
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
...
...
This diff is collapsed.
Click to expand it.
src/HOTP.php
+
1
−
4
View file @
c7051644
...
@@ -6,7 +6,6 @@ namespace OTPHP;
...
@@ -6,7 +6,6 @@ namespace OTPHP;
use
InvalidArgumentException
;
use
InvalidArgumentException
;
use
function
is_int
;
use
function
is_int
;
use
ParagonIE\ConstantTime\Base32
;
/**
/**
* @see \OTPHP\Test\HOTPTest
* @see \OTPHP\Test\HOTPTest
...
@@ -39,9 +38,7 @@ final class HOTP extends OTP implements HOTPInterface
...
@@ -39,9 +38,7 @@ final class HOTP extends OTP implements HOTPInterface
public
static
function
generate
(
int
$counter
=
0
,
string
$digest
=
'sha1'
,
int
$digits
=
6
):
self
public
static
function
generate
(
int
$counter
=
0
,
string
$digest
=
'sha1'
,
int
$digits
=
6
):
self
{
{
$secret
=
Base32
::
encodeUpper
(
random_bytes
(
64
));
return
new
self
(
self
::
generateSecret
(),
$counter
,
$digest
,
$digits
);
return
new
self
(
$secret
,
$counter
,
$digest
,
$digits
);
}
}
public
function
getCounter
():
int
public
function
getCounter
():
int
...
...
This diff is collapsed.
Click to expand it.
src/OTP.php
+
8
−
0
View file @
c7051644
...
@@ -36,6 +36,14 @@ abstract class OTP implements OTPInterface
...
@@ -36,6 +36,14 @@ abstract class OTP implements OTPInterface
return
$this
->
generateOTP
(
$input
);
return
$this
->
generateOTP
(
$input
);
}
}
/**
* @return non-empty-string
*/
final
protected
static
function
generateSecret
():
string
{
return
Base32
::
encodeUpper
(
random_bytes
(
64
));
}
/**
/**
* The OTP at the specified input.
* The OTP at the specified input.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
src/TOTP.php
+
1
−
4
View file @
c7051644
...
@@ -6,7 +6,6 @@ namespace OTPHP;
...
@@ -6,7 +6,6 @@ namespace OTPHP;
use
InvalidArgumentException
;
use
InvalidArgumentException
;
use
function
is_int
;
use
function
is_int
;
use
ParagonIE\ConstantTime\Base32
;
/**
/**
* @see \OTPHP\Test\TOTPTest
* @see \OTPHP\Test\TOTPTest
...
@@ -46,9 +45,7 @@ final class TOTP extends OTP implements TOTPInterface
...
@@ -46,9 +45,7 @@ final class TOTP extends OTP implements TOTPInterface
int
$digits
=
6
,
int
$digits
=
6
,
int
$epoch
=
0
int
$epoch
=
0
):
self
{
):
self
{
$secret
=
Base32
::
encodeUpper
(
random_bytes
(
64
));
return
new
self
(
self
::
generateSecret
(),
$period
,
$digest
,
$digits
,
$epoch
);
return
new
self
(
$secret
,
$period
,
$digest
,
$digits
,
$epoch
);
}
}
public
function
getPeriod
():
int
public
function
getPeriod
():
int
...
...
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