Completed
Pull Request — master (#2)
by Milos
03:07
created
src/Jwe/AesCbcHmacEncryption.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -58,17 +58,17 @@  discard block
 block discarded – undo
58 58
     public function encrypt($aad, $plainText, $cek)
59 59
     {
60 60
         $cekLen = StringUtils::length($cek);
61
-        if ($cekLen * 8 != $this->keySize) {
62
-            throw new JoseJwtException(sprintf('AES-CBC with HMAC algorithm expected key of size %s bits, but was given %s bits', $this->keySize, $cekLen * 8));
61
+        if ($cekLen*8 != $this->keySize) {
62
+            throw new JoseJwtException(sprintf('AES-CBC with HMAC algorithm expected key of size %s bits, but was given %s bits', $this->keySize, $cekLen*8));
63 63
         }
64
-        if ($cekLen % 2 != 0) {
64
+        if ($cekLen%2 != 0) {
65 65
             throw new JoseJwtException('AES-CBC with HMAC encryption expected key of even number size');
66 66
         }
67 67
 
68
-        $hmacKey = StringUtils::substring($cek, 0, $cekLen / 2);
69
-        $aesKey = StringUtils::substring($cek, $cekLen / 2, $cekLen / 2);
68
+        $hmacKey = StringUtils::substring($cek, 0, $cekLen/2);
69
+        $aesKey = StringUtils::substring($cek, $cekLen/2, $cekLen/2);
70 70
 
71
-        $method = sprintf('AES-%d-CBC', $this->keySize / 2);
71
+        $method = sprintf('AES-%d-CBC', $this->keySize/2);
72 72
         $ivLen = openssl_cipher_iv_length($method);
73 73
         $iv = $this->randomGenerator->get($ivLen);
74 74
         $cipherText = openssl_encrypt($plainText, $method, $aesKey, true, $iv);
@@ -90,22 +90,22 @@  discard block
 block discarded – undo
90 90
     public function decrypt($aad, $cek, $iv, $cipherText, $authTag)
91 91
     {
92 92
         $cekLen = StringUtils::length($cek);
93
-        if ($cekLen * 8 != $this->keySize) {
94
-            throw new JoseJwtException(sprintf('AES-CBC with HMAC algorithm expected key of size %s bits, but was given %s bits', $this->keySize, $cekLen * 8));
93
+        if ($cekLen*8 != $this->keySize) {
94
+            throw new JoseJwtException(sprintf('AES-CBC with HMAC algorithm expected key of size %s bits, but was given %s bits', $this->keySize, $cekLen*8));
95 95
         }
96
-        if ($cekLen % 2 != 0) {
96
+        if ($cekLen%2 != 0) {
97 97
             throw new JoseJwtException('AES-CBC with HMAC encryption expected key of even number size');
98 98
         }
99 99
 
100
-        $hmacKey = StringUtils::substring($cek, 0, $cekLen / 2);
101
-        $aesKey = StringUtils::substring($cek, $cekLen / 2);
100
+        $hmacKey = StringUtils::substring($cek, 0, $cekLen/2);
101
+        $aesKey = StringUtils::substring($cek, $cekLen/2);
102 102
 
103 103
         $expectedAuthTag = $this->computeAuthTag($aad, $iv, $cipherText, $hmacKey);
104 104
         if (false === StringUtils::equals($expectedAuthTag, $authTag)) {
105 105
             throw new IntegrityException('Authentication tag does not match');
106 106
         }
107 107
 
108
-        $method = sprintf('AES-%d-CBC', $this->keySize / 2);
108
+        $method = sprintf('AES-%d-CBC', $this->keySize/2);
109 109
         $plainText = openssl_decrypt($cipherText, $method, $aesKey, true, $iv);
110 110
 
111 111
         return $plainText;
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
             $aad,
128 128
             $iv,
129 129
             $cipherText,
130
-            pack('N2', ($aadLen / $max32bit) * 8, ($aadLen % $max32bit) * 8),
130
+            pack('N2', ($aadLen/$max32bit)*8, ($aadLen%$max32bit)*8),
131 131
         ]);
132 132
         $authTag = $this->hashAlgorithm->sign($hmacInput, $hmacKey);
133 133
         $authTagLen = StringUtils::length($authTag);
134
-        $authTag = StringUtils::substring($authTag, 0, $authTagLen / 2);
134
+        $authTag = StringUtils::substring($authTag, 0, $authTagLen/2);
135 135
 
136 136
         return $authTag;
137 137
     }
Please login to merge, or discard this patch.