--- /dev/null
+<?php
+/**
+ * Generates nonces.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Nonce
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Nonce
+ */
+
+/**
+ * Generates nonces.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Nonce
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Nonce
+ */
+class Horde_Nonce_Filter
+{
+ private $_filter = array();
+
+ public function isUsed($counter, $hashes)
+ {
+ $unused_checks = 0;
+ foreach ($hashes as $hash) {
+ if (!isset($this->_filter[$hash]) || $counter > $this->_filter[$hash]) {
+ $unused_checks++;
+ }
+ }
+ foreach ($hashes as $hash) {
+ if (!isset($this->_filter[$hash]) || $counter > $this->_filter[$hash]) {
+ $this->_filter[$hash] = $counter;
+ }
+ }
+ if ($unused_checks > 0) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+}
\ No newline at end of file
case 'the default nonce generator':
$world['nonce_generator'] = new Horde_Nonce_Generator();
break;
+ case 'the default filter setup':
+ $world['nonce_filter'] = new Horde_Nonce_Filter();
+ break;
+ case 'the following counter and hash values are marked':
+ $world['nonce_filter']->isUsed(array_shift($arguments), $arguments);
+ break;
default:
return $this->notImplemented($action);
}
list($timestamp, $random) = $world['nonce_generator']->split($arguments[0]);
$world['hashes'] = $world['nonce_hash']->hash($random);
break;
+ case 'testing whether a nonce is unused if it has the following counter and hash values':
+ $world['used'] = $world['nonce_filter']->isUsed(array_shift($arguments), $arguments);
+ break;
default:
return $this->notImplemented($action);
}
$arguments
);
break;
+ case 'the nonce is unused':
+ $this->assertFalse($world['used']);
+ break;
+ case 'the nonce is used':
+ $this->assertTrue($world['used']);
+ break;
default:
return $this->notImplemented($action);
}