Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Commit

Permalink
Refactored to use driver classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Sep 24, 2013
1 parent 4d99abe commit 4897f1a
Show file tree
Hide file tree
Showing 74 changed files with 2,053 additions and 1,584 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/*
* This file is part of the Otis package.
*
* Copyright © 2013 Erin Millard
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Configuration;

use Eloquent\Otis\Exception\InvalidPasswordLengthException;

/**
* An abstract base class for creating counter-based one-time password
* authentication configurations.
*/
abstract class AbstractCounterBasedOtpConfiguration
extends AbstractOtpConfiguration
implements CounterBasedOtpConfigurationInterface
{
/**
* Construct a new counter-based one-time password authentication
* configuration.
*
* @param integer|null $digits The number of password digits.
* @param integer|null $window The amount of counter increments to search through for a match.
* @param integer|null $initialCounter The initial counter value.
* @param integer|null $secretLength The length of the shared secret.
*
* @throws InvalidPasswordLengthException If the number of digits is invalid.
*/
public function __construct(
$digits = null,
$window = null,
$initialCounter = null,
$secretLength = null
) {
if (null === $window) {
$window = 10;
}
if (null === $initialCounter) {
$initialCounter = 1;
}

parent::__construct($digits, $secretLength);

$this->window = $window;
$this->initialCounter = $initialCounter;
}

/**
* Get the amount of counter increments to search through for a match.
*
* @return integer The amount of counter increments to search through for a match.
*/
public function window()
{
return $this->window;
}

/**
* Get the initial counter value.
*
* @return integer The initial counter value.
*/
public function initialCounter()
{
return $this->initialCounter;
}

private $window;
private $initialCounter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,39 @@
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Hotp\Configuration;
namespace Eloquent\Otis\Configuration;

use Eloquent\Otis\Exception\InvalidPasswordLengthException;
use Eloquent\Otis\Hotp\HotpHashAlgorithm;

/**
* An abstract base class for implementing one-time password authentication
* configurations based upon HOTP.
* configurations.
*/
abstract class AbstractHotpBasedOtpConfiguration implements
HotpBasedConfigurationInterface
abstract class AbstractOtpConfiguration implements OtpConfigurationInterface
{
/**
* Construct a new one-time password authentication configuration.
*
* @param integer|null $digits The number of password digits.
* @param integer|null $secretLength The length of the shared secret.
* @param HotpHashAlgorithm|null $algorithm The underlying hash algorithm to use.
* @param integer|null $digits The number of password digits.
* @param integer|null $secretLength The length of the shared secret.
*
* @throws InvalidPasswordLengthException If the number of digits is invalid.
*/
public function __construct(
$digits = null,
$secretLength = null,
HotpHashAlgorithm $algorithm = null
) {
public function __construct($digits = null, $secretLength = null)
{
if (null === $digits) {
$digits = 6;
}
if (null === $secretLength) {
$secretLength = 10;
}
if (null === $algorithm) {
$algorithm = HotpHashAlgorithm::SHA1();
}

if ($digits < 6 || $digits > 10) {
if ($digits < 6) {
throw new InvalidPasswordLengthException($digits);
}

$this->digits = $digits;
$this->secretLength = $secretLength;
$this->algorithm = $algorithm;
}

/**
Expand All @@ -74,17 +64,6 @@ public function secretLength()
return $this->secretLength;
}

/**
* Get the underlying algorithm name.
*
* @return HotpHashAlgorithm The algorithm name.
*/
public function algorithm()
{
return $this->algorithm;
}

private $digits;
private $secretLength;
private $algorithm;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

/*
* This file is part of the Otis package.
*
* Copyright © 2013 Erin Millard
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Configuration;

use Eloquent\Otis\Exception\InvalidPasswordLengthException;

/**
* An abstract base class for creating time-based one-time password
* authentication configurations.
*/
abstract class AbstractTimeBasedOtpConfiguration
extends AbstractOtpConfiguration
implements TimeBasedOtpConfigurationInterface
{
/**
* Construct a new time-based one-time password authentication
* configuration.
*
* @param integer|null $digits The number of password digits.
* @param integer|null $window The number of seconds each token is valid for.
* @param integer|null $futureWindows The number of future windows to check.
* @param integer|null $pastWindows The number of past windows to check.
* @param integer|null $secretLength The length of the shared secret.
*
* @throws InvalidPasswordLengthException If the number of digits is invalid.
*/
public function __construct(
$digits = null,
$window = null,
$futureWindows = null,
$pastWindows = null,
$secretLength = null
) {
if (null === $window) {
$window = 30;
}
if (null === $futureWindows) {
$futureWindows = 1;
}
if (null === $pastWindows) {
$pastWindows = 1;
}

parent::__construct($digits, $secretLength);

$this->window = $window;
$this->futureWindows = $futureWindows;
$this->pastWindows = $pastWindows;
}

/**
* Get the number of seconds each token is valid for.
*
* @return integer The number of seconds each token is valid for.
*/
public function window()
{
return $this->window;
}

/**
* Get the number of future windows to check.
*
* @return integer The number of future windows to check.
*/
public function futureWindows()
{
return $this->futureWindows;
}

/**
* Get the number of past windows to check.
*
* @return integer The number of past windows to check.
*/
public function pastWindows()
{
return $this->pastWindows;
}

private $window;
private $futureWindows;
private $pastWindows;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the Otis package.
*
* Copyright © 2013 Erin Millard
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Configuration;

/**
* The interface implemented by counter-based one-time password authentication
* configurations.
*/
interface CounterBasedOtpConfigurationInterface extends
OtpConfigurationInterface
{
/**
* Get the amount of counter increments to search through for a match.
*
* @return integer The amount of counter increments to search through for a match.
*/
public function window();

/**
* Get the initial counter value.
*
* @return integer The initial counter value.
*/
public function initialCounter();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // @codeCoverageIgnoreStart
<?php

/*
* This file is part of the Otis package.
Expand Down
32 changes: 32 additions & 0 deletions src/Eloquent/Otis/Configuration/OtpConfigurationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Otis package.
*
* Copyright © 2013 Erin Millard
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Configuration;

/**
* The interface implemented by one-time password authentication configurations.
*/
interface OtpConfigurationInterface extends MfaConfigurationInterface
{
/**
* Get the number of password digits.
*
* @return integer The number of digits.
*/
public function digits();

/**
* Get the length of the shared secret.
*
* @return integer The secret length.
*/
public function secretLength();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the Otis package.
*
* Copyright © 2013 Erin Millard
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Configuration;

/**
* The interface implemented by time-based one-time password authentication
* configurations.
*/
interface TimeBasedOtpConfigurationInterface extends OtpConfigurationInterface
{
/**
* Get the number of seconds each token is valid for.
*
* @return integer The number of seconds each token is valid for.
*/
public function window();

/**
* Get the number of future windows to check.
*
* @return integer The number of future windows to check.
*/
public function futureWindows();

/**
* Get the number of past windows to check.
*
* @return integer The number of past windows to check.
*/
public function pastWindows();
}
2 changes: 1 addition & 1 deletion src/Eloquent/Otis/Credentials/MfaCredentialsInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // @codeCoverageIgnoreStart
<?php

/*
* This file is part of the Otis package.
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Otis/Credentials/OtpCredentialsInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // @codeCoverageIgnoreStart
<?php

/*
* This file is part of the Otis package.
Expand Down

0 comments on commit 4897f1a

Please sign in to comment.