Passed
Push — develop ( 339f21...34e8b6 )
by Pieter van der
14:45
created
library/tiqr/Tiqr/Message/Exception.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
      * @param string    $message    exception message
30 30
      * @param Exception $parent     parent exception
31 31
      */
32
-     public function __construct($message, $parent=null)
33
-     {
34
-         parent::__construct($message, 0, $parent);
35
-     }
32
+        public function __construct($message, $parent=null)
33
+        {
34
+            parent::__construct($message, 0, $parent);
35
+        }
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRA.php 1 patch
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.
library/tiqr/Tiqr/UserStorage/GenericStore.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     public function createUser(string $userId, string $displayName) : void
61 61
     {
62 62
         $user = array("userId"=>$userId,
63
-                      "displayName"=>$displayName);
63
+                        "displayName"=>$displayName);
64 64
         $this->_saveUser($userId, $user);
65 65
     }
66 66
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
     {
91 91
         if ($data = $this->_loadUser($userId)) {
92 92
             if (isset($data["notificationType"])) {
93
-               return $data["notificationType"];
93
+                return $data["notificationType"];
94 94
             }
95 95
         }
96 96
         return '';
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     {
114 114
         if ($data = $this->_loadUser($userId)) {
115 115
             if (isset($data["notificationAddress"])) {
116
-               return $data["notificationAddress"];
116
+                return $data["notificationAddress"];
117 117
             }
118 118
         }
119 119
         $this->logger->info('Unable to find notification address for user');
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/File.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,8 +54,8 @@
 block discarded – undo
54 54
         }
55 55
 
56 56
         $envelope = array("expire"=>$expire,
57
-                          "createdAt"=>time(),
58
-                          "value"=>$value);
57
+                            "createdAt"=>time(),
58
+                            "value"=>$value);
59 59
         $filename = $this->getFilenameByKey($key);
60 60
         
61 61
         if (!file_put_contents($filename, serialize($envelope))) {
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Service.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -571,17 +571,17 @@  discard block
 block discarded – undo
571 571
         }
572 572
 
573 573
         $metadata = array("service"=>
574
-                               array("displayName"       => $this->_name,
575
-                                     "identifier"        => $this->_identifier,
576
-                                     "logoUrl"           => $this->_logoUrl,
577
-                                     "infoUrl"           => $this->_infoUrl,
578
-                                     "authenticationUrl" => $authenticationUrl,
579
-                                     "ocraSuite"         => $this->_ocraSuite,
580
-                                     "enrollmentUrl"     => $enrollmentUrl
581
-                               ),
582
-                          "identity"=>
583
-                               array("identifier" =>$data["userId"],
584
-                                     "displayName"=>$data["displayName"]));
574
+                                array("displayName"       => $this->_name,
575
+                                        "identifier"        => $this->_identifier,
576
+                                        "logoUrl"           => $this->_logoUrl,
577
+                                        "infoUrl"           => $this->_infoUrl,
578
+                                        "authenticationUrl" => $authenticationUrl,
579
+                                        "ocraSuite"         => $this->_ocraSuite,
580
+                                        "enrollmentUrl"     => $enrollmentUrl
581
+                                ),
582
+                            "identity"=>
583
+                                array("identifier" =>$data["userId"],
584
+                                        "displayName"=>$data["displayName"]));
585 585
 
586 586
         $this->_unsetStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey);
587 587
 
@@ -611,28 +611,28 @@  discard block
 block discarded – undo
611 611
      */
612 612
     public function getEnrollmentSecret(string $enrollmentKey): string
613 613
     {
614
-         $data = $this->_getStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey);
615
-         if (!is_array($data)) {
616
-             $this->logger->error('getEnrollmentSecret: enrollment key not found');
617
-             throw new RuntimeException('enrollment key not found');
618
-         }
619
-         $userId = $data["userId"] ?? NULL;
620
-         $sessionId = $data["sessionId"] ?? NULL;
621
-         if (!is_string($userId) || !(is_string($sessionId))) {
622
-             throw new RuntimeException('getEnrollmentSecret: invalid enrollment data');
623
-         }
624
-         $enrollmentData = [
625
-             "userId" => $userId,
626
-             "sessionId" => $sessionId
627
-         ];
628
-         $enrollmentSecret = $this->_uniqueSessionKey();
629
-         $this->_setStateValue(
630
-             self::PREFIX_ENROLLMENT_SECRET,
631
-             $enrollmentSecret,
632
-             $enrollmentData,
633
-             self::ENROLLMENT_EXPIRE
634
-         );
635
-         return $enrollmentSecret;
614
+            $data = $this->_getStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey);
615
+            if (!is_array($data)) {
616
+                $this->logger->error('getEnrollmentSecret: enrollment key not found');
617
+                throw new RuntimeException('enrollment key not found');
618
+            }
619
+            $userId = $data["userId"] ?? NULL;
620
+            $sessionId = $data["sessionId"] ?? NULL;
621
+            if (!is_string($userId) || !(is_string($sessionId))) {
622
+                throw new RuntimeException('getEnrollmentSecret: invalid enrollment data');
623
+            }
624
+            $enrollmentData = [
625
+                "userId" => $userId,
626
+                "sessionId" => $sessionId
627
+            ];
628
+            $enrollmentSecret = $this->_uniqueSessionKey();
629
+            $this->_setStateValue(
630
+                self::PREFIX_ENROLLMENT_SECRET,
631
+                $enrollmentSecret,
632
+                $enrollmentData,
633
+                self::ENROLLMENT_EXPIRE
634
+            );
635
+            return $enrollmentSecret;
636 636
     }
637 637
 
638 638
     /**
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Encryption/OpenSSL.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -160,7 +160,7 @@
 block discarded – undo
160 160
     }
161 161
     
162 162
     /**
163
-      * Decrypts the given data.
163
+     * Decrypts the given data.
164 164
      *
165 165
      * @param string $data Data to decrypt.
166 166
      * @return string decrypted data
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Encryption/Plain.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
     }
58 58
     
59 59
     /**
60
-      * Decrypts the given data.
60
+     * Decrypts the given data.
61 61
      *
62 62
      * @param String $data Data to decrypt.
63 63
      *
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@
 block discarded – undo
97 97
      *         ),
98 98
      *     )
99 99
      * );
100
- *
100
+     *
101 101
      *
102 102
      * @return Tiqr_UserSecretStorage_Interface
103 103
      * @throws RuntimeException If an unknown type is requested.
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRAParser.php 1 patch
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -2,32 +2,32 @@  discard block
 block discarded – undo
2 2
 
3 3
 class OATH_OCRAParser {
4 4
 
5
-	private $OCRASuite = NULL;
5
+    private $OCRASuite = NULL;
6 6
 
7
-	private $OCRAVersion = NULL;
7
+    private $OCRAVersion = NULL;
8 8
 
9
-	private $CryptoFunctionType = NULL;
10
-	private $CryptoFunctionHash = NULL;
11
-	private $CryptoFunctionHashLength = NULL;
12
-	private $CryptoFunctionTruncation = NULL;
9
+    private $CryptoFunctionType = NULL;
10
+    private $CryptoFunctionHash = NULL;
11
+    private $CryptoFunctionHashLength = NULL;
12
+    private $CryptoFunctionTruncation = NULL;
13 13
 
14
-	private $C = FALSE;
15
-	private $Q = FALSE;
16
-	private $QType = 'N';
17
-	private $QLength = 8;
14
+    private $C = FALSE;
15
+    private $Q = FALSE;
16
+    private $QType = 'N';
17
+    private $QLength = 8;
18 18
 
19
-	private $P = FALSE;
20
-	private $PType = 'SHA1';
21
-	private $PLength = 20;
19
+    private $P = FALSE;
20
+    private $PType = 'SHA1';
21
+    private $PLength = 20;
22 22
 
23
-	private $S = FALSE;
24
-	private $SLength = 64;
23
+    private $S = FALSE;
24
+    private $SLength = 64;
25 25
 
26
-	private $T = FALSE;
27
-	private $TLength = 60; // 1M
28
-	private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
26
+    private $T = FALSE;
27
+    private $TLength = 60; // 1M
28
+    private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
29 29
 
30
-	private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
30
+    private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
31 31
 
32 32
 
33 33
     /**
@@ -35,149 +35,149 @@  discard block
 block discarded – undo
35 35
      * @throws Exception
36 36
      */
37 37
     public function __construct(String $ocraSuite) {
38
-		$this->parseOCRASuite($ocraSuite);
39
-	}
38
+        $this->parseOCRASuite($ocraSuite);
39
+    }
40 40
 
41
-	/**
42
-	 * Inspired by https://github.com/bdauvergne/python-oath
41
+    /**
42
+     * Inspired by https://github.com/bdauvergne/python-oath
43 43
      *
44 44
      * @throws Exception
45
-	 */
46
-	private function parseOCRASuite($ocraSuite) {
47
-		if (!is_string($ocraSuite)) {
48
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
49
-		}
50
-
51
-		$ocraSuite = strtoupper($ocraSuite);
52
-		$this->OCRASuite = $ocraSuite;
53
-
54
-		$s = explode(':', $ocraSuite);
55
-		if (count($s) != 3) {
56
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
57
-		}
58
-
59
-		$algo = explode('-', $s[0]);
60
-		if (count($algo) != 2) {
61
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
62
-		}
63
-
64
-		if ($algo[0] !== 'OCRA') {
65
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
66
-		}
67
-
68
-		if ($algo[1] !== '1') {
69
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
70
-		}
71
-		$this->OCRAVersion = $algo[1];
72
-
73
-		$cf = explode('-', $s[1]);
74
-		if (count($cf) != 3) {
75
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
76
-		}
77
-
78
-		if ($cf[0] !== 'HOTP') {
79
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
80
-		}
81
-		$this->CryptoFunctionType = $cf[0];
82
-
83
-		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
84
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
85
-		}
86
-		$this->CryptoFunctionHash = $cf[1];
87
-		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
88
-
89
-		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
90
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
91
-		}
92
-		$this->CryptoFunctionTruncation = intval($cf[2]);
93
-
94
-		$di = explode('-', $s[2]);
95
-		if (count($cf) == 0) {
96
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
97
-		}
98
-
99
-		$data_input = array();
100
-		foreach($di as $elem) {
101
-			$letter = $elem[0];
102
-			if (array_key_exists($letter, $data_input)) {
103
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
104
-			}
105
-			$data_input[$letter] = 1;
106
-
107
-			if ($letter === 'C' && strlen($elem) == 1) {
108
-				$this->C = TRUE;
109
-			} elseif ($letter === 'Q') {
110
-				if (strlen($elem) == 1) {
111
-					$this->Q = TRUE;
112
-				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
113
-					$q_len = intval($match[2]);
114
-					if ($q_len < 4 || $q_len > 64) {
115
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
116
-					}
117
-					$this->Q = TRUE;
118
-					$this->QType = $match[1];
119
-					$this->QLength = $q_len;
120
-				} else {
121
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
122
-				}
123
-			} elseif ($letter === 'P') {
124
-				if (strlen($elem) == 1) {
125
-					$this->P = TRUE;
126
-				} else {
127
-					$p_algo = substr($elem, 1);
128
-					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
129
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
130
-					}
131
-					$this->P = TRUE;
132
-					$this->PType = $p_algo;
133
-					$this->PLength = $this->supportedHashFunctions[$p_algo];
134
-				}
135
-			} elseif ($letter === 'S') {
136
-				if (strlen($elem) == 1) {
137
-					$this->S = TRUE;
138
-				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
139
-					$s_len = intval($match[1]);
140
-					if ($s_len <= 0 || $s_len > 512) {
141
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
142
-					}
143
-
144
-					$this->S = TRUE;
145
-					$this->SLength = $s_len;
146
-				} else {
147
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
148
-				}
149
-			} elseif ($letter === 'T') {
150
-				if (strlen($elem) == 1) {
151
-					$this->T = TRUE;
152
-				} elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
153
-					preg_match_all('/(\d+)([HMS])/', $elem, $match);
154
-
155
-					if (count($match[1]) !== count(array_unique($match[2]))) {
156
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
157
-					}
158
-
159
-					$length = 0;
160
-					for ($i = 0; $i < count($match[1]); $i++) {
161
-						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
162
-					}
163
-					if ($length <= 0) {
164
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
165
-					}
166
-
167
-					$this->T = TRUE;
168
-					$this->TLength = $length;
169
-				} else {
170
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
171
-				}
172
-			} else {
173
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
174
-			}
175
-		}
176
-
177
-		if (!$this->Q) {
178
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
179
-		}
180
-	}
45
+     */
46
+    private function parseOCRASuite($ocraSuite) {
47
+        if (!is_string($ocraSuite)) {
48
+            throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
49
+        }
50
+
51
+        $ocraSuite = strtoupper($ocraSuite);
52
+        $this->OCRASuite = $ocraSuite;
53
+
54
+        $s = explode(':', $ocraSuite);
55
+        if (count($s) != 3) {
56
+            throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
57
+        }
58
+
59
+        $algo = explode('-', $s[0]);
60
+        if (count($algo) != 2) {
61
+            throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
62
+        }
63
+
64
+        if ($algo[0] !== 'OCRA') {
65
+            throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
66
+        }
67
+
68
+        if ($algo[1] !== '1') {
69
+            throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
70
+        }
71
+        $this->OCRAVersion = $algo[1];
72
+
73
+        $cf = explode('-', $s[1]);
74
+        if (count($cf) != 3) {
75
+            throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
76
+        }
77
+
78
+        if ($cf[0] !== 'HOTP') {
79
+            throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
80
+        }
81
+        $this->CryptoFunctionType = $cf[0];
82
+
83
+        if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
84
+            throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
85
+        }
86
+        $this->CryptoFunctionHash = $cf[1];
87
+        $this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
88
+
89
+        if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
90
+            throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
91
+        }
92
+        $this->CryptoFunctionTruncation = intval($cf[2]);
93
+
94
+        $di = explode('-', $s[2]);
95
+        if (count($cf) == 0) {
96
+            throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
97
+        }
98
+
99
+        $data_input = array();
100
+        foreach($di as $elem) {
101
+            $letter = $elem[0];
102
+            if (array_key_exists($letter, $data_input)) {
103
+                throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
104
+            }
105
+            $data_input[$letter] = 1;
106
+
107
+            if ($letter === 'C' && strlen($elem) == 1) {
108
+                $this->C = TRUE;
109
+            } elseif ($letter === 'Q') {
110
+                if (strlen($elem) == 1) {
111
+                    $this->Q = TRUE;
112
+                } elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
113
+                    $q_len = intval($match[2]);
114
+                    if ($q_len < 4 || $q_len > 64) {
115
+                        throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
116
+                    }
117
+                    $this->Q = TRUE;
118
+                    $this->QType = $match[1];
119
+                    $this->QLength = $q_len;
120
+                } else {
121
+                    throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
122
+                }
123
+            } elseif ($letter === 'P') {
124
+                if (strlen($elem) == 1) {
125
+                    $this->P = TRUE;
126
+                } else {
127
+                    $p_algo = substr($elem, 1);
128
+                    if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
129
+                        throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
130
+                    }
131
+                    $this->P = TRUE;
132
+                    $this->PType = $p_algo;
133
+                    $this->PLength = $this->supportedHashFunctions[$p_algo];
134
+                }
135
+            } elseif ($letter === 'S') {
136
+                if (strlen($elem) == 1) {
137
+                    $this->S = TRUE;
138
+                } elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
139
+                    $s_len = intval($match[1]);
140
+                    if ($s_len <= 0 || $s_len > 512) {
141
+                        throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
142
+                    }
143
+
144
+                    $this->S = TRUE;
145
+                    $this->SLength = $s_len;
146
+                } else {
147
+                    throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
148
+                }
149
+            } elseif ($letter === 'T') {
150
+                if (strlen($elem) == 1) {
151
+                    $this->T = TRUE;
152
+                } elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
153
+                    preg_match_all('/(\d+)([HMS])/', $elem, $match);
154
+
155
+                    if (count($match[1]) !== count(array_unique($match[2]))) {
156
+                        throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
157
+                    }
158
+
159
+                    $length = 0;
160
+                    for ($i = 0; $i < count($match[1]); $i++) {
161
+                        $length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
162
+                    }
163
+                    if ($length <= 0) {
164
+                        throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
165
+                    }
166
+
167
+                    $this->T = TRUE;
168
+                    $this->TLength = $length;
169
+                } else {
170
+                    throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
171
+                }
172
+            } else {
173
+                throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
174
+            }
175
+        }
176
+
177
+        if (!$this->Q) {
178
+            throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
179
+        }
180
+    }
181 181
 
182 182
     /** Generate an OCRA challenge question according to the ocra suite specified in the constructor
183 183
      * @return String: The randomly generated OCRA question
@@ -190,50 +190,50 @@  discard block
 block discarded – undo
190 190
      * Note that the question string is the exact question string a specified in the OCRA strandard (RFC 6287)
191 191
      * The challenge is not yet hex encoded as expected by OCRA::generateOCRA()
192 192
      */
193
-	public function generateChallenge() : String {
194
-		$q_length = $this->QLength;
195
-		$q_type = $this->QType;
193
+    public function generateChallenge() : String {
194
+        $q_length = $this->QLength;
195
+        $q_type = $this->QType;
196 196
 
197 197
         $bytes = Tiqr_Random::randomBytes($q_length);
198 198
 
199
-		switch($q_type) {
200
-			case 'A':
201
-				$challenge = base64_encode($bytes);
202
-				$tr = implode("", unpack('H*', $bytes));
203
-				$challenge = rtrim(strtr($challenge, '+/', $tr), '=');
204
-				break;
205
-			case 'H':
206
-				$challenge = implode("", unpack('H*', $bytes));
207
-				break;
208
-			case 'N':
209
-				$challenge = implode("", unpack('N*', $bytes));
210
-				break;
211
-			default:
212
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
213
-				break;
214
-		}
215
-
216
-		$challenge = substr($challenge, 0, $q_length);
217
-
218
-		return $challenge;
219
-	}
220
-
221
-
222
-	/**
223
-	 * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
224
-	 */
225
-	public static function constEqual(string $s1, string $s2): bool {
226
-		if (strlen($s1) != strlen($s2)) {
227
-			return FALSE;
228
-		}
229
-
230
-		$result = TRUE;
231
-		$length = strlen($s1);
232
-		for ($i = 0; $i < $length; $i++) {
233
-			$result &= ($s1[$i] == $s2[$i]);
234
-		}
235
-
236
-		return (boolean)$result;
237
-	}
199
+        switch($q_type) {
200
+            case 'A':
201
+                $challenge = base64_encode($bytes);
202
+                $tr = implode("", unpack('H*', $bytes));
203
+                $challenge = rtrim(strtr($challenge, '+/', $tr), '=');
204
+                break;
205
+            case 'H':
206
+                $challenge = implode("", unpack('H*', $bytes));
207
+                break;
208
+            case 'N':
209
+                $challenge = implode("", unpack('N*', $bytes));
210
+                break;
211
+            default:
212
+                throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
213
+                break;
214
+        }
215
+
216
+        $challenge = substr($challenge, 0, $q_length);
217
+
218
+        return $challenge;
219
+    }
220
+
221
+
222
+    /**
223
+     * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
224
+     */
225
+    public static function constEqual(string $s1, string $s2): bool {
226
+        if (strlen($s1) != strlen($s2)) {
227
+            return FALSE;
228
+        }
229
+
230
+        $result = TRUE;
231
+        $length = strlen($s1);
232
+        for ($i = 0; $i < $length; $i++) {
233
+            $result &= ($s1[$i] == $s2[$i]);
234
+        }
235
+
236
+        return (boolean)$result;
237
+    }
238 238
 
239 239
 }
Please login to merge, or discard this patch.