Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
[ci skip] [skip ci]
  • Loading branch information
antonioribeiro authored and StyleCIBot committed Oct 6, 2018
1 parent b0526ba commit 9ac4355
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
51 changes: 28 additions & 23 deletions src/Google2FA.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace PragmaRX\Google2FA;

use PragmaRX\Google2FA\Support\QRCode;
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException;
use PragmaRX\Google2FA\Support\Base32;
use PragmaRX\Google2FA\Support\Constants;
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException;
use PragmaRX\Google2FA\Support\QRCode;

class Google2FA
{
Expand Down Expand Up @@ -41,10 +41,11 @@ class Google2FA
* @param $timestamp
* @param string $oldTimestamp
*
* @return bool
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
*
* @return bool
*/
public function findValidOTP($secret, $key, $window, $startingTimestamp, $timestamp, $oldTimestamp = Constants::ARGUMENT_NOT_SET)
{
Expand All @@ -63,12 +64,13 @@ public function findValidOTP($secret, $key, $window, $startingTimestamp, $timest
/**
* Generate a digit secret key in base32 format.
*
* @param int $length
* @param int $length
* @param string $prefix
*
* @return string
* @throws Exceptions\InvalidCharactersException
* @throws Exceptions\IncompatibleWithGoogleAuthenticatorException
*
* @return string
*/
public function generateSecretKey($length = 16, $prefix = '')
{
Expand All @@ -80,10 +82,11 @@ public function generateSecretKey($length = 16, $prefix = '')
*
* @param $secret
*
* @return string
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
*
* @return string
*/
public function getCurrentOtp($secret)
{
Expand Down Expand Up @@ -187,8 +190,8 @@ protected function makeTimestamp($timestamp = null)
* Takes the secret key and the timestamp and returns the one time
* password.
*
* @param string $secret - Secret key in binary form.
* @param int $counter - Timestamp as returned by getTimestamp.
* @param string $secret - Secret key in binary form.
* @param int $counter - Timestamp as returned by getTimestamp.
*
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
Expand Down Expand Up @@ -298,16 +301,17 @@ public function setWindow($window)
* Verifies a user inputted key against the current timestamp. Checks $window
* keys either side of the timestamp.
*
* @param string $key - User specified key
* @param null|string $secret
* @param null|int $window
* @param null|int $timestamp
* @param string $key - User specified key
* @param null|string $secret
* @param null|int $window
* @param null|int $timestamp
* @param null|string|int $oldTimestamp
*
* @return bool|int
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
*
* @return bool|int
*/
public function verify($key, $secret = null, $window = null, $timestamp = null, $oldTimestamp = Constants::ARGUMENT_NOT_SET)
{
Expand All @@ -324,16 +328,17 @@ public function verify($key, $secret = null, $window = null, $timestamp = null,
* Verifies a user inputted key against the current timestamp. Checks $window
* keys either side of the timestamp.
*
* @param string $secret
* @param string $key - User specified key
* @param null|int $window
* @param null|int $timestamp
* @param string $secret
* @param string $key - User specified key
* @param null|int $window
* @param null|int $timestamp
* @param null|string|int $oldTimestamp
*
* @return bool|int
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
*
* @return bool|int
*/
public function verifyKey($secret, $key, $window = null, $timestamp = null, $oldTimestamp = Constants::ARGUMENT_NOT_SET)
{
Expand All @@ -355,17 +360,17 @@ public function verifyKey($secret, $key, $window = null, $timestamp = null, $old
* the given oldTimestamp. Useful if you need to ensure that a single key cannot
* be used twice.
*
* @param string $secret
* @param string $key - User specified key
* @param int $oldTimestamp - The timestamp from the last verified key
* @param string $secret
* @param string $key - User specified key
* @param int $oldTimestamp - The timestamp from the last verified key
* @param int|null $window
* @param int|null $timestamp
*
* @return bool|int - false (not verified) or the timestamp of the verified key
*
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
*
* @return bool|int - false (not verified) or the timestamp of the verified key
*/
public function verifyKeyNewer($secret, $key, $oldTimestamp, $window = null, $timestamp = null)
{
Expand Down
16 changes: 10 additions & 6 deletions src/Support/Base32.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace PragmaRX\Google2FA\Support;

use ParagonIE\ConstantTime\Base32 as ParagonieBase32;
use PragmaRX\Google2FA\Exceptions\InvalidCharactersException;
use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException;
use PragmaRX\Google2FA\Exceptions\InvalidCharactersException;

trait Base32
{
Expand All @@ -16,12 +16,13 @@ trait Base32
/**
* Generate a digit secret key in base32 format.
*
* @param int $length
*
* @param int $length
* @param string $prefix
* @return string
*
* @throws IncompatibleWithGoogleAuthenticatorException
* @throws InvalidCharactersException
*
* @return string
*/
public function generateBase32RandomKey($length = 16, $prefix = '')
{
Expand Down Expand Up @@ -59,8 +60,9 @@ public function base32Decode($b32)
* @param $string
* @param $length
*
* @return string
* @throws \Exception
*
* @return string
*/
private function strPadBase32($string, $length)
{
Expand Down Expand Up @@ -91,8 +93,9 @@ public function toBase32($string)
* @param $from
* @param $to
*
* @return int
* @throws \Exception
*
* @return int
*/
protected function getRandomNumber($from = 0, $to = 31)
{
Expand All @@ -103,6 +106,7 @@ protected function getRandomNumber($from = 0, $to = 31)
* Validate the secret.
*
* @param $b32
*
* @throws IncompatibleWithGoogleAuthenticatorException
* @throws InvalidCharactersException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Support/QRCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait QRCode
* @param string $company
* @param string $holder
* @param string $secret
* @param int $size
* @param int $size
*
* @throws \PragmaRX\Google2FA\Exceptions\InsecureCallException
*
Expand Down
1 change: 1 addition & 0 deletions tests/Google2FATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function testValidateKey()
public function setAllowInsecureCallToGoogleApis($allowInsecureCallToGoogleApis)
{
$this->allowInsecureCallToGoogleApis = $allowInsecureCallToGoogleApis;

return $this;
}
}

0 comments on commit 9ac4355

Please sign in to comment.