Convert to PSR-2 coding style (using phpcs-fixer)

This commit is contained in:
Sobak
2016-07-26 08:19:35 +02:00
parent 884310add6
commit 5d7003ecc1
37 changed files with 636 additions and 665 deletions

View File

@@ -35,39 +35,68 @@ class sjcl
// Make sure content is valid json
$decoded = json_decode($encoded);
if (is_null($decoded)) return false;
if (is_null($decoded)) {
return false;
}
$decoded = (array) $decoded;
// Make sure no additionnal keys were added.
if (
count(array_keys($decoded)) != count($accepted_keys)
) return false;
) {
return false;
}
// Make sure required fields are present and contain base64 data.
foreach($accepted_keys as $k)
{
if (!array_key_exists($k, $decoded)) return false;
foreach ($accepted_keys as $k) {
if (!array_key_exists($k, $decoded)) {
return false;
}
}
// Make sure some fields are base64 data.
if (!base64_decode($decoded['iv'], true)) return false;
if (!base64_decode($decoded['salt'], true)) return false;
if (!($ct = base64_decode($decoded['ct'], true))) return false;
if (!base64_decode($decoded['iv'], true)) {
return false;
}
if (!base64_decode($decoded['salt'], true)) {
return false;
}
if (!($ct = base64_decode($decoded['ct'], true))) {
return false;
}
// Make sure some fields have a reasonable size.
if (strlen($decoded['iv']) > 24) return false;
if (strlen($decoded['salt']) > 14) return false;
if (strlen($decoded['iv']) > 24) {
return false;
}
if (strlen($decoded['salt']) > 14) {
return false;
}
// Make sure some fields contain no unsupported values.
if (!(is_int($decoded['v']) || is_float($decoded['v'])) || (float) $decoded['v'] < 1) return false;
if (!is_int($decoded['iter']) || $decoded['iter'] <= 100) return false;
if (!in_array($decoded['ks'], array(128, 192, 256), true)) return false;
if (!in_array($decoded['ts'], array(64, 96, 128), true)) return false;
if (!in_array($decoded['mode'], array('ccm', 'ocb2', 'gcm'), true)) return false;
if ($decoded['cipher'] !== 'aes') return false;
if (!(is_int($decoded['v']) || is_float($decoded['v'])) || (float) $decoded['v'] < 1) {
return false;
}
if (!is_int($decoded['iter']) || $decoded['iter'] <= 100) {
return false;
}
if (!in_array($decoded['ks'], array(128, 192, 256), true)) {
return false;
}
if (!in_array($decoded['ts'], array(64, 96, 128), true)) {
return false;
}
if (!in_array($decoded['mode'], array('ccm', 'ocb2', 'gcm'), true)) {
return false;
}
if ($decoded['cipher'] !== 'aes') {
return false;
}
// Reject data if entropy is too low
if (strlen($ct) > strlen(gzdeflate($ct))) return false;
if (strlen($ct) > strlen(gzdeflate($ct))) {
return false;
}
return true;
}