@@ -60,7 +60,7 @@ |
||
60 | 60 | * a state storage instance of a certain type. |
61 | 61 | * @param array $options An array of options for the state storage |
62 | 62 | */ |
63 | - public function __construct($options=array(), LoggerInterface $logger) |
|
63 | + public function __construct($options = array(), LoggerInterface $logger) |
|
64 | 64 | { |
65 | 65 | $this->logger = $logger; |
66 | 66 | $this->_options = $options; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | private function getUserSecret($userId) |
83 | 83 | { |
84 | 84 | $sth = $this->handle->prepare("SELECT secret FROM ".$this->tableName." WHERE userid = ?"); |
85 | - if($sth->execute(array($userId))) { |
|
85 | + if ($sth->execute(array($userId))) { |
|
86 | 86 | $secret = $sth->fetchColumn(); |
87 | 87 | if ($secret !== false) { |
88 | 88 | return $secret; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } else { |
105 | 105 | $sth = $this->handle->prepare("INSERT INTO ".$this->tableName." (secret,userid) VALUES (?,?)"); |
106 | 106 | } |
107 | - $result = $sth->execute(array($secret,$userId)); |
|
107 | + $result = $sth->execute(array($secret, $userId)); |
|
108 | 108 | if (!$result) { |
109 | 109 | throw new ReadWriteException('Unable to persist user secret in user secret storage (PDO)'); |
110 | 110 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | parent::__construct($config, $logger); |
47 | 47 | $this->tablename = isset($config['table']) ? $config['table'] : 'tiqruser'; |
48 | 48 | try { |
49 | - $this->handle = new PDO($config['dsn'],$config['username'],$config['password']); |
|
49 | + $this->handle = new PDO($config['dsn'], $config['username'], $config['password']); |
|
50 | 50 | } catch (PDOException $e) { |
51 | 51 | $this->logger->error( |
52 | 52 | sprintf('Unable to establish a PDO connection. Error message from PDO: %s', $e->getMessage()) |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | } else { |
62 | 62 | $sth = $this->handle->prepare("INSERT INTO ".$this->tablename." (displayname,userid) VALUES (?,?)"); |
63 | 63 | } |
64 | - if ($sth->execute(array($displayName,$userId))){ |
|
64 | + if ($sth->execute(array($displayName, $userId))) { |
|
65 | 65 | return $this->userExists($userId); |
66 | 66 | } |
67 | 67 | throw new ReadWriteException('The user could not be saved in the user storage (PDO)'); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | public function setNotificationType($userId, $type) |
107 | 107 | { |
108 | 108 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET notificationtype = ? WHERE userid = ?"); |
109 | - if (!$sth->execute(array($type,$userId))) { |
|
109 | + if (!$sth->execute(array($type, $userId))) { |
|
110 | 110 | throw new ReadWriteException('Unable to set the notification type in user storage for a given user (PDO)'); |
111 | 111 | } |
112 | 112 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | public function setNotificationAddress($userId, $address) |
124 | 124 | { |
125 | 125 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET notificationaddress = ? WHERE userid = ?"); |
126 | - if (!$sth->execute(array($address,$userId))) { |
|
126 | + if (!$sth->execute(array($address, $userId))) { |
|
127 | 127 | throw new ReadWriteException('Unable to set the notification address in user storage for a given user (PDO)'); |
128 | 128 | |
129 | 129 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | public function setLoginAttempts($userId, $amount) |
142 | 142 | { |
143 | 143 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET loginattempts = ? WHERE userid = ?"); |
144 | - if (!$sth->execute(array($amount,$userId))) { |
|
144 | + if (!$sth->execute(array($amount, $userId))) { |
|
145 | 145 | throw new ReadWriteException('Unable to set login attempts in user storage for a given user (PDO)'); |
146 | 146 | } |
147 | 147 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | public function setTemporaryBlockAttempts($userId, $amount) { |
176 | 176 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET tmpblockattempts = ? WHERE userid = ?"); |
177 | - if (!$sth->execute(array($amount,$userId))) { |
|
177 | + if (!$sth->execute(array($amount, $userId))) { |
|
178 | 178 | throw new ReadWriteException('Unable to set temp login attempts in user storage for a given user (PDO)'); |
179 | 179 | } |
180 | 180 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | public function setTemporaryBlockTimestamp($userId, $timestamp) |
200 | 200 | { |
201 | 201 | $sth = $this->handle->prepare("UPDATE ".$this->tablename." SET tmpblocktimestamp = ? WHERE userid = ?"); |
202 | - if (!$sth->execute(array($timestamp,$userId))) { |
|
202 | + if (!$sth->execute(array($timestamp, $userId))) { |
|
203 | 203 | throw new ReadWriteException('Unable to update temp lock timestamp in user storage for a given user (PDO)'); |
204 | 204 | } |
205 | 205 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param int $expire The expiration (in seconds) of the data |
25 | 25 | * @throws ReadWriteException |
26 | 26 | */ |
27 | - public function setValue($key, $value, $expire=0); |
|
27 | + public function setValue($key, $value, $expire = 0); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Remove a value from the state storage |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $this->path = $path; |
45 | 45 | } |
46 | 46 | |
47 | - public function setValue($key, $value, $expire=0) |
|
47 | + public function setValue($key, $value, $expire = 0) |
|
48 | 48 | { |
49 | 49 | $envelope = array("expire"=>$expire, |
50 | 50 | "createdAt"=>time(), |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | |
99 | 99 | private function getPath(): string |
100 | 100 | { |
101 | - if (substr($this->path, -1)!=="/") { |
|
102 | - return $this->path . "/"; |
|
101 | + if (substr($this->path, -1) !== "/") { |
|
102 | + return $this->path."/"; |
|
103 | 103 | } |
104 | 104 | return $this->path; |
105 | 105 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | private function cleanExpired() { |
75 | 75 | $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0"); |
76 | 76 | $result = $sth->execute(array(time())); |
77 | - if (!$result || $sth->rowCount() === 0){ |
|
77 | + if (!$result || $sth->rowCount() === 0) { |
|
78 | 78 | // No exception is thrown here. The application can continue with expired state for now. |
79 | 79 | $this->logger->error('Unable to remove expired keys from the pdo state storage'); |
80 | 80 | } |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * (non-PHPdoc) |
85 | 85 | * @see library/tiqr/Tiqr/StateStorage/Tiqr_StateStorage_Abstract::setValue() |
86 | 86 | */ |
87 | - public function setValue($key, $value, $expire=0) |
|
87 | + public function setValue($key, $value, $expire = 0) |
|
88 | 88 | { |
89 | - if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) { |
|
89 | + if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) { |
|
90 | 90 | $this->cleanExpired(); |
91 | 91 | } |
92 | 92 | if ($this->keyExists($key)) { |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | } |
97 | 97 | // $expire == 0 means never expire |
98 | 98 | if ($expire != 0) { |
99 | - $expire+=time(); // Store unix timestamp after which the expires |
|
99 | + $expire += time(); // Store unix timestamp after which the expires |
|
100 | 100 | } |
101 | - if (!$sth->execute(array(serialize($value),$expire,$key))) { |
|
101 | + if (!$sth->execute(array(serialize($value), $expire, $key))) { |
|
102 | 102 | throw new ReadWriteException(sprintf('Unable to store "%s" state to the PDO', $key)); |
103 | 103 | } |
104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | public function unsetValue($key) |
111 | 111 | { |
112 | 112 | if ($this->keyExists($key)) { |
113 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
|
113 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `key` = ?"); |
|
114 | 114 | $result = $sth->execute(array($key)); |
115 | 115 | if (!$result || $sth->rowCount() === 0) { |
116 | 116 | throw new ReadWriteException( |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $this->logger->error('Unable to prepare the get key statement'); |
138 | 138 | return NULL; |
139 | 139 | } |
140 | - if (false === $sth->execute(array($key, time())) ) { |
|
140 | + if (false === $sth->execute(array($key, time()))) { |
|
141 | 141 | $this->logger->error('Unable to get key from the pdo state storage'); |
142 | 142 | return NULL; |
143 | 143 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | public static function autoload($className) { |
26 | - if($className === NULL) { |
|
26 | + if ($className === NULL) { |
|
27 | 27 | return; |
28 | 28 | } |
29 | 29 | |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | $substr5 = substr($className, 0, 5); |
33 | 33 | |
34 | 34 | if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') { |
35 | - $file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
35 | + $file = $self->tiqrPath.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php'; |
|
36 | 36 | } elseif ($className === 'QRcode') { |
37 | - $file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php'; |
|
37 | + $file = $self->qrcodePath.DIRECTORY_SEPARATOR.'qrlib.php'; |
|
38 | 38 | } elseif ($substr5 === 'Zend_') { |
39 | - $file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
39 | + $file = $self->zendPath.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php'; |
|
40 | 40 | } elseif ($className === 'ReadWriteException') { |
41 | - $file = $self->tiqrPath . DIRECTORY_SEPARATOR . 'Tiqr/Exception/ReadWriteException.php'; |
|
41 | + $file = $self->tiqrPath.DIRECTORY_SEPARATOR.'Tiqr/Exception/ReadWriteException.php'; |
|
42 | 42 | } else { |
43 | 43 | return; |
44 | 44 | } |
@@ -59,34 +59,34 @@ discard block |
||
59 | 59 | if (is_dir($tiqr_path)) { |
60 | 60 | $this->tiqrPath = $tiqr_path; |
61 | 61 | } else { |
62 | - throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE)); |
|
62 | + throw new Exception('Directory not found: '.var_export($tiqr_dir, TRUE)); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | if (isset($options["phpqrcode.path"])) { |
66 | 66 | $qrcode_dir = $options["phpqrcode.path"]; |
67 | 67 | $qrcode_path = realpath($qrcode_dir); |
68 | 68 | } else { |
69 | - $qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode'; |
|
69 | + $qrcode_dir = dirname(dirname(dirname(__FILE__))).'/phpqrcode'; |
|
70 | 70 | $qrcode_path = $qrcode_dir; |
71 | 71 | } |
72 | 72 | |
73 | 73 | if (is_dir($qrcode_path)) { |
74 | 74 | $this->qrcodePath = $qrcode_path; |
75 | 75 | } else { |
76 | - throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE)); |
|
76 | + throw new Exception('Directory not found: '.var_export($qrcode_dir, TRUE)); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | if (isset($options["zend.path"])) { |
80 | 80 | $zend_dir = $options["zend.path"]; |
81 | 81 | $zend_path = realpath($zend_dir); |
82 | 82 | } else { |
83 | - $zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend"; |
|
83 | + $zend_dir = dirname(dirname(dirname(__FILE__)))."/zend"; |
|
84 | 84 | $zend_path = $zend_dir; |
85 | 85 | } |
86 | 86 | if (is_dir($zend_path)) { |
87 | 87 | $this->zendPath = $zend_path; |
88 | 88 | } else { |
89 | - throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE)); |
|
89 | + throw new Exception('Directory not found: '.var_export($zend_dir, TRUE)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 |
@@ -58,18 +58,18 @@ discard block |
||
58 | 58 | private static function _hexStr2Bytes(string $hex, int $maxBytes, string $parameterName) : string |
59 | 59 | { |
60 | 60 | $len = strlen($hex); |
61 | - if ( ($len !== 0) && (! ctype_xdigit($hex)) ) { |
|
61 | + if (($len !== 0) && (!ctype_xdigit($hex))) { |
|
62 | 62 | throw new InvalidArgumentException("Parameter '$parameterName' contains non hex digits"); |
63 | 63 | } |
64 | - if ( $len % 2 !== 0 ) { |
|
64 | + if ($len % 2 !== 0) { |
|
65 | 65 | throw new InvalidArgumentException("Parameter '$parameterName' contains odd number of hex digits"); |
66 | 66 | } |
67 | - if ( $len > $maxBytes * 2) { |
|
67 | + if ($len > $maxBytes * 2) { |
|
68 | 68 | throw new InvalidArgumentException("Parameter '$parameterName' too long"); |
69 | 69 | } |
70 | 70 | // hex2bin logs PHP warnings when $hex contains invalid characters or has uneven length. Because we |
71 | 71 | // check for these conditions above hex2bin() should always be silent |
72 | - $res=hex2bin($hex); |
|
72 | + $res = hex2bin($hex); |
|
73 | 73 | if (false === $res) { |
74 | 74 | throw new InvalidArgumentException("Parameter '$parameterName' could not be decoded"); |
75 | 75 | } |
@@ -122,72 +122,72 @@ discard block |
||
122 | 122 | $cryptoFunction = $components[1]; |
123 | 123 | $dataInput = strtolower($components[2]); // lower here so we can do case insensitive comparisons |
124 | 124 | |
125 | - if(stripos($cryptoFunction, "sha1")!==false) |
|
125 | + if (stripos($cryptoFunction, "sha1") !== false) |
|
126 | 126 | $crypto = "sha1"; |
127 | - if(stripos($cryptoFunction, "sha256")!==false) |
|
127 | + if (stripos($cryptoFunction, "sha256") !== false) |
|
128 | 128 | $crypto = "sha256"; |
129 | - if(stripos($cryptoFunction, "sha512")!==false) |
|
129 | + if (stripos($cryptoFunction, "sha512") !== false) |
|
130 | 130 | $crypto = "sha512"; |
131 | 131 | |
132 | - $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1); |
|
132 | + $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-") + 1); |
|
133 | 133 | |
134 | 134 | // The size of the byte array message to be encrypted |
135 | 135 | // Counter |
136 | - if($dataInput[0] == "c" ) { |
|
136 | + if ($dataInput[0] == "c") { |
|
137 | 137 | // Fix the length of the HEX string |
138 | - while(strlen($counter) < 16) |
|
139 | - $counter = "0" . $counter; |
|
140 | - $counterLength=8; |
|
138 | + while (strlen($counter) < 16) |
|
139 | + $counter = "0".$counter; |
|
140 | + $counterLength = 8; |
|
141 | 141 | } |
142 | 142 | // Question |
143 | - if($dataInput[0] == "q" || |
|
144 | - stripos($dataInput, "-q")!==false) { |
|
145 | - while(strlen($question) < 256) |
|
146 | - $question = $question . "0"; |
|
147 | - $questionLength=128; |
|
143 | + if ($dataInput[0] == "q" || |
|
144 | + stripos($dataInput, "-q") !== false) { |
|
145 | + while (strlen($question) < 256) |
|
146 | + $question = $question."0"; |
|
147 | + $questionLength = 128; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | // Password |
151 | - if(stripos($dataInput, "psha1")!==false) { |
|
152 | - while(strlen($password) < 40) |
|
153 | - $password = "0" . $password; |
|
154 | - $passwordLength=20; |
|
151 | + if (stripos($dataInput, "psha1") !== false) { |
|
152 | + while (strlen($password) < 40) |
|
153 | + $password = "0".$password; |
|
154 | + $passwordLength = 20; |
|
155 | 155 | } |
156 | 156 | |
157 | - if(stripos($dataInput, "psha256")!==false) { |
|
158 | - while(strlen($password) < 64) |
|
159 | - $password = "0" . $password; |
|
160 | - $passwordLength=32; |
|
157 | + if (stripos($dataInput, "psha256") !== false) { |
|
158 | + while (strlen($password) < 64) |
|
159 | + $password = "0".$password; |
|
160 | + $passwordLength = 32; |
|
161 | 161 | } |
162 | 162 | |
163 | - if(stripos($dataInput, "psha512")!==false) { |
|
164 | - while(strlen($password) < 128) |
|
165 | - $password = "0" . $password; |
|
166 | - $passwordLength=64; |
|
163 | + if (stripos($dataInput, "psha512") !== false) { |
|
164 | + while (strlen($password) < 128) |
|
165 | + $password = "0".$password; |
|
166 | + $passwordLength = 64; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // sessionInformation |
170 | - if(stripos($dataInput, "s064") !==false) { |
|
171 | - while(strlen($sessionInformation) < 128) |
|
172 | - $sessionInformation = "0" . $sessionInformation; |
|
170 | + if (stripos($dataInput, "s064") !== false) { |
|
171 | + while (strlen($sessionInformation) < 128) |
|
172 | + $sessionInformation = "0".$sessionInformation; |
|
173 | 173 | |
174 | - $sessionInformationLength=64; |
|
175 | - } else if(stripos($dataInput, "s128") !==false) { |
|
176 | - while(strlen($sessionInformation) < 256) |
|
177 | - $sessionInformation = "0" . $sessionInformation; |
|
174 | + $sessionInformationLength = 64; |
|
175 | + } else if (stripos($dataInput, "s128") !== false) { |
|
176 | + while (strlen($sessionInformation) < 256) |
|
177 | + $sessionInformation = "0".$sessionInformation; |
|
178 | 178 | |
179 | - $sessionInformationLength=128; |
|
180 | - } else if(stripos($dataInput, "s256") !==false) { |
|
181 | - while(strlen($sessionInformation) < 512) |
|
182 | - $sessionInformation = "0" . $sessionInformation; |
|
179 | + $sessionInformationLength = 128; |
|
180 | + } else if (stripos($dataInput, "s256") !== false) { |
|
181 | + while (strlen($sessionInformation) < 512) |
|
182 | + $sessionInformation = "0".$sessionInformation; |
|
183 | 183 | |
184 | - $sessionInformationLength=256; |
|
185 | - } else if(stripos($dataInput, "s512") !==false) { |
|
186 | - while(strlen($sessionInformation) < 128) |
|
187 | - $sessionInformation = "0" . $sessionInformation; |
|
184 | + $sessionInformationLength = 256; |
|
185 | + } else if (stripos($dataInput, "s512") !== false) { |
|
186 | + while (strlen($sessionInformation) < 128) |
|
187 | + $sessionInformation = "0".$sessionInformation; |
|
188 | 188 | |
189 | - $sessionInformationLength=64; |
|
190 | - } else if (stripos($dataInput, "-s") !== false ) { |
|
189 | + $sessionInformationLength = 64; |
|
190 | + } else if (stripos($dataInput, "-s") !== false) { |
|
191 | 191 | // deviation from spec. Officially 's' without a length indicator is not in the reference implementation. |
192 | 192 | // RFC is ambigious. However we have supported this in Tiqr since day 1, so we continue to support it. |
193 | 193 | |
@@ -196,27 +196,27 @@ discard block |
||
196 | 196 | // to prevent matching the "s" in the password input e.g. "psha1". |
197 | 197 | // [C] | QFxx | [PH | Snnn | TG] : Challenge-Response computation |
198 | 198 | // [C] | QFxx | [PH | TG] : Plain Signature computation |
199 | - while(strlen($sessionInformation) < 128) |
|
200 | - $sessionInformation = "0" . $sessionInformation; |
|
199 | + while (strlen($sessionInformation) < 128) |
|
200 | + $sessionInformation = "0".$sessionInformation; |
|
201 | 201 | |
202 | - $sessionInformationLength=64; |
|
202 | + $sessionInformationLength = 64; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
206 | 206 | |
207 | 207 | // TimeStamp |
208 | - if($dataInput[0] == "t" || |
|
208 | + if ($dataInput[0] == "t" || |
|
209 | 209 | stripos($dataInput, "-t") !== false) { |
210 | - while(strlen($timeStamp) < 16) |
|
211 | - $timeStamp = "0" . $timeStamp; |
|
212 | - $timeStampLength=8; |
|
210 | + while (strlen($timeStamp) < 16) |
|
211 | + $timeStamp = "0".$timeStamp; |
|
212 | + $timeStampLength = 8; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | // Put the bytes of "ocraSuite" parameters into the message |
216 | 216 | |
217 | - $msg = array_fill(0,$ocraSuiteLength+$counterLength+$questionLength+$passwordLength+$sessionInformationLength+$timeStampLength+1, 0); |
|
217 | + $msg = array_fill(0, $ocraSuiteLength + $counterLength + $questionLength + $passwordLength + $sessionInformationLength + $timeStampLength + 1, 0); |
|
218 | 218 | |
219 | - for($i=0;$i<strlen($ocraSuite);$i++) { |
|
219 | + for ($i = 0; $i < strlen($ocraSuite); $i++) { |
|
220 | 220 | $msg[$i] = $ocraSuite[$i]; |
221 | 221 | } |
222 | 222 | |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | |
226 | 226 | // Put the bytes of "Counter" to the message |
227 | 227 | // Input is HEX encoded |
228 | - if($counterLength > 0 ) { |
|
228 | + if ($counterLength > 0) { |
|
229 | 229 | $bArray = self::_hexStr2Bytes($counter, $counterLength, 'counter'); |
230 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
230 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
231 | 231 | $msg [$i + $ocraSuiteLength + 1] = $bArray[$i]; |
232 | 232 | } |
233 | 233 | } |
@@ -235,41 +235,41 @@ discard block |
||
235 | 235 | |
236 | 236 | // Put the bytes of "question" to the message |
237 | 237 | // Input is text encoded |
238 | - if($questionLength > 0 ) { |
|
238 | + if ($questionLength > 0) { |
|
239 | 239 | $bArray = self::_hexStr2Bytes($question, $questionLength, 'question'); |
240 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
240 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
241 | 241 | $msg [$i + $ocraSuiteLength + 1 + $counterLength] = $bArray[$i]; |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | 245 | // Put the bytes of "password" to the message |
246 | 246 | // Input is HEX encoded |
247 | - if($passwordLength > 0){ |
|
247 | + if ($passwordLength > 0) { |
|
248 | 248 | $bArray = self::_hexStr2Bytes($password, $passwordLength, 'password'); |
249 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
249 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
250 | 250 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength] = $bArray[$i]; |
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
254 | 254 | // Put the bytes of "sessionInformation" to the message |
255 | 255 | // Input is HEX encoded |
256 | - if($sessionInformationLength > 0 ){ |
|
256 | + if ($sessionInformationLength > 0) { |
|
257 | 257 | $bArray = self::_hexStr2Bytes($sessionInformation, $sessionInformationLength, 'sessionInformation'); |
258 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
258 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
259 | 259 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength] = $bArray[$i]; |
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | 263 | // Put the bytes of "time" to the message |
264 | 264 | // Input is HEX encoded value of minutes |
265 | - if($timeStampLength > 0){ |
|
265 | + if ($timeStampLength > 0) { |
|
266 | 266 | $bArray = self::_hexStr2Bytes($timeStamp, $timeStampLength, 'timeStamp'); |
267 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
267 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
268 | 268 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength + $sessionInformationLength] = $bArray[$i]; |
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
272 | - $byteKey = self::_hexStr2Bytes($key, strlen($key)/2, 'key'); |
|
272 | + $byteKey = self::_hexStr2Bytes($key, strlen($key) / 2, 'key'); |
|
273 | 273 | |
274 | 274 | $msg = implode("", $msg); |
275 | 275 | |
@@ -291,23 +291,23 @@ discard block |
||
291 | 291 | static function _oath_truncate(string $hash, int $length = 6) : string |
292 | 292 | { |
293 | 293 | // Convert to dec |
294 | - foreach(str_split($hash,2) as $hex) |
|
294 | + foreach (str_split($hash, 2) as $hex) |
|
295 | 295 | { |
296 | - $hmac_result[]=hexdec($hex); |
|
296 | + $hmac_result[] = hexdec($hex); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | // Find offset |
300 | 300 | $offset = $hmac_result[count($hmac_result) - 1] & 0xf; |
301 | 301 | |
302 | 302 | $v = strval( |
303 | - (($hmac_result[$offset+0] & 0x7f) << 24 ) | |
|
304 | - (($hmac_result[$offset+1] & 0xff) << 16 ) | |
|
305 | - (($hmac_result[$offset+2] & 0xff) << 8 ) | |
|
306 | - ($hmac_result[$offset+3] & 0xff) |
|
303 | + (($hmac_result[$offset + 0] & 0x7f) << 24) | |
|
304 | + (($hmac_result[$offset + 1] & 0xff) << 16) | |
|
305 | + (($hmac_result[$offset + 2] & 0xff) << 8) | |
|
306 | + ($hmac_result[$offset + 3] & 0xff) |
|
307 | 307 | ); |
308 | 308 | |
309 | 309 | // Prefix truncated string with 0's to ensure it always has the required length |
310 | - $v=str_pad($v, $length, "0", STR_PAD_LEFT); |
|
310 | + $v = str_pad($v, $length, "0", STR_PAD_LEFT); |
|
311 | 311 | |
312 | 312 | $v = substr($v, strlen($v) - $length); |
313 | 313 | return $v; |