Completed
Push — master ( ac11d6...c4c91f )
by Fabio
07:06
created
framework/Security/TSecurityManager.php 3 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	}
153 153
 
154 154
 	/**
155
-	 * @return mixed the algorithm used to encrypt/decrypt data. Defaults to the string 'aes-256-cbc'.
155
+	 * @return string the algorithm used to encrypt/decrypt data. Defaults to the string 'aes-256-cbc'.
156 156
 	 */
157 157
 	public function getCryptAlgorithm()
158 158
 	{
@@ -173,6 +173,7 @@  discard block
 block discarded – undo
173 173
 	/**
174 174
 	 * Encrypts data with {@link getEncryptionKey EncryptionKey}.
175 175
 	 * @param string data to be encrypted.
176
+	 * @param string $data
176 177
 	 * @return string the encrypted data
177 178
 	 * @throws TNotSupportedException if PHP OpenSSL extension is not loaded
178 179
 	 */
@@ -191,6 +192,7 @@  discard block
 block discarded – undo
191 192
 	/**
192 193
 	 * Decrypts data with {@link getEncryptionKey EncryptionKey}.
193 194
 	 * @param string data to be decrypted.
195
+	 * @param string $data
194 196
 	 * @return string the decrypted data
195 197
 	 * @throws TNotSupportedException if PHP OpenSSL extension is not loaded
196 198
 	 */
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
  */
50 50
 class TSecurityManager extends \Prado\TModule
51 51
 {
52
-	const STATE_VALIDATION_KEY = 'prado:securitymanager:validationkey';
53
-	const STATE_ENCRYPTION_KEY = 'prado:securitymanager:encryptionkey';
52
+	const STATE_VALIDATION_KEY='prado:securitymanager:validationkey';
53
+	const STATE_ENCRYPTION_KEY='prado:securitymanager:encryptionkey';
54 54
 
55
-	private $_validationKey = null;
56
-	private $_encryptionKey = null;
57
-	private $_hashAlgorithm = 'sha256';
58
-	private $_cryptAlgorithm = 'aes-256-cbc';
55
+	private $_validationKey=null;
56
+	private $_encryptionKey=null;
57
+	private $_hashAlgorithm='sha256';
58
+	private $_cryptAlgorithm='aes-256-cbc';
59 59
 	private $_mbstring;
60 60
 
61 61
 	/**
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 */
75 75
 	protected function generateRandomKey()
76 76
 	{
77
-		return sprintf('%08x%08x%08x%08x',mt_rand(),mt_rand(),mt_rand(),mt_rand());
77
+		return sprintf('%08x%08x%08x%08x', mt_rand(), mt_rand(), mt_rand(), mt_rand());
78 78
 	}
79 79
 
80 80
 	/**
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	public function getValidationKey()
85 85
 	{
86
-		if(null === $this->_validationKey) {
87
-			if(null === ($this->_validationKey = $this->getApplication()->getGlobalState(self::STATE_VALIDATION_KEY))) {
88
-				$this->_validationKey = $this->generateRandomKey();
86
+		if(null===$this->_validationKey) {
87
+			if(null===($this->_validationKey=$this->getApplication()->getGlobalState(self::STATE_VALIDATION_KEY))) {
88
+				$this->_validationKey=$this->generateRandomKey();
89 89
 				$this->getApplication()->setGlobalState(self::STATE_VALIDATION_KEY, $this->_validationKey, null, true);
90 90
 			}
91 91
 		}
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	public function setValidationKey($value)
100 100
 	{
101
-		if('' === $value)
101
+		if(''===$value)
102 102
 			throw new TInvalidDataValueException('securitymanager_validationkey_invalid');
103 103
 
104
-		$this->_validationKey = $value;
104
+		$this->_validationKey=$value;
105 105
 	}
106 106
 
107 107
 	/**
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
 	 */
111 111
 	public function getEncryptionKey()
112 112
 	{
113
-		if(null === $this->_encryptionKey) {
114
-			if(null === ($this->_encryptionKey = $this->getApplication()->getGlobalState(self::STATE_ENCRYPTION_KEY))) {
115
-				$this->_encryptionKey = $this->generateRandomKey();
113
+		if(null===$this->_encryptionKey) {
114
+			if(null===($this->_encryptionKey=$this->getApplication()->getGlobalState(self::STATE_ENCRYPTION_KEY))) {
115
+				$this->_encryptionKey=$this->generateRandomKey();
116 116
 				$this->getApplication()->setGlobalState(self::STATE_ENCRYPTION_KEY, $this->_encryptionKey, null, true);
117 117
 			}
118 118
 		}
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function setEncryptionKey($value)
127 127
 	{
128
-		if('' === $value)
128
+		if(''===$value)
129 129
 			throw new TInvalidDataValueException('securitymanager_encryptionkey_invalid');
130 130
 
131
-		$this->_encryptionKey = $value;
131
+		$this->_encryptionKey=$value;
132 132
 	}
133 133
 
134 134
 	/**
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 */
147 147
 	public function setHashAlgorithm($value)
148 148
 	{
149
-		$this->_hashAlgorithm = TPropertyValue::ensureString($value);
149
+		$this->_hashAlgorithm=TPropertyValue::ensureString($value);
150 150
 		if(!in_array($this->_hashAlgorithm, hash_algos()))
151 151
 			throw new TInvalidDataValueException('securitymanager_hash_algorithm_invalid');
152 152
 	}
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	public function setCryptAlgorithm($value)
167 167
 	{
168
-		$this->_cryptAlgorithm = TPropertyValue::ensureString($value);
168
+		$this->_cryptAlgorithm=TPropertyValue::ensureString($value);
169 169
 		if(!in_array($this->_hashAlgorithm, openssl_get_cipher_methods()))
170 170
 			throw new TInvalidDataValueException('securitymanager_crypt_algorithm_invalid');
171 171
 	}
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
 	{
181 181
 		if(extension_loaded('openssl'))
182 182
 		{
183
-			$key = md5($this->getEncryptionKey());
184
-			$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->_cryptAlgorithm));
183
+			$key=md5($this->getEncryptionKey());
184
+			$iv=openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->_cryptAlgorithm));
185 185
 			return $iv.openssl_encrypt($data, $this->_cryptAlgorithm, $key, null, $iv);
186 186
 		}
187 187
 		else
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
 	{
199 199
 		if(extension_loaded('openssl'))
200 200
 		{
201
-			$key = md5($this->getEncryptionKey());
202
-			$iv = $this->substr($data, 0, openssl_cipher_iv_length($this->_cryptAlgorithm));
201
+			$key=md5($this->getEncryptionKey());
202
+			$iv=$this->substr($data, 0, openssl_cipher_iv_length($this->_cryptAlgorithm));
203 203
 			return openssl_decrypt($this->substr($data, $this->strlen($iv), $this->strlen($data)), $this->_cryptAlgorithm, $key, null, $iv);
204 204
 		}
205 205
 		else
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 	 */
214 214
 	public function hashData($data)
215 215
 	{
216
-		$hmac = $this->computeHMAC($data);
216
+		$hmac=$this->computeHMAC($data);
217 217
 		return $hmac.$data;
218 218
 	}
219 219
 
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 		if($this->strlen($data) < $len)
232 232
 			return false;
233 233
 
234
-		$hmac = $this->substr($data, 0, $len);
234
+		$hmac=$this->substr($data, 0, $len);
235 235
 		$data2=$this->substr($data, $len, $this->strlen($data));
236
-		return $hmac === $this->computeHMAC($data2) ? $data2 : false;
236
+		return $hmac===$this->computeHMAC($data2) ? $data2 : false;
237 237
 	}
238 238
 
239 239
 	/**
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	 */
255 255
 	private function strlen($string)
256 256
 	{
257
-		return $this->_mbstring ? mb_strlen($string,'8bit') : strlen($string);
257
+		return $this->_mbstring ? mb_strlen($string, '8bit') : strlen($string);
258 258
 	}
259 259
 
260 260
 	/**
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
 	 * @param int $length the desired portion length
266 266
 	 * @return string the extracted part of string, or FALSE on failure or an empty string.
267 267
 	 */
268
-	private function substr($string,$start,$length)
268
+	private function substr($string, $start, $length)
269 269
 	{
270
-		return $this->_mbstring ? mb_substr($string,$start,$length,'8bit') : substr($string,$start,$length);
270
+		return $this->_mbstring ? mb_substr($string, $start, $length, '8bit') : substr($string, $start, $length);
271 271
 	}
272 272
 }
273 273
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -189,8 +189,7 @@  discard block
 block discarded – undo
189 189
 				return file_put_contents($fileName,file_get_contents($this->_localName))!==false;
190 190
 			else
191 191
 				return false;
192
-		}
193
-		else
192
+		} else
194 193
 			return false;
195 194
 	}
196 195
 
@@ -211,8 +210,7 @@  discard block
 block discarded – undo
211 210
 			$this->_errorCode=$_FILES[$key]['error'];
212 211
 			$this->_localName=$_FILES[$key]['tmp_name'];
213 212
 			return $this->_dataChanged=true;
214
-		}
215
-		else
213
+		} else
216 214
 			return false;
217 215
 	}
218 216
 
Please login to merge, or discard this patch.