Permalink
Browse files

Intermediate commit

  • Loading branch information...
1 parent a962d70 commit 81f083274f68636a1e763500348989eddaebcebf @tothimre committed Jan 8, 2014
View
@@ -1,4 +1,12 @@
-# Info Token
+<pre>
+ ### #######
+ # # # ###### #### # #### # # ###### # #
+ # ## # # # # # # # # # # ## #
+ # # # # ##### # # # # # #### ##### # # #
+ # # # # # # # # # # # # # # # #
+ # # ## # # # # # # # # # # ##
+ ### # # # #### # #### # # ###### # #
+</pre>
[![Build Status](https://travis-ci.org/tothimre/hashids_timestamp_salt.png?branch=master)](https://travis-ci.org/flyingwhale/poc)
@@ -0,0 +1,48 @@
+<?php
+namespace InfoToken\HashJugglers;
+
+use Hashids\Hashids;
+use InfoToken\Hashers\CheckerInterface;
+use InfoToken\Hashers\HasherContainersInterface;
+use InfoToken\Hashers\Hashids\Hasher\HashidsCrypter;
+
+class Checker implements CheckerInterface
+{
+ public static function check(HasherContainersInterface $hashIdContainers, $stringToCheck)
+ {
+ $hashIds = $hashIdContainers->getHashers();
+ /** @var Hashids $hashId */
+ foreach ($hashIds as $hashId){
+ $hash = $hashId->decrypt($stringToCheck);
+ $broken = self::hashSpecificCheck($hash);
+ if($broken){
+ continue;
+ }
+ if(!empty($hash)){
+ return $hash;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return array
+ */
+ public static function hashSpecificCheck(&$value)
+ {
+ $broken = false;
+ $checkerArray = HashidsCrypter::getCheckerArray();
+ $hashCount = count($checkerArray);
+
+ for ($i = 1; $i <= $hashCount; $i++) {
+ if (array_shift($value) != array_shift($checkerArray)) {
+ $broken = true;
+ break;
+ }
+ else{
+ }
+ }
+ return $broken;
+ }
+
+}
@@ -12,35 +12,39 @@ class HashsidsFactory
const ACTUAL_INTERVAL_START_INDEX = 0;
const PREVIOUS_INTERVAL_START_INDEX = 1;
- public static function getDecryptHashids(HasherConstructorValues $hashidConstructorValues, TimeInterval $timeinterval)
+ public function getDecryptHashers(HasherConstructorValues $hashidConstructorValues, TimeInterval $timeinterval)
{
return array(
- self::getHashid($hashidConstructorValues, $timeinterval->getIntervalStartTime()),
- self::getHashid($hashidConstructorValues, $timeinterval->getPreviousIntervalStartTime()),
+ $this->getHashid($hashidConstructorValues, $timeinterval->getIntervalStartTime()),
+ $this->getHashid($hashidConstructorValues, $timeinterval->getPreviousIntervalStartTime()),
);
}
/**
- * @param HasherConstructorValues $hashidConstructorValues
+ * @param HasherConstructorValues $hasherConstructorValues
* @param TimeInterval $timeinterval
* @return CrypterInterface HashidsCrypter
*/
- public static function getEncryptHashids(HasherConstructorValues $hashidConstructorValues, TimeInterval $timeinterval)
+ public function getEncryptHasher(HasherConstructorValues $hasherConstructorValues, TimeInterval $timeinterval)
{
- $hashid = self::getHashid($hashidConstructorValues, $timeinterval->getIntervalStartTime());
-
-
+// $hashid = $this->getHashid($hasherConstructorValues, $timeinterval->getIntervalStartTime());
$crypter = new HashidsCrypter();
- $crypter->setCrypter($hashid);
- $crypter->setSalt($hashidConstructorValues->getSalt().$timeinterval->getIntervalStartTime());
+ $crypter->setCrypter($hasherConstructorValues);
+ $crypter->setSalt($hasherConstructorValues->getSalt().$timeinterval->getIntervalStartTime());
return $crypter;
}
- protected static function getHashid(HasherConstructorValues $hashidConstructorValues, $timestamp)
+ /**
+ * @param HasherConstructorValues $hashidConstructorValues
+ * @param $timestamp
+ * @return Hashids
+ */
+ protected function getHashid(HasherConstructorValues $hashidConstructorValues, $timestamp)
{
return new Hashids($hashidConstructorValues->getSalt().$timestamp,
- $hashidConstructorValues->getMinHashLength(), $hashidConstructorValues->getAlphabet());
+ $hashidConstructorValues->getMinHashLength(),
+ $hashidConstructorValues->getAlphabet());
}
}
@@ -0,0 +1,10 @@
+<?php
+
+namespace InfoToken\Hashers\Hashids;
+
+
+class HahsidsAdaptor
+{
+ protected $salt;
+
+}
@@ -1,38 +0,0 @@
-<?php
-namespace InfoToken\Hashers\Hashids\HashJugglers;
-
-use Hashids\Hashids;
-use InfoToken\Hashers\CheckerInterface;
-use InfoToken\Hashers\HasherContainersInterface;
-
-class Checker implements CheckerInterface
-{
- public static function check(HasherContainersInterface $hashIdContainers, $stringToCheck)
- {
- $hashIds = $hashIdContainers->getHashers();
- /** @var Hashids $hashId */
- $hash = array();
- foreach ($hashIds as $hashId){
- $hash = $hashId->decrypt($stringToCheck);
- $checkerArray = Creator::getCheckerArray();
- $hashCount = count($checkerArray);
- $broken = false;
- for($i=1;$i<=$hashCount;$i++)
- {
- if(array_shift($hash) != array_shift($checkerArray)){
- $broken = true;
- break;
- }
- }
- if($broken){
- continue;
- }
- if(!empty($hash)){
- return $hash;
- }
- }
- return $hash;
-
- }
-
-}
@@ -1,18 +0,0 @@
-<?php
-namespace InfoToken\Hashers\Hashids\HashJugglers;
-
-use InfoToken\Hashers\HasherInterface;
-
-class Creator
-{
- public static function getCheckerArray(){
- return array(
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,5
- );
- }
-}
@@ -4,20 +4,17 @@
use Hashids\Hashids;
use InfoToken\Hashers\CrypterInterface;
-use InfoToken\Hashers\Hashids\HashJugglers\Creator;
+use InfoToken\HashJugglers\Creator;
class HashidsCrypter implements CrypterInterface
{
- protected $salt;
+ private $salt;
- /**
- * @var Hashids
- */
- protected $crypter;
+ private $hashidsConstructorValues;
- public function setCrypter($crypter = null)
+ public function setCrypter($hashidsConstructorValues = null)
{
- $this->crypter = $crypter;
+ $this->hashidsConstructorValues = $hashidsConstructorValues;
}
/**
@@ -43,8 +40,8 @@ public function getSalt()
*/
public function encrypt($data)
{
-// public static function create(HasherInterface $hashId, $numbersArray)
- $hash = call_user_func_array(array($this->crypter, 'encrypt' ),array_merge(Creator::getCheckerArray(), $data));
+ $hashid = $this->getHashid();
+ $hash = call_user_func_array(array($hashid, 'encrypt' ),array_merge(self::getCheckerArray(), $data));
return $hash;
return $this->crypter->encrypt($string);
}
@@ -59,5 +56,22 @@ public function decrypt($string)
}
+ private function getHashid()
+ {
+ return new Hashids($this->salt,
+ $this->hashidsConstructorValues->getMinHashLength(),
+ $this->hashidsConstructorValues->getAlphabet());
+ }
+
+ public static function getCheckerArray(){
+ return array(
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,5
+ );
+ }
}
Oops, something went wrong.

0 comments on commit 81f0832

Please sign in to comment.