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

Commit

Permalink
Implemented configuration classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Sep 12, 2013
1 parent d1b3a55 commit 4c04636
Show file tree
Hide file tree
Showing 11 changed files with 527 additions and 47 deletions.
99 changes: 52 additions & 47 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions src/Eloquent/Otis/Configuration/AbstractOtpConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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;

/**
* An abstract base class for implementing OTP configurations.
*/
abstract class AbstractOtpConfiguration implements OtpConfigurationInterface
{
/**
* Construct a new OTP 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.
*/
public function __construct(
$digits = null,
$secretLength = null,
HashAlgorithm $algorithm = null
) {
if (null === $digits) {
$digits = 6;
}
if (null === $secretLength) {
$secretLength = 10;
}
if (null === $algorithm) {
$algorithm = HashAlgorithm::SHA1();
}

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

/**
* Get the number of password digits.
*
* @return integer The number of digits.
*/
public function digits()
{
return $this->digits;
}

/**
* Get the length of the shared secret.
*
* @return integer The secret length.
*/
public function secretLength()
{
return $this->secretLength;
}

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

private $digits;
private $secretLength;
private $algorithm;
}
41 changes: 41 additions & 0 deletions src/Eloquent/Otis/Configuration/HashAlgorithm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\Enumeration\Enumeration;

/**
* The available hash algorithms.
*/
final class HashAlgorithm extends Enumeration
{
/**
* The SHA-1 hash algorithm.
*
* @link http://tools.ietf.org/html/rfc3174
*/
const SHA1 = 'sha1';

/**
* The SHA-256 hash algorithm.
*
* @link http://tools.ietf.org/html/rfc6234
*/
const SHA256 = 'sha256';

/**
* The SHA-512 hash algorithm.
*
* @link http://tools.ietf.org/html/rfc6234
*/
const SHA512 = 'sha512';
}
Loading

0 comments on commit 4c04636

Please sign in to comment.