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

Commit

Permalink
Namespace reshuffle.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Sep 17, 2013
1 parent 615d2cc commit 4b4c9bb
Show file tree
Hide file tree
Showing 65 changed files with 619 additions and 512 deletions.
19 changes: 19 additions & 0 deletions src/Eloquent/Otis/Configuration/MfaConfigurationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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 used to identify multi-factor authentication configurations.
*/
interface MfaConfigurationInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Configuration\Exception;
namespace Eloquent\Otis\Exception;

use Exception;

Expand All @@ -30,7 +30,7 @@ public function __construct($digits, Exception $previous = null)

parent::__construct(
sprintf(
'Invalid OTP password length (%s).',
'Invalid password length (%s).',
var_export($digits, true)
),
0,
Expand Down
39 changes: 0 additions & 39 deletions src/Eloquent/Otis/Generator/TotpGeneratorInterface.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,31 @@
* file that was distributed with this source code.
*/

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

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

/**
* An abstract base class for implementing OTP configurations.
* An abstract base class for implementing one-time password authentication
* configurations based upon HOTP.
*/
abstract class AbstractOtpConfiguration implements OtpConfigurationInterface
abstract class AbstractHotpBasedOtpConfiguration implements
HotpBasedConfigurationInterface
{
/**
* Construct a new OTP configuration.
* 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 HashAlgorithm|null $algorithm The underlying algorithm to use.
* @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.
*
* @throws Exception\InvalidPasswordLengthException If the number of digits is invalid.
* @throws InvalidPasswordLengthException If the number of digits is invalid.
*/
public function __construct(
$digits = null,
$secretLength = null,
HashAlgorithm $algorithm = null
HotpHashAlgorithm $algorithm = null
) {
if (null === $digits) {
$digits = 6;
Expand All @@ -37,11 +42,11 @@ public function __construct(
$secretLength = 10;
}
if (null === $algorithm) {
$algorithm = HashAlgorithm::SHA1();
$algorithm = HotpHashAlgorithm::SHA1();
}

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

$this->digits = $digits;
Expand Down Expand Up @@ -72,7 +77,7 @@ public function secretLength()
/**
* Get the underlying algorithm name.
*
* @return HashAlgorithm The algorithm name.
* @return HotpHashAlgorithm The algorithm name.
*/
public function algorithm()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
* file that was distributed with this source code.
*/

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

use Eloquent\Otis\Configuration\MfaConfigurationInterface;
use Eloquent\Otis\Hotp\HotpHashAlgorithm;

/**
* The interface implemented by OTP configurations.
* The interface implemented by one-time password authentication configurations
* based upon HOTP.
*/
interface OtpConfigurationInterface
interface HotpBasedConfigurationInterface extends MfaConfigurationInterface
{
/**
* Get the number of password digits.
Expand All @@ -33,7 +37,7 @@ public function secretLength();
/**
* Get the underlying algorithm name.
*
* @return HashAlgorithm The algorithm name.
* @return HotpHashAlgorithm The algorithm name.
*/
public function algorithm();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,34 @@
* file that was distributed with this source code.
*/

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

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

/**
* Represents a complete set of HOTP configuration settings.
*/
class HotpConfiguration extends AbstractOtpConfiguration implements
class HotpConfiguration extends AbstractHotpBasedOtpConfiguration implements
HotpConfigurationInterface
{
/**
* Construct a new HOTP 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.
* @param HashAlgorithm|null $algorithm The underlying algorithm to use.
* @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.
* @param HotpHashAlgorithm|null $algorithm The underlying algorithm to use.
*
* @throws Exception\InvalidPasswordLengthException If the number of digits is invalid.
* @throws InvalidPasswordLengthException If the number of digits is invalid.
*/
public function __construct(
$digits = null,
$window = null,
$initialCounter = null,
$secretLength = null,
HashAlgorithm $algorithm = null
HotpHashAlgorithm $algorithm = null
) {
if (null === $window) {
$window = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/

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

/**
* The interface implemented by HOTP configurations.
*/
interface HotpConfigurationInterface extends OtpConfigurationInterface
interface HotpConfigurationInterface extends HotpBasedConfigurationInterface
{
/**
* Get the amount of counter increments to search through for a match.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Generator;
namespace Eloquent\Otis\Hotp\Generator;

use Eloquent\Otis\Configuration\HashAlgorithm;
use Eloquent\Otis\Hotp\HotpHashAlgorithm;

/**
* Generates HOTP values.
Expand All @@ -23,19 +23,19 @@ class HotpGenerator implements HotpGeneratorInterface
*
* @link http://tools.ietf.org/html/rfc4226#section-5.3
*
* @param string $secret The shared secret.
* @param integer $counter The counter value.
* @param HashAlgorithm|null $algorithm The hash algorithm to use.
* @param string $secret The shared secret.
* @param integer $counter The counter value.
* @param HotpHashAlgorithm|null $algorithm The hash algorithm to use.
*
* @return OtpValueInterface The generated HOTP value.
* @return HotpValueInterface The generated HOTP value.
*/
public function generate($secret, $counter, HashAlgorithm $algorithm = null)
public function generate($secret, $counter, HotpHashAlgorithm $algorithm = null)
{
if (null === $algorithm) {
$algorithm = HashAlgorithm::SHA1();
$algorithm = HotpHashAlgorithm::SHA1();
}

return new OtpValue(
return new HotpValue(
hash_hmac($algorithm->value(), $this->pack($counter), $secret, true)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Generator;
namespace Eloquent\Otis\Hotp\Generator;

use Eloquent\Otis\Configuration\HashAlgorithm;
use Eloquent\Otis\Hotp\HotpHashAlgorithm;
use Eloquent\Otis\Hotp\Value\HotpValueInterface;

/**
* The interface implemented by HOTP generators.
Expand All @@ -23,15 +24,15 @@ interface HotpGeneratorInterface
*
* @link http://tools.ietf.org/html/rfc4226#section-5.3
*
* @param string $secret The shared secret.
* @param integer $counter The counter value.
* @param HashAlgorithm|null $algorithm The hash algorithm to use.
* @param string $secret The shared secret.
* @param integer $counter The counter value.
* @param HotpHashAlgorithm|null $algorithm The hash algorithm to use.
*
* @return OtpValueInterface The generated HOTP value.
* @return HotpValueInterface The generated HOTP value.
*/
public function generate(
$secret,
$counter,
HashAlgorithm $algorithm = null
HotpHashAlgorithm $algorithm = null
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Generator;
namespace Eloquent\Otis\Hotp\Generator;

use Eloquent\Otis\Configuration\Exception\InvalidPasswordLengthException;
use Eloquent\Otis\Exception\InvalidPasswordLengthException;

/**
* Represents a generated OTP value.
* Represents a generated HOTP value.
*/
class OtpValue implements OtpValueInterface
class HotpValue implements HotpValueInterface
{
/**
* Construct a new OTP value.
* Construct a new HOTP value.
*
* @param string $value The raw value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
* file that was distributed with this source code.
*/

namespace Eloquent\Otis\Generator;
namespace Eloquent\Otis\Hotp\Generator;

use Eloquent\Otis\Configuration\Exception\InvalidPasswordLengthException;
use Eloquent\Otis\Exception\InvalidPasswordLengthException;

/**
* The interface implemented by generated OTP values.
*/
interface OtpValueInterface
interface HotpValueInterface
{
/**
* Get the raw value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
* file that was distributed with this source code.
*/

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

use Eloquent\Enumeration\Enumeration;

/**
* The available hash algorithms.
* The available HOTP hash algorithms.
*/
final class HashAlgorithm extends Enumeration
final class HotpHashAlgorithm extends Enumeration
{
/**
* The SHA-1 hash algorithm.
Expand Down
Loading

0 comments on commit 4b4c9bb

Please sign in to comment.