mirror of https://github.com/MISP/MISP
chg: [internal] Faster IPv6 compression
parent
c19162dace
commit
339b6e55a8
|
@ -600,9 +600,6 @@ class AttributeValidationTool
|
|||
*/
|
||||
private static function isHashValid($type, $value)
|
||||
{
|
||||
if (!isset(self::HASH_HEX_LENGTH[$type])) {
|
||||
throw new InvalidArgumentException("Invalid hash type '$type'.");
|
||||
}
|
||||
return strlen($value) === self::HASH_HEX_LENGTH[$type] && ctype_xdigit($value);
|
||||
}
|
||||
|
||||
|
@ -653,9 +650,8 @@ class AttributeValidationTool
|
|||
*/
|
||||
private static function compressIpv6($value)
|
||||
{
|
||||
if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
// convert IPv6 address to compressed format
|
||||
return inet_ntop(inet_pton($value));
|
||||
if (strpos($value, ':') && $converted = inet_pton($value)) {
|
||||
return inet_ntop($converted);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@ class AttributeValidationToolTest extends TestCase
|
|||
$this->assertEquals('1234:fd2:5621:1:89::4500', AttributeValidationTool::modifyBeforeValidation('ip-src', '1234:0fd2:5621:0001:0089:0000:0000:4500'));
|
||||
$this->assertEquals('example.com|1234:fd2:5621:1:89::4500', AttributeValidationTool::modifyBeforeValidation('domain|ip', 'example.com|1234:0fd2:5621:0001:0089:0000:0000:4500'));
|
||||
$this->assertEquals('1234:fd2:5621:1:89::4500|80', AttributeValidationTool::modifyBeforeValidation('ip-src|port', '1234:0fd2:5621:0001:0089:0000:0000:4500|80'));
|
||||
$this->assertEquals('127.0.0.1', AttributeValidationTool::modifyBeforeValidation('ip-src', '127.0.0.1'));
|
||||
}
|
||||
|
||||
private function shouldBeValid($type, array $values)
|
||||
|
|
Loading…
Reference in New Issue