Test Failed
Pull Request — develop (#21)
by Pieter van der
07:09
created
library/tiqr/Tiqr/OATH/OCRA_v1.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             $keyBytes,
47 47
             $text)
48 48
     {
49
-         $hash = hash_hmac ($crypto, $text, $keyBytes);
49
+         $hash = hash_hmac($crypto, $text, $keyBytes);
50 50
          return $hash;
51 51
     }
52 52
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return String a string with raw bytes
59 59
      */
60
-    private static function _hexStr2Bytes($hex){
60
+    private static function _hexStr2Bytes($hex) {
61 61
         return pack("H*", $hex);
62 62
     }
63 63
 
@@ -101,63 +101,63 @@  discard block
 block discarded – undo
101 101
         $sessionInformationLength = 0;
102 102
         $timeStampLength = 0;
103 103
 
104
-        if(stripos($ocraSuite, "sha1")!==false)
104
+        if (stripos($ocraSuite, "sha1") !== false)
105 105
             $crypto = "sha1";
106
-        if(stripos($ocraSuite, "sha256")!==false)
106
+        if (stripos($ocraSuite, "sha256") !== false)
107 107
             $crypto = "sha256";
108
-        if(stripos($ocraSuite, "sha512")!==false)
108
+        if (stripos($ocraSuite, "sha512") !== false)
109 109
             $crypto = "sha512";
110 110
 
111 111
         // How many digits should we return
112
-        $oS = substr($ocraSuite, strpos($ocraSuite, ":")+1, strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1) -strpos($ocraSuite, ":")-1);
113
-        $codeDigits = substr($oS, strrpos($oS, "-")+1);
112
+        $oS = substr($ocraSuite, strpos($ocraSuite, ":") + 1, strpos($ocraSuite, ":", strpos($ocraSuite, ":") + 1) - strpos($ocraSuite, ":") - 1);
113
+        $codeDigits = substr($oS, strrpos($oS, "-") + 1);
114 114
         
115 115
         // The size of the byte array message to be encrypted
116 116
         // Counter
117
-        if(stripos($ocraSuite, ":c") !==false) {
117
+        if (stripos($ocraSuite, ":c") !== false) {
118 118
             // Fix the length of the HEX string
119
-            while(strlen($counter) < 16)
120
-                $counter = "0" . $counter;
121
-            $counterLength=8;
119
+            while (strlen($counter) < 16)
120
+                $counter = "0".$counter;
121
+            $counterLength = 8;
122 122
         }
123 123
         // Question
124
-        if(stripos($ocraSuite, ":q")!==false ||
125
-                stripos($ocraSuite, "-q")!==false) {
126
-            while(strlen($question) < 256)
127
-                $question = $question . "0";
128
-            $questionLength=128;
124
+        if (stripos($ocraSuite, ":q") !== false ||
125
+                stripos($ocraSuite, "-q") !== false) {
126
+            while (strlen($question) < 256)
127
+                $question = $question."0";
128
+            $questionLength = 128;
129 129
         }
130 130
 
131 131
         // Password
132
-        if(stripos($ocraSuite, ":p")!==false ||
133
-                stripos($ocraSuite, "-p") !==false) {
134
-            while(strlen($password) < 40)
135
-                $password = "0" . $password;
136
-            $passwordLength=20;
132
+        if (stripos($ocraSuite, ":p") !== false ||
133
+                stripos($ocraSuite, "-p") !== false) {
134
+            while (strlen($password) < 40)
135
+                $password = "0".$password;
136
+            $passwordLength = 20;
137 137
         }
138 138
 
139 139
         // sessionInformation
140
-        if(stripos($ocraSuite, ":s") !==false ||
141
-                stripos($ocraSuite, "-s", strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1)) !== false) {
142
-            while(strlen($sessionInformation) < 128)
143
-                $sessionInformation = "0" . $sessionInformation;
140
+        if (stripos($ocraSuite, ":s") !== false ||
141
+                stripos($ocraSuite, "-s", strpos($ocraSuite, ":", strpos($ocraSuite, ":") + 1)) !== false) {
142
+            while (strlen($sessionInformation) < 128)
143
+                $sessionInformation = "0".$sessionInformation;
144 144
 
145
-            $sessionInformationLength=64;
145
+            $sessionInformationLength = 64;
146 146
         }
147 147
              
148 148
         // TimeStamp
149
-        if(stripos($ocraSuite, ":t") !==false ||
149
+        if (stripos($ocraSuite, ":t") !== false ||
150 150
                 stripos($ocraSuite, "-t") !== false) {
151
-            while(strlen($timeStamp) < 16)
152
-                $timeStamp = "0" . $timeStamp;
153
-            $timeStampLength=8;
151
+            while (strlen($timeStamp) < 16)
152
+                $timeStamp = "0".$timeStamp;
153
+            $timeStampLength = 8;
154 154
         }
155 155
 
156 156
         // Put the bytes of "ocraSuite" parameters into the message
157 157
         
158
-        $msg = array_fill(0,$ocraSuiteLength+$counterLength+$questionLength+$passwordLength+$sessionInformationLength+$timeStampLength+1, 0);
158
+        $msg = array_fill(0, $ocraSuiteLength + $counterLength + $questionLength + $passwordLength + $sessionInformationLength + $timeStampLength + 1, 0);
159 159
                 
160
-        for($i=0;$i<strlen($ocraSuite);$i++) {
160
+        for ($i = 0; $i < strlen($ocraSuite); $i++) {
161 161
             $msg[$i] = $ocraSuite[$i];
162 162
         }
163 163
         
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
 
167 167
         // Put the bytes of "Counter" to the message
168 168
         // Input is HEX encoded
169
-        if($counterLength > 0 ) {
169
+        if ($counterLength > 0) {
170 170
             $bArray = self::_hexStr2Bytes($counter);
171
-            for ($i=0;$i<strlen($bArray);$i++) {
171
+            for ($i = 0; $i < strlen($bArray); $i++) {
172 172
                 $msg [$i + $ocraSuiteLength + 1] = $bArray[$i];
173 173
             }
174 174
         }
@@ -176,36 +176,36 @@  discard block
 block discarded – undo
176 176
 
177 177
         // Put the bytes of "question" to the message
178 178
         // Input is text encoded
179
-        if($questionLength > 0 ) {
179
+        if ($questionLength > 0) {
180 180
             $bArray = self::_hexStr2Bytes($question);
181
-            for ($i=0;$i<strlen($bArray);$i++) {
181
+            for ($i = 0; $i < strlen($bArray); $i++) {
182 182
                 $msg [$i + $ocraSuiteLength + 1 + $counterLength] = $bArray[$i];
183 183
             }
184 184
         }
185 185
 
186 186
         // Put the bytes of "password" to the message
187 187
         // Input is HEX encoded
188
-        if($passwordLength > 0){
188
+        if ($passwordLength > 0) {
189 189
             $bArray = self::_hexStr2Bytes($password);
190
-            for ($i=0;$i<strlen($bArray);$i++) {
190
+            for ($i = 0; $i < strlen($bArray); $i++) {
191 191
                 $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength] = $bArray[$i];
192 192
             }
193 193
         }
194 194
 
195 195
         // Put the bytes of "sessionInformation" to the message
196 196
         // Input is text encoded
197
-        if($sessionInformationLength > 0 ){
197
+        if ($sessionInformationLength > 0) {
198 198
             $bArray = self::_hexStr2Bytes($sessionInformation);
199
-            for ($i=0;$i<strlen($bArray);$i++) {
199
+            for ($i = 0; $i < strlen($bArray); $i++) {
200 200
                 $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength] = $bArray[$i];
201 201
             }
202 202
         }
203 203
 
204 204
         // Put the bytes of "time" to the message
205 205
         // Input is text value of minutes
206
-        if($timeStampLength > 0){
206
+        if ($timeStampLength > 0) {
207 207
             $bArray = self::_hexStr2Bytes($timestamp);
208
-            for ($i=0;$i<strlen($bArray);$i++) {
208
+            for ($i = 0; $i < strlen($bArray); $i++) {
209 209
                 $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength + $sessionInformationLength] = $bArray[$i];
210 210
             }
211 211
         }
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
     static function _oath_truncate($hash, $length = 6)
228 228
     {
229 229
         // Convert to dec
230
-        foreach(str_split($hash,2) as $hex)
230
+        foreach (str_split($hash, 2) as $hex)
231 231
         {
232
-            $hmac_result[]=hexdec($hex);
232
+            $hmac_result[] = hexdec($hex);
233 233
         }
234 234
     
235 235
         // Find offset
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
         // Algorithm from RFC
239 239
         return
240 240
         (
241
-            (($hmac_result[$offset+0] & 0x7f) << 24 ) |
242
-            (($hmac_result[$offset+1] & 0xff) << 16 ) |
243
-            (($hmac_result[$offset+2] & 0xff) << 8 ) |
244
-            ($hmac_result[$offset+3] & 0xff)
245
-        ) % pow(10,$length);
241
+            (($hmac_result[$offset + 0] & 0x7f) << 24) |
242
+            (($hmac_result[$offset + 1] & 0xff) << 16) |
243
+            (($hmac_result[$offset + 2] & 0xff) << 8) |
244
+            ($hmac_result[$offset + 3] & 0xff)
245
+        ) % pow(10, $length);
246 246
     }
247 247
     
248 248
 }
Please login to merge, or discard this patch.