Skip to content

Commit

Permalink
Add Timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kittinan committed Oct 5, 2014
1 parent 143ed98 commit a637b61
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/KS/CryptTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CryptTime {
private $KEY = '00000000000000000000000000000000';
private $SEPERATOR = 'XXXXX_XXXXX';

private $TimeOut = 86400;

function __construct() {

Expand Down Expand Up @@ -64,7 +65,20 @@ public function getKey() {
return $this->KEY;
}

public function encrypt($plainText, $timeout = 86400) {
public function setTimeOut($timeout) {
if (!empty($timeout) && is_numeric($timeout) == true) {
$this->TimeOut = $timeout;
}
}

public function getTimeOut() {
return $this->TimeOut;
}

public function encrypt($plainText, $timeout = null) {
if (empty($timeout)) {
$timeout = $this->TimeOut;
}
$endTime = time() + $timeout;
$str = rand(0x112, 0xDEADC0DE).$this->SEPERATOR.$endTime.$this->SEPERATOR.$plainText;
return $this->base64url_encode($this->_encryptAES128($this->IV, $this->KEY, $str));
Expand Down
7 changes: 7 additions & 0 deletions tests/CryptTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ public function testEncrypt() {
$this->assertEquals(false, $result);
}

public function testSetTimeOut() {
$timeout = 86400 * 30;
$this->Crypt->setTimeOut($timeout);
$result = $this->Crypt->getTimeOut();
$this->assertEquals($timeout, $result);
}

}

0 comments on commit a637b61

Please sign in to comment.