Passed
Pull Request — develop (#41)
by Pieter van der
03:08
created
library/tiqr/Tiqr/StateStorage/Abstract.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/AutoLoader.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -1,102 +1,102 @@
 block discarded – undo
1 1
 <?php
2 2
 class Tiqr_AutoLoader {
3 3
 
4
-	protected static $instance;
5
-
6
-	protected $tiqrPath;
7
-	protected $qrcodePath;
8
-	protected $zendPath;
9
-
10
-	protected function __construct($options) {
11
-		if ($options !== NULL) {
12
-			$this->setOptions($options);
13
-		}
14
-		spl_autoload_register(array(__CLASS__, 'autoload'));
15
-	}
16
-
17
-	public static function getInstance($options = NULL) {
18
-		if (null === self::$instance) {
19
-			self::$instance = new self($options);
20
-		}
21
-
22
-		return self::$instance;
23
-	}
24
-
25
-	public static function autoload($className) {
26
-		if($className === NULL) {
27
-			return;
28
-		}
29
-
30
-		$self = self::getInstance();
31
-
32
-		$substr5 = substr($className, 0, 5);
33
-
34
-		if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') {
35
-			$file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
36
-		} elseif ($className === 'QRcode') {
37
-			$file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php';
38
-		} elseif ($substr5 === 'Zend_') {
39
-			$file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
4
+    protected static $instance;
5
+
6
+    protected $tiqrPath;
7
+    protected $qrcodePath;
8
+    protected $zendPath;
9
+
10
+    protected function __construct($options) {
11
+        if ($options !== NULL) {
12
+            $this->setOptions($options);
13
+        }
14
+        spl_autoload_register(array(__CLASS__, 'autoload'));
15
+    }
16
+
17
+    public static function getInstance($options = NULL) {
18
+        if (null === self::$instance) {
19
+            self::$instance = new self($options);
20
+        }
21
+
22
+        return self::$instance;
23
+    }
24
+
25
+    public static function autoload($className) {
26
+        if($className === NULL) {
27
+            return;
28
+        }
29
+
30
+        $self = self::getInstance();
31
+
32
+        $substr5 = substr($className, 0, 5);
33
+
34
+        if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') {
35
+            $file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
36
+        } elseif ($className === 'QRcode') {
37
+            $file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php';
38
+        } elseif ($substr5 === 'Zend_') {
39
+            $file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
40 40
         } elseif ($className === 'ReadWriteException') {
41 41
             $file = $self->tiqrPath . DIRECTORY_SEPARATOR . 'Tiqr/Exception/ReadWriteException.php';
42
-		} else {
43
-			return;
44
-		}
45
-
46
-		if (file_exists($file)) {
47
-			require_once($file);
48
-		}
49
-	}
50
-
51
-	public function setOptions($options) {
52
-		if (isset($options["tiqr.path"])) {
53
-			$tiqr_dir = $options["tiqr.path"];
54
-			$tiqr_path = realpath($tiqr_dir);
55
-		} else {
56
-			$tiqr_dir = dirname(__FILE__);
57
-			$tiqr_path = $tiqr_dir;
58
-		}
59
-		if (is_dir($tiqr_path)) {
60
-			$this->tiqrPath = $tiqr_path;
61
-		} else {
62
-			throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE));
63
-		}
64
-
65
-		if (isset($options["phpqrcode.path"])) {
66
-			$qrcode_dir = $options["phpqrcode.path"];
67
-			$qrcode_path = realpath($qrcode_dir);
68
-		} else {
69
-			$qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode';
70
-			$qrcode_path = $qrcode_dir;
71
-		}
72
-
73
-		if (is_dir($qrcode_path)) {
74
-			$this->qrcodePath = $qrcode_path;
75
-		} else {
76
-			throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE));
77
-		}
78
-
79
-		if (isset($options["zend.path"])) {
80
-			$zend_dir = $options["zend.path"];
81
-			$zend_path = realpath($zend_dir);
82
-		} else {
83
-			$zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend";
84
-			$zend_path = $zend_dir;
85
-		}
86
-		if (is_dir($zend_path)) {
87
-			$this->zendPath = $zend_path;
88
-		} else {
89
-			throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE));
90
-		}
91
-	}
92
-
93
-
94
-	public function setIncludePath() {
95
-		set_include_path(implode(PATH_SEPARATOR, array(
96
-			$this->tiqrPath,
97
-			$this->zendPath,
98
-			$this->qrcodePath,
99
-			get_include_path(),
100
-		)));
101
-	}
42
+        } else {
43
+            return;
44
+        }
45
+
46
+        if (file_exists($file)) {
47
+            require_once($file);
48
+        }
49
+    }
50
+
51
+    public function setOptions($options) {
52
+        if (isset($options["tiqr.path"])) {
53
+            $tiqr_dir = $options["tiqr.path"];
54
+            $tiqr_path = realpath($tiqr_dir);
55
+        } else {
56
+            $tiqr_dir = dirname(__FILE__);
57
+            $tiqr_path = $tiqr_dir;
58
+        }
59
+        if (is_dir($tiqr_path)) {
60
+            $this->tiqrPath = $tiqr_path;
61
+        } else {
62
+            throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE));
63
+        }
64
+
65
+        if (isset($options["phpqrcode.path"])) {
66
+            $qrcode_dir = $options["phpqrcode.path"];
67
+            $qrcode_path = realpath($qrcode_dir);
68
+        } else {
69
+            $qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode';
70
+            $qrcode_path = $qrcode_dir;
71
+        }
72
+
73
+        if (is_dir($qrcode_path)) {
74
+            $this->qrcodePath = $qrcode_path;
75
+        } else {
76
+            throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE));
77
+        }
78
+
79
+        if (isset($options["zend.path"])) {
80
+            $zend_dir = $options["zend.path"];
81
+            $zend_path = realpath($zend_dir);
82
+        } else {
83
+            $zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend";
84
+            $zend_path = $zend_dir;
85
+        }
86
+        if (is_dir($zend_path)) {
87
+            $this->zendPath = $zend_path;
88
+        } else {
89
+            throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE));
90
+        }
91
+    }
92
+
93
+
94
+    public function setIncludePath() {
95
+        set_include_path(implode(PATH_SEPARATOR, array(
96
+            $this->tiqrPath,
97
+            $this->zendPath,
98
+            $this->qrcodePath,
99
+            get_include_path(),
100
+        )));
101
+    }
102 102
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRA.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
      */
37 37
     private static function _hmac(string $crypto, string $keyBytes, string $text) : string
38 38
     {
39
-         $hash = hash_hmac($crypto, $text, $keyBytes);
40
-         if (false === $hash) {
41
-             throw new Exception("calculating hash_hmac failed");
42
-         }
43
-         return $hash;
39
+            $hash = hash_hmac($crypto, $text, $keyBytes);
40
+            if (false === $hash) {
41
+                throw new Exception("calculating hash_hmac failed");
42
+            }
43
+            return $hash;
44 44
     }
45 45
 
46 46
     /**
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
      * alternative to "-S064"
100 100
      */
101 101
     static function generateOCRA(string $ocraSuite,
102
-                                 string $key,
103
-                                 string $counter,
104
-                                 string $question,
105
-                                 string $password,
106
-                                 string $sessionInformation,
107
-                                 string $timeStamp) : string
102
+                                    string $key,
103
+                                    string $counter,
104
+                                    string $question,
105
+                                    string $password,
106
+                                    string $sessionInformation,
107
+                                    string $timeStamp) : string
108 108
     {
109 109
         $codeDigits = 0;
110 110
         $crypto = "";
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -58,18 +58,18 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Braces   +42 added lines, -28 removed lines patch added patch discarded remove patch
@@ -122,12 +122,15 @@  discard block
 block discarded – undo
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)
126
-            $crypto = "sha1";
127
-        if(stripos($cryptoFunction, "sha256")!==false)
128
-            $crypto = "sha256";
129
-        if(stripos($cryptoFunction, "sha512")!==false)
130
-            $crypto = "sha512";
125
+        if(stripos($cryptoFunction, "sha1")!==false) {
126
+                    $crypto = "sha1";
127
+        }
128
+        if(stripos($cryptoFunction, "sha256")!==false) {
129
+                    $crypto = "sha256";
130
+        }
131
+        if(stripos($cryptoFunction, "sha512")!==false) {
132
+                    $crypto = "sha512";
133
+        }
131 134
         
132 135
         $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1);
133 136
                 
@@ -135,56 +138,65 @@  discard block
 block discarded – undo
135 138
         // Counter
136 139
         if($dataInput[0] == "c" ) {
137 140
             // Fix the length of the HEX string
138
-            while(strlen($counter) < 16)
139
-                $counter = "0" . $counter;
141
+            while(strlen($counter) < 16) {
142
+                            $counter = "0" . $counter;
143
+            }
140 144
             $counterLength=8;
141 145
         }
142 146
         // Question
143 147
         if($dataInput[0] == "q" ||
144 148
                 stripos($dataInput, "-q")!==false) {
145
-            while(strlen($question) < 256)
146
-                $question = $question . "0";
149
+            while(strlen($question) < 256) {
150
+                            $question = $question . "0";
151
+            }
147 152
             $questionLength=128;
148 153
         }
149 154
 
150 155
         // Password
151 156
         if(stripos($dataInput, "psha1")!==false) {
152
-            while(strlen($password) < 40)
153
-                $password = "0" . $password;
157
+            while(strlen($password) < 40) {
158
+                            $password = "0" . $password;
159
+            }
154 160
             $passwordLength=20;
155 161
         }
156 162
     
157 163
         if(stripos($dataInput, "psha256")!==false) {
158
-            while(strlen($password) < 64)
159
-                $password = "0" . $password;
164
+            while(strlen($password) < 64) {
165
+                            $password = "0" . $password;
166
+            }
160 167
             $passwordLength=32;
161 168
         }
162 169
         
163 170
         if(stripos($dataInput, "psha512")!==false) {
164
-            while(strlen($password) < 128)
165
-                $password = "0" . $password;
171
+            while(strlen($password) < 128) {
172
+                            $password = "0" . $password;
173
+            }
166 174
             $passwordLength=64;
167 175
         }
168 176
         
169 177
         // sessionInformation
170 178
         if(stripos($dataInput, "s064") !==false) {
171
-            while(strlen($sessionInformation) < 128)
172
-                $sessionInformation = "0" . $sessionInformation;
179
+            while(strlen($sessionInformation) < 128) {
180
+                            $sessionInformation = "0" . $sessionInformation;
181
+            }
173 182
 
174 183
             $sessionInformationLength=64;
175 184
         } else if(stripos($dataInput, "s128") !==false) {
176
-            while(strlen($sessionInformation) < 256)
177
-                $sessionInformation = "0" . $sessionInformation;
185
+            while(strlen($sessionInformation) < 256) {
186
+                            $sessionInformation = "0" . $sessionInformation;
187
+            }
178 188
         
179 189
             $sessionInformationLength=128;
180 190
         } else if(stripos($dataInput, "s256") !==false) {
181
-            while(strlen($sessionInformation) < 512)
182
-                $sessionInformation = "0" . $sessionInformation;
191
+            while(strlen($sessionInformation) < 512) {
192
+                            $sessionInformation = "0" . $sessionInformation;
193
+            }
183 194
         
184 195
             $sessionInformationLength=256;
185 196
         } else if(stripos($dataInput, "s512") !==false) {
186
-            while(strlen($sessionInformation) < 128)
187
-                $sessionInformation = "0" . $sessionInformation;
197
+            while(strlen($sessionInformation) < 128) {
198
+                            $sessionInformation = "0" . $sessionInformation;
199
+            }
188 200
         
189 201
             $sessionInformationLength=64;
190 202
         } else if (stripos($dataInput, "-s") !== false ) {
@@ -196,8 +208,9 @@  discard block
 block discarded – undo
196 208
             // to prevent matching the "s" in the password input e.g. "psha1".
197 209
             // [C] | QFxx | [PH | Snnn | TG] : Challenge-Response computation
198 210
             // [C] | QFxx | [PH | TG] : Plain Signature computation
199
-            while(strlen($sessionInformation) < 128)
200
-                $sessionInformation = "0" . $sessionInformation;
211
+            while(strlen($sessionInformation) < 128) {
212
+                            $sessionInformation = "0" . $sessionInformation;
213
+            }
201 214
             
202 215
             $sessionInformationLength=64;
203 216
         }
@@ -207,8 +220,9 @@  discard block
 block discarded – undo
207 220
         // TimeStamp
208 221
         if($dataInput[0] == "t" ||
209 222
                 stripos($dataInput, "-t") !== false) {
210
-            while(strlen($timeStamp) < 16)
211
-                $timeStamp = "0" . $timeStamp;
223
+            while(strlen($timeStamp) < 16) {
224
+                            $timeStamp = "0" . $timeStamp;
225
+            }
212 226
             $timeStampLength=8;
213 227
         }
214 228
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/File.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
79 79
      */
80 80
     private function setUserSecret(string $userId, string $secret): void
81 81
     {
82
-        $data=array();
82
+        $data = array();
83 83
         if ($this->_userExists($userId)) {
84 84
             $data = $this->_loadUser($userId);
85 85
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Pdo.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     public function userExists(string $userId): bool
84 84
     {
85 85
         try {
86
-            $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?');
86
+            $sth = $this->handle->prepare('SELECT userid FROM '.$this->tableName.' WHERE userid = ?');
87 87
             $sth->execute(array($userId));
88 88
             return (false !== $sth->fetchColumn());
89 89
         }
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
     private function getUserSecret(string $userId): string
104 104
     {
105 105
         try {
106
-            $sth = $this->handle->prepare('SELECT secret FROM ' . $this->tableName . ' WHERE userid = ?');
106
+            $sth = $this->handle->prepare('SELECT secret FROM '.$this->tableName.' WHERE userid = ?');
107 107
             $sth->execute(array($userId));
108
-            $res=$sth->fetchColumn();
108
+            $res = $sth->fetchColumn();
109 109
             if ($res === false) {
110 110
                 // No result
111 111
                 $this->logger->error(sprintf('No result getting secret for user "%s"', $userId));
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
         // - The INSERT will fail when displayname has a NOT NULL constraint
142 142
         try {
143 143
             if ($this->userExists($userId)) {
144
-                $sth = $this->handle->prepare('UPDATE ' . $this->tableName . ' SET secret = ? WHERE userid = ?');
144
+                $sth = $this->handle->prepare('UPDATE '.$this->tableName.' SET secret = ? WHERE userid = ?');
145 145
             } else {
146
-                $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)');
146
+                $sth = $this->handle->prepare('INSERT INTO '.$this->tableName.' (secret,userid) VALUES (?,?)');
147 147
             }
148 148
             $sth->execute(array($secret, $userId));
149 149
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -86,8 +86,7 @@  discard block
 block discarded – undo
86 86
             $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?');
87 87
             $sth->execute(array($userId));
88 88
             return (false !== $sth->fetchColumn());
89
-        }
90
-        catch (Exception $e) {
89
+        } catch (Exception $e) {
91 90
             $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId));
92 91
             throw ReadWriteException::fromOriginalException($e);
93 92
         }
@@ -111,8 +110,7 @@  discard block
 block discarded – undo
111 110
                 $this->logger->error(sprintf('No result getting secret for user "%s"', $userId));
112 111
                 throw new RuntimeException('User not found');
113 112
             }
114
-        }
115
-        catch (Exception $e) {
113
+        } catch (Exception $e) {
116 114
             $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId));
117 115
             throw ReadWriteException::fromOriginalException($e);
118 116
         }
@@ -146,8 +144,7 @@  discard block
 block discarded – undo
146 144
                 $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)');
147 145
             }
148 146
             $sth->execute(array($secret, $userId));
149
-        }
150
-        catch (Exception $e) {
147
+        } catch (Exception $e) {
151 148
             $this->logger->error(
152 149
                 sprintf('Unable to persist user secret for user "%s" in user secret storage (PDO)', $userId),
153 150
                 array('exception'=>$e)
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRAParser.php 2 patches
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -4,32 +4,32 @@  discard block
 block discarded – undo
4 4
 
5 5
 class OATH_OCRAParser {
6 6
 
7
-	private $OCRASuite = NULL;
7
+    private $OCRASuite = NULL;
8 8
 
9
-	private $OCRAVersion = NULL;
9
+    private $OCRAVersion = NULL;
10 10
 
11
-	private $CryptoFunctionType = NULL;
12
-	private $CryptoFunctionHash = NULL;
13
-	private $CryptoFunctionHashLength = NULL;
14
-	private $CryptoFunctionTruncation = NULL;
11
+    private $CryptoFunctionType = NULL;
12
+    private $CryptoFunctionHash = NULL;
13
+    private $CryptoFunctionHashLength = NULL;
14
+    private $CryptoFunctionTruncation = NULL;
15 15
 
16
-	private $C = FALSE;
17
-	private $Q = FALSE;
18
-	private $QType = 'N';
19
-	private $QLength = 8;
16
+    private $C = FALSE;
17
+    private $Q = FALSE;
18
+    private $QType = 'N';
19
+    private $QLength = 8;
20 20
 
21
-	private $P = FALSE;
22
-	private $PType = 'SHA1';
23
-	private $PLength = 20;
21
+    private $P = FALSE;
22
+    private $PType = 'SHA1';
23
+    private $PLength = 20;
24 24
 
25
-	private $S = FALSE;
26
-	private $SLength = 64;
25
+    private $S = FALSE;
26
+    private $SLength = 64;
27 27
 
28
-	private $T = FALSE;
29
-	private $TLength = 60; // 1M
30
-	private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
28
+    private $T = FALSE;
29
+    private $TLength = 60; // 1M
30
+    private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
31 31
 
32
-	private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
32
+    private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
33 33
 
34 34
 
35 35
     /**
@@ -37,149 +37,149 @@  discard block
 block discarded – undo
37 37
      * @throws Exception
38 38
      */
39 39
     public function __construct(String $ocraSuite) {
40
-		$this->parseOCRASuite($ocraSuite);
41
-	}
40
+        $this->parseOCRASuite($ocraSuite);
41
+    }
42 42
 
43
-	/**
44
-	 * Inspired by https://github.com/bdauvergne/python-oath
43
+    /**
44
+     * Inspired by https://github.com/bdauvergne/python-oath
45 45
      *
46 46
      * @throws Exception
47
-	 */
48
-	private function parseOCRASuite($ocraSuite) {
49
-		if (!is_string($ocraSuite)) {
50
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
51
-		}
52
-
53
-		$ocraSuite = strtoupper($ocraSuite);
54
-		$this->OCRASuite = $ocraSuite;
55
-
56
-		$s = explode(':', $ocraSuite);
57
-		if (count($s) != 3) {
58
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
59
-		}
60
-
61
-		$algo = explode('-', $s[0]);
62
-		if (count($algo) != 2) {
63
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
64
-		}
65
-
66
-		if ($algo[0] !== 'OCRA') {
67
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
68
-		}
69
-
70
-		if ($algo[1] !== '1') {
71
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
72
-		}
73
-		$this->OCRAVersion = $algo[1];
74
-
75
-		$cf = explode('-', $s[1]);
76
-		if (count($cf) != 3) {
77
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
78
-		}
79
-
80
-		if ($cf[0] !== 'HOTP') {
81
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
82
-		}
83
-		$this->CryptoFunctionType = $cf[0];
84
-
85
-		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
86
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
87
-		}
88
-		$this->CryptoFunctionHash = $cf[1];
89
-		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
90
-
91
-		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
92
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
93
-		}
94
-		$this->CryptoFunctionTruncation = intval($cf[2]);
95
-
96
-		$di = explode('-', $s[2]);
97
-		if (count($cf) == 0) {
98
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
99
-		}
100
-
101
-		$data_input = array();
102
-		foreach($di as $elem) {
103
-			$letter = $elem[0];
104
-			if (array_key_exists($letter, $data_input)) {
105
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
106
-			}
107
-			$data_input[$letter] = 1;
108
-
109
-			if ($letter === 'C' && strlen($elem) == 1) {
110
-				$this->C = TRUE;
111
-			} elseif ($letter === 'Q') {
112
-				if (strlen($elem) == 1) {
113
-					$this->Q = TRUE;
114
-				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
115
-					$q_len = intval($match[2]);
116
-					if ($q_len < 4 || $q_len > 64) {
117
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
118
-					}
119
-					$this->Q = TRUE;
120
-					$this->QType = $match[1];
121
-					$this->QLength = $q_len;
122
-				} else {
123
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
124
-				}
125
-			} elseif ($letter === 'P') {
126
-				if (strlen($elem) == 1) {
127
-					$this->P = TRUE;
128
-				} else {
129
-					$p_algo = substr($elem, 1);
130
-					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
131
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
132
-					}
133
-					$this->P = TRUE;
134
-					$this->PType = $p_algo;
135
-					$this->PLength = $this->supportedHashFunctions[$p_algo];
136
-				}
137
-			} elseif ($letter === 'S') {
138
-				if (strlen($elem) == 1) {
139
-					$this->S = TRUE;
140
-				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
141
-					$s_len = intval($match[1]);
142
-					if ($s_len <= 0 || $s_len > 512) {
143
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
144
-					}
145
-
146
-					$this->S = TRUE;
147
-					$this->SLength = $s_len;
148
-				} else {
149
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
150
-				}
151
-			} elseif ($letter === 'T') {
152
-				if (strlen($elem) == 1) {
153
-					$this->T = TRUE;
154
-				} elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
155
-					preg_match_all('/(\d+)([HMS])/', $elem, $match);
156
-
157
-					if (count($match[1]) !== count(array_unique($match[2]))) {
158
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
159
-					}
160
-
161
-					$length = 0;
162
-					for ($i = 0; $i < count($match[1]); $i++) {
163
-						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
164
-					}
165
-					if ($length <= 0) {
166
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
167
-					}
168
-
169
-					$this->T = TRUE;
170
-					$this->TLength = $length;
171
-				} else {
172
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
173
-				}
174
-			} else {
175
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
176
-			}
177
-		}
178
-
179
-		if (!$this->Q) {
180
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
181
-		}
182
-	}
47
+     */
48
+    private function parseOCRASuite($ocraSuite) {
49
+        if (!is_string($ocraSuite)) {
50
+            throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
51
+        }
52
+
53
+        $ocraSuite = strtoupper($ocraSuite);
54
+        $this->OCRASuite = $ocraSuite;
55
+
56
+        $s = explode(':', $ocraSuite);
57
+        if (count($s) != 3) {
58
+            throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
59
+        }
60
+
61
+        $algo = explode('-', $s[0]);
62
+        if (count($algo) != 2) {
63
+            throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
64
+        }
65
+
66
+        if ($algo[0] !== 'OCRA') {
67
+            throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
68
+        }
69
+
70
+        if ($algo[1] !== '1') {
71
+            throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
72
+        }
73
+        $this->OCRAVersion = $algo[1];
74
+
75
+        $cf = explode('-', $s[1]);
76
+        if (count($cf) != 3) {
77
+            throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
78
+        }
79
+
80
+        if ($cf[0] !== 'HOTP') {
81
+            throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
82
+        }
83
+        $this->CryptoFunctionType = $cf[0];
84
+
85
+        if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
86
+            throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
87
+        }
88
+        $this->CryptoFunctionHash = $cf[1];
89
+        $this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
90
+
91
+        if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
92
+            throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
93
+        }
94
+        $this->CryptoFunctionTruncation = intval($cf[2]);
95
+
96
+        $di = explode('-', $s[2]);
97
+        if (count($cf) == 0) {
98
+            throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
99
+        }
100
+
101
+        $data_input = array();
102
+        foreach($di as $elem) {
103
+            $letter = $elem[0];
104
+            if (array_key_exists($letter, $data_input)) {
105
+                throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
106
+            }
107
+            $data_input[$letter] = 1;
108
+
109
+            if ($letter === 'C' && strlen($elem) == 1) {
110
+                $this->C = TRUE;
111
+            } elseif ($letter === 'Q') {
112
+                if (strlen($elem) == 1) {
113
+                    $this->Q = TRUE;
114
+                } elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
115
+                    $q_len = intval($match[2]);
116
+                    if ($q_len < 4 || $q_len > 64) {
117
+                        throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
118
+                    }
119
+                    $this->Q = TRUE;
120
+                    $this->QType = $match[1];
121
+                    $this->QLength = $q_len;
122
+                } else {
123
+                    throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
124
+                }
125
+            } elseif ($letter === 'P') {
126
+                if (strlen($elem) == 1) {
127
+                    $this->P = TRUE;
128
+                } else {
129
+                    $p_algo = substr($elem, 1);
130
+                    if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
131
+                        throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
132
+                    }
133
+                    $this->P = TRUE;
134
+                    $this->PType = $p_algo;
135
+                    $this->PLength = $this->supportedHashFunctions[$p_algo];
136
+                }
137
+            } elseif ($letter === 'S') {
138
+                if (strlen($elem) == 1) {
139
+                    $this->S = TRUE;
140
+                } elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
141
+                    $s_len = intval($match[1]);
142
+                    if ($s_len <= 0 || $s_len > 512) {
143
+                        throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
144
+                    }
145
+
146
+                    $this->S = TRUE;
147
+                    $this->SLength = $s_len;
148
+                } else {
149
+                    throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
150
+                }
151
+            } elseif ($letter === 'T') {
152
+                if (strlen($elem) == 1) {
153
+                    $this->T = TRUE;
154
+                } elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
155
+                    preg_match_all('/(\d+)([HMS])/', $elem, $match);
156
+
157
+                    if (count($match[1]) !== count(array_unique($match[2]))) {
158
+                        throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
159
+                    }
160
+
161
+                    $length = 0;
162
+                    for ($i = 0; $i < count($match[1]); $i++) {
163
+                        $length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
164
+                    }
165
+                    if ($length <= 0) {
166
+                        throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
167
+                    }
168
+
169
+                    $this->T = TRUE;
170
+                    $this->TLength = $length;
171
+                } else {
172
+                    throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
173
+                }
174
+            } else {
175
+                throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
176
+            }
177
+        }
178
+
179
+        if (!$this->Q) {
180
+            throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
181
+        }
182
+    }
183 183
 
184 184
     /** Generate an OCRA challenge question according to the ocra suite specified in the constructor
185 185
      * @return The randomly generated OCRA question
@@ -192,50 +192,50 @@  discard block
 block discarded – undo
192 192
      * Note that the question string is the exact question string a specified in the OCRA strandard (RFC 6287)
193 193
      * The challenge is not yet hex encoded as expected by OCRA::generateOCRA()
194 194
      */
195
-	public function generateChallenge() : String {
196
-		$q_length = $this->QLength;
197
-		$q_type = $this->QType;
195
+    public function generateChallenge() : String {
196
+        $q_length = $this->QLength;
197
+        $q_type = $this->QType;
198 198
 
199 199
         $bytes = Tiqr_Random::randomBytes($q_length);
200 200
 
201
-		switch($q_type) {
202
-			case 'A':
203
-				$challenge = base64_encode($bytes);
204
-				$tr = implode("", unpack('H*', $bytes));
205
-				$challenge = rtrim(strtr($challenge, '+/', $tr), '=');
206
-				break;
207
-			case 'H':
208
-				$challenge = implode("", unpack('H*', $bytes));
209
-				break;
210
-			case 'N':
211
-				$challenge = implode("", unpack('N*', $bytes));
212
-				break;
213
-			default:
214
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
215
-				break;
216
-		}
217
-
218
-		$challenge = substr($challenge, 0, $q_length);
219
-
220
-		return $challenge;
221
-	}
222
-
223
-
224
-	/**
225
-	 * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
226
-	 */
227
-	public static function constEqual(string $s1, string $s2): bool {
228
-		if (strlen($s1) != strlen($s2)) {
229
-			return FALSE;
230
-		}
231
-
232
-		$result = TRUE;
233
-		$length = strlen($s1);
234
-		for ($i = 0; $i < $length; $i++) {
235
-			$result &= ($s1[$i] == $s2[$i]);
236
-		}
237
-
238
-		return (boolean)$result;
239
-	}
201
+        switch($q_type) {
202
+            case 'A':
203
+                $challenge = base64_encode($bytes);
204
+                $tr = implode("", unpack('H*', $bytes));
205
+                $challenge = rtrim(strtr($challenge, '+/', $tr), '=');
206
+                break;
207
+            case 'H':
208
+                $challenge = implode("", unpack('H*', $bytes));
209
+                break;
210
+            case 'N':
211
+                $challenge = implode("", unpack('N*', $bytes));
212
+                break;
213
+            default:
214
+                throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
215
+                break;
216
+        }
217
+
218
+        $challenge = substr($challenge, 0, $q_length);
219
+
220
+        return $challenge;
221
+    }
222
+
223
+
224
+    /**
225
+     * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
226
+     */
227
+    public static function constEqual(string $s1, string $s2): bool {
228
+        if (strlen($s1) != strlen($s2)) {
229
+            return FALSE;
230
+        }
231
+
232
+        $result = TRUE;
233
+        $length = strlen($s1);
234
+        for ($i = 0; $i < $length; $i++) {
235
+            $result &= ($s1[$i] == $s2[$i]);
236
+        }
237
+
238
+        return (boolean)$result;
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once(__DIR__ . "/../Random.php");
3
+require_once(__DIR__."/../Random.php");
4 4
 
5 5
 class OATH_OCRAParser {
6 6
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 	private function parseOCRASuite($ocraSuite) {
49 49
 		if (!is_string($ocraSuite)) {
50
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
50
+			throw new Exception('OCRASuite not in string format: '.var_export($ocraSuite, TRUE));
51 51
 		}
52 52
 
53 53
 		$ocraSuite = strtoupper($ocraSuite);
@@ -55,54 +55,54 @@  discard block
 block discarded – undo
55 55
 
56 56
 		$s = explode(':', $ocraSuite);
57 57
 		if (count($s) != 3) {
58
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
58
+			throw new Exception('Invalid OCRASuite format: '.var_export($ocraSuite, TRUE));
59 59
 		}
60 60
 
61 61
 		$algo = explode('-', $s[0]);
62 62
 		if (count($algo) != 2) {
63
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
63
+			throw new Exception('Invalid OCRA version: '.var_export($s[0], TRUE));
64 64
 		}
65 65
 
66 66
 		if ($algo[0] !== 'OCRA') {
67
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
67
+			throw new Exception('Unsupported OCRA algorithm: '.var_export($algo[0], TRUE));
68 68
 		}
69 69
 
70 70
 		if ($algo[1] !== '1') {
71
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
71
+			throw new Exception('Unsupported OCRA version: '.var_export($algo[1], TRUE));
72 72
 		}
73 73
 		$this->OCRAVersion = $algo[1];
74 74
 
75 75
 		$cf = explode('-', $s[1]);
76 76
 		if (count($cf) != 3) {
77
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
77
+			throw new Exception('Invalid OCRA suite crypto function: '.var_export($s[1], TRUE));
78 78
 		}
79 79
 
80 80
 		if ($cf[0] !== 'HOTP') {
81
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
81
+			throw new Exception('Unsupported OCRA suite crypto function: '.var_export($cf[0], TRUE));
82 82
 		}
83 83
 		$this->CryptoFunctionType = $cf[0];
84 84
 
85 85
 		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
86
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
86
+			throw new Exception('Unsupported hash function in OCRA suite crypto function: '.var_export($cf[1], TRUE));
87 87
 		}
88 88
 		$this->CryptoFunctionHash = $cf[1];
89 89
 		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
90 90
 
91 91
 		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
92
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
92
+			throw new Exception('Invalid OCRA suite crypto function truncation length: '.var_export($cf[2], TRUE));
93 93
 		}
94 94
 		$this->CryptoFunctionTruncation = intval($cf[2]);
95 95
 
96 96
 		$di = explode('-', $s[2]);
97 97
 		if (count($cf) == 0) {
98
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
98
+			throw new Exception('Invalid OCRA suite data input: '.var_export($s[2], TRUE));
99 99
 		}
100 100
 
101 101
 		$data_input = array();
102
-		foreach($di as $elem) {
102
+		foreach ($di as $elem) {
103 103
 			$letter = $elem[0];
104 104
 			if (array_key_exists($letter, $data_input)) {
105
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
105
+				throw new Exception('Duplicate field in OCRA suite data input: '.var_export($elem, TRUE));
106 106
 			}
107 107
 			$data_input[$letter] = 1;
108 108
 
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
 				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
115 115
 					$q_len = intval($match[2]);
116 116
 					if ($q_len < 4 || $q_len > 64) {
117
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
117
+						throw new Exception('Invalid OCRA suite data input question length: '.var_export($q_len, TRUE));
118 118
 					}
119 119
 					$this->Q = TRUE;
120 120
 					$this->QType = $match[1];
121 121
 					$this->QLength = $q_len;
122 122
 				} else {
123
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
123
+					throw new Exception('Invalid OCRA suite data input question: '.var_export($elem, TRUE));
124 124
 				}
125 125
 			} elseif ($letter === 'P') {
126 126
 				if (strlen($elem) == 1) {
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 				} else {
129 129
 					$p_algo = substr($elem, 1);
130 130
 					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
131
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
131
+						throw new Exception('Unsupported OCRA suite PIN hash function: '.var_export($elem, TRUE));
132 132
 					}
133 133
 					$this->P = TRUE;
134 134
 					$this->PType = $p_algo;
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
 				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
141 141
 					$s_len = intval($match[1]);
142 142
 					if ($s_len <= 0 || $s_len > 512) {
143
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
143
+						throw new Exception('Invalid OCRA suite data input session information length: '.var_export($s_len, TRUE));
144 144
 					}
145 145
 
146 146
 					$this->S = TRUE;
147 147
 					$this->SLength = $s_len;
148 148
 				} else {
149
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
149
+					throw new Exception('Invalid OCRA suite data input session information length: '.var_export($elem, TRUE));
150 150
 				}
151 151
 			} elseif ($letter === 'T') {
152 152
 				if (strlen($elem) == 1) {
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 					preg_match_all('/(\d+)([HMS])/', $elem, $match);
156 156
 
157 157
 					if (count($match[1]) !== count(array_unique($match[2]))) {
158
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
158
+						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: '.var_export($elem, TRUE));
159 159
 					}
160 160
 
161 161
 					$length = 0;
@@ -163,21 +163,21 @@  discard block
 block discarded – undo
163 163
 						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
164 164
 					}
165 165
 					if ($length <= 0) {
166
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
166
+						throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
167 167
 					}
168 168
 
169 169
 					$this->T = TRUE;
170 170
 					$this->TLength = $length;
171 171
 				} else {
172
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
172
+					throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
173 173
 				}
174 174
 			} else {
175
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
175
+				throw new Exception('Unsupported OCRA suite data input field: '.var_export($elem, TRUE));
176 176
 			}
177 177
 		}
178 178
 
179 179
 		if (!$this->Q) {
180
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
180
+			throw new Exception('OCRA suite data input question not defined: '.var_export($s[2], TRUE));
181 181
 		}
182 182
 	}
183 183
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 
199 199
         $bytes = Tiqr_Random::randomBytes($q_length);
200 200
 
201
-		switch($q_type) {
201
+		switch ($q_type) {
202 202
 			case 'A':
203 203
 				$challenge = base64_encode($bytes);
204 204
 				$tr = implode("", unpack('H*', $bytes));
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 				$challenge = implode("", unpack('N*', $bytes));
212 212
 				break;
213 213
 			default:
214
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
214
+				throw new Exception('Unsupported OCRASuite challenge type: '.var_export($q_type, TRUE));
215 215
 				break;
216 216
 		}
217 217
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 			$result &= ($s1[$i] == $s2[$i]);
236 236
 		}
237 237
 
238
-		return (boolean)$result;
238
+		return (boolean) $result;
239 239
 	}
240 240
 
241 241
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/DeviceStorage/Abstract.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
      * @param array $options The options
60 60
      * @param LoggerInterface $logger
61 61
      */
62
-    public function __construct(array $options=array(), LoggerInterface $logger)
62
+    public function __construct(array $options = array(), LoggerInterface $logger)
63 63
     {
64 64
         $this->_options = $options;
65 65
         $this->logger = $logger;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/FileTrait.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
74 74
      */
75 75
     public function getPath(): string
76 76
     {
77
-        if (substr($this->path, -1)!="/") return $this->path."/";
77
+        if (substr($this->path, -1) != "/") return $this->path."/";
78 78
         return $this->path;
79 79
     }
80 80
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,9 @@
 block discarded – undo
74 74
      */
75 75
     public function getPath(): string
76 76
     {
77
-        if (substr($this->path, -1)!="/") return $this->path."/";
77
+        if (substr($this->path, -1)!="/") {
78
+            return $this->path."/";
79
+        }
78 80
         return $this->path;
79 81
     }
80 82
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Encryption.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
      *
41 41
      * @return Tiqr_UserSecretStorage_Encryption_Interface
42 42
      */
43
-    public static function getEncryption(LoggerInterface $logger, string $type="dummy", array $options=array()): Tiqr_UserSecretStorage_Encryption_Interface
43
+    public static function getEncryption(LoggerInterface $logger, string $type = "dummy", array $options = array()): Tiqr_UserSecretStorage_Encryption_Interface
44 44
     {
45 45
         $logger->info(sprintf('Using %s as UserStorage encryption type', $type));
46 46
         switch ($type) {
Please login to merge, or discard this patch.