Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v4]

## [v4.0.0] - 2025-01-22
### Changed
- PHPSecLib v2.0 to v3.0. Updated all imports to use `phpseclib3`

## [v3]

## [v3.2.0] - 2023-08-14
### Added
- Support for PHP 8.1 and up
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"require": {
"php": "^7.4||^8.1",
"dxw/result": "^1.0",
"phpseclib/phpseclib": "^2.0"
"phpseclib/phpseclib": "~3.0"
}
}
10 changes: 5 additions & 5 deletions spec/ipv4address.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@

describe('::FromBinary()', function () {
it('handles correct addresses (small)', function () {
$result = \Dxw\CIDR\IPv4Address::FromBinary(new \phpseclib\Math\BigInteger(1));
$result = \Dxw\CIDR\IPv4Address::FromBinary(new \phpseclib3\Math\BigInteger(1));

expect($result->isErr())->toEqual(false);
expect($result->unwrap())->toBeAnInstanceOf(\Dxw\CIDR\IPv4Address::class);
expect($result->unwrap()->__toString())->toEqual('0.0.0.1');
});

it('handles correct addresses (large)', function () {
$result = \Dxw\CIDR\IPv4Address::FromBinary(new \phpseclib\Math\BigInteger('ffffffff', 16));
$result = \Dxw\CIDR\IPv4Address::FromBinary(new \phpseclib3\Math\BigInteger('ffffffff', 16));

expect($result->isErr())->toEqual(false);
expect($result->unwrap())->toBeAnInstanceOf(\Dxw\CIDR\IPv4Address::class);
expect($result->unwrap()->__toString())->toEqual('255.255.255.255');
});

it('handles broken addresses (too large)', function () {
$result = \Dxw\CIDR\IPv4Address::FromBinary(new \phpseclib\Math\BigInteger('100000000', 16));
$result = \Dxw\CIDR\IPv4Address::FromBinary(new \phpseclib3\Math\BigInteger('100000000', 16));

expect($result->isErr())->toEqual(true);
expect($result->getErr())->toEqual('address size cannot exceed 32 bytes');
});

it('handles broken addresses (negative)', function () {
$result = \Dxw\CIDR\IPv4Address::FromBinary(new \phpseclib\Math\BigInteger(-1));
$result = \Dxw\CIDR\IPv4Address::FromBinary(new \phpseclib3\Math\BigInteger(-1));

expect($result->isErr())->toEqual(true);
expect($result->getErr())->toEqual('address cannot be negative');
Expand All @@ -75,7 +75,7 @@
it('returns a binary representation', function () {
$address = \Dxw\CIDR\IPv4Address::Make('127.0.0.1')->unwrap();

expect($address->getBinary())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($address->getBinary())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($address->getBinary()->toHex())->toEqual(
'7f000001'
);
Expand Down
8 changes: 4 additions & 4 deletions spec/ipv4block.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
it('returns a binary representation for /32', function () {
$block = \Dxw\CIDR\IPv4Block::Make(32)->unwrap();

expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($block->getNetmask()->toHex())->toEqual(
'ffffffff'
);
Expand All @@ -38,7 +38,7 @@
it('returns a binary representation for /0', function () {
$block = \Dxw\CIDR\IPv4Block::Make(0)->unwrap();

expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($block->getNetmask()->toHex())->toEqual(
''
);
Expand All @@ -47,7 +47,7 @@
it('returns a binary representation for /8', function () {
$block = \Dxw\CIDR\IPv4Block::Make(8)->unwrap();

expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($block->getNetmask()->toHex())->toEqual(
'ff000000'
);
Expand All @@ -56,7 +56,7 @@
it('returns a binary representation for /9', function () {
$block = \Dxw\CIDR\IPv4Block::Make(9)->unwrap();

expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($block->getNetmask()->toHex())->toEqual(
'ff800000'
);
Expand Down
14 changes: 7 additions & 7 deletions spec/ipv6address.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@

describe('::FromBinary()', function () {
it('handles correct addresses (small)', function () {
$result = \Dxw\CIDR\IPv6Address::FromBinary(new \phpseclib\Math\BigInteger(1));
$result = \Dxw\CIDR\IPv6Address::FromBinary(new \phpseclib3\Math\BigInteger(1));

expect($result->isErr())->toEqual(false);
expect($result->unwrap())->toBeAnInstanceOf(\Dxw\CIDR\IPv6Address::class);
expect($result->unwrap()->__toString())->toEqual('::1');
});

it('handles correct addresses (large)', function () {
$result = \Dxw\CIDR\IPv6Address::FromBinary(new \phpseclib\Math\BigInteger('ffffffffffffffffffffffffffffffff', 16));
$result = \Dxw\CIDR\IPv6Address::FromBinary(new \phpseclib3\Math\BigInteger('ffffffffffffffffffffffffffffffff', 16));

expect($result->isErr())->toEqual(false);
expect($result->unwrap())->toBeAnInstanceOf(\Dxw\CIDR\IPv6Address::class);
expect($result->unwrap()->__toString())->toEqual('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff');
});

it('handles broken addresses (too large)', function () {
$result = \Dxw\CIDR\IPv6Address::FromBinary(new \phpseclib\Math\BigInteger('100000000000000000000000000000000', 16));
$result = \Dxw\CIDR\IPv6Address::FromBinary(new \phpseclib3\Math\BigInteger('100000000000000000000000000000000', 16));

expect($result->isErr())->toEqual(true);
expect($result->getErr())->toEqual('address size cannot exceed 128 bytes');
});

it('handles broken addresses (negative)', function () {
$result = \Dxw\CIDR\IPv6Address::FromBinary(new \phpseclib\Math\BigInteger(-1));
$result = \Dxw\CIDR\IPv6Address::FromBinary(new \phpseclib3\Math\BigInteger(-1));

expect($result->isErr())->toEqual(true);
expect($result->getErr())->toEqual('address cannot be negative');
Expand All @@ -77,7 +77,7 @@
it('returns a binary representation', function () {
$address = \Dxw\CIDR\IPv6Address::Make('::1')->unwrap();

expect($address->getBinary())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($address->getBinary())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($address->getBinary()->toHex())->toEqual(
'01'
);
Expand All @@ -87,7 +87,7 @@
it('returns a binary representation for IPv4-compatible addresses', function () {
$address = \Dxw\CIDR\IPv6Address::Make('::127.0.0.1')->unwrap();

expect($address->getBinary())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($address->getBinary())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($address->getBinary()->toHex())->toEqual(
'7f000001'
);
Expand All @@ -97,7 +97,7 @@
it('returns a binary representation for IPv4-mapped addresses', function () {
$address = \Dxw\CIDR\IPv6Address::Make('::ffff:127.0.0.1')->unwrap();

expect($address->getBinary())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($address->getBinary())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($address->getBinary()->toHex())->toEqual(
'ffff7f000001'
);
Expand Down
8 changes: 4 additions & 4 deletions spec/ipv6block.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
it('returns a binary representation for /32', function () {
$block = \Dxw\CIDR\IPv6Block::Make(32)->unwrap();

expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($block->getNetmask()->toHex())->toEqual(
'ffffffff000000000000000000000000'
);
Expand All @@ -38,7 +38,7 @@
it('returns a binary representation for /0', function () {
$block = \Dxw\CIDR\IPv6Block::Make(0)->unwrap();

expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($block->getNetmask()->toHex())->toEqual(
''
);
Expand All @@ -47,7 +47,7 @@
it('returns a binary representation for /8', function () {
$block = \Dxw\CIDR\IPv6Block::Make(8)->unwrap();

expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($block->getNetmask()->toHex())->toEqual(
'ff000000000000000000000000000000'
);
Expand All @@ -56,7 +56,7 @@
it('returns a binary representation for /9', function () {
$block = \Dxw\CIDR\IPv6Block::Make(9)->unwrap();

expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib\Math\BigInteger::class);
expect($block->getNetmask())->toBeAnInstanceOf(\phpseclib3\Math\BigInteger::class);
expect($block->getNetmask()->toHex())->toEqual(
'ff800000000000000000000000000000'
);
Expand Down
8 changes: 4 additions & 4 deletions src/AddressBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function __toString(): string
return $value;
}

public static function FromBinary(\phpseclib\Math\BigInteger $binary): \Dxw\Result\Result
public static function FromBinary(\phpseclib3\Math\BigInteger $binary): \Dxw\Result\Result
{
if ($binary->compare(new \phpseclib\Math\BigInteger(0)) < 0) {
if ($binary->compare(new \phpseclib3\Math\BigInteger(0)) < 0) {
return \Dxw\Result\Result::err('address cannot be negative');
}

Expand All @@ -58,8 +58,8 @@ public static function FromBinary(\phpseclib\Math\BigInteger $binary): \Dxw\Resu
return \Dxw\Result\Result::ok(new static($bytes));
}

public function getBinary(): \phpseclib\Math\BigInteger
public function getBinary(): \phpseclib3\Math\BigInteger
{
return new \phpseclib\Math\BigInteger($this->address, 256);
return new \phpseclib3\Math\BigInteger($this->address, 256);
}
}
4 changes: 2 additions & 2 deletions src/BlockBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getValue(): int
return $this->value;
}

public function getNetmask(): \phpseclib\Math\BigInteger
public function getNetmask(): \phpseclib3\Math\BigInteger
{
$i = $this->value;
$s = '';
Expand All @@ -44,7 +44,7 @@ public function getNetmask(): \phpseclib\Math\BigInteger
$s .= '0';
}

return new \phpseclib\Math\BigInteger($s, 2);
return new \phpseclib3\Math\BigInteger($s, 2);
}

public function __toString(): string
Expand Down
Loading