Skip to content

Commit a95445d

Browse files
committed
Switch digital signatur ip range check to use symfony function
1 parent de2282a commit a95445d

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

modules/os2forms_digital_signature/os2forms_digital_signature.module

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Drupal\Core\Form\FormStateInterface;
99
use Drupal\Core\StreamWrapper\StreamWrapperManager;
1010
use Drupal\os2forms_digital_signature\Form\SettingsForm;
11+
use Symfony\Component\HttpFoundation\IpUtils;
1112

1213
/**
1314
* Implements hook_cron().
@@ -106,21 +107,5 @@ function os2forms_digital_signature_file_download($uri) {
106107
* TRUE if the IP is within the CIDR range, FALSE otherwise.
107108
*/
108109
function os2forms_digital_signature_ip_in_cidr(string $ip, string $cidr): bool {
109-
if (!str_contains($cidr, '/')) {
110-
return FALSE;
111-
}
112-
113-
[$subnet, $bits] = explode('/', $cidr, 2);
114-
$bits = (int) $bits;
115-
116-
$ip = ip2long($ip);
117-
$subnet = ip2long($subnet);
118-
119-
if ($ip === FALSE || $subnet === FALSE || $bits < 0 || $bits > 32) {
120-
return FALSE;
121-
}
122-
123-
$mask = -1 << (32 - $bits);
124-
125-
return ($ip & $mask) === ($subnet & $mask);
110+
return IpUtils::checkIp($ip, $cidr);
126111
}

0 commit comments

Comments
 (0)