Skip to content

Commit

Permalink
fix(32bit): drop darsyn/ip dependency
Browse files Browse the repository at this point in the history
Parse IPv6 addresses directly using built-in functions.

Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
st3iny committed Feb 2, 2024
1 parent d482467 commit 967fa13
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 64 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"require": {
"amphp/amp": "^2.6.2",
"amphp/parallel": "^1.4.3",
"darsyn/ip": "^4.1.0",
"rubix/ml": "dev-chore/bump-flysystem-v2.1.1"
},
"license": "AGPLv3",
Expand Down
61 changes: 1 addition & 60 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions lib/Service/IpV6Strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright 2019 Christoph Wurst <[email protected]>
*
* @author 2019 Christoph Wurst <[email protected]>
* @author Richard Steinmetz <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -25,7 +26,7 @@

namespace OCA\SuspiciousLogin\Service;

use Darsyn\IP\Version\IPv6;
use InvalidArgumentException;
use OCA\SuspiciousLogin\Db\LoginAddressAggregatedMapper;
use OCA\SuspiciousLogin\Service\MLP\Config;
use function array_map;
Expand All @@ -50,8 +51,12 @@ public function findHistoricAndRecent(LoginAddressAggregatedMapper $loginAddress
}

protected function ipToVec(string $ip): array {
$addr = IPv6::factory($ip);
$hex = bin2hex($addr->getBinary());
$addr = inet_pton($ip);
if ($addr === false) {
throw new InvalidArgumentException('Invalid IPv6 address');
}

$hex = bin2hex($addr);
$padded = str_pad($hex, 32, '0', STR_PAD_LEFT);
$binString = implode('', array_map(function (string $h) {
return str_pad(base_convert($h, 16, 2), 4, '0', STR_PAD_LEFT);
Expand Down

0 comments on commit 967fa13

Please sign in to comment.