__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
declare(strict_types=1);
namespace SpomkyLabs\Pki\X509\GeneralName;
use LogicException;
use SpomkyLabs\Pki\ASN1\Type\Primitive\OctetString;
use SpomkyLabs\Pki\ASN1\Type\Tagged\ImplicitlyTaggedType;
use SpomkyLabs\Pki\ASN1\Type\TaggedType;
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
use UnexpectedValueException;
use function mb_strlen;
/**
* Implements *iPAddress* CHOICE type of *GeneralName*.
*
* Concrete classes `IPv4Address` and `IPv6Address` furthermore implement the parsing semantics.
*
* @see https://tools.ietf.org/html/rfc5280#section-4.2.1.6
*/
abstract class IPAddress extends GeneralName
{
protected function __construct(
protected string $ip,
protected ?string $mask = null
) {
parent::__construct(self::TAG_IP_ADDRESS);
}
/**
* @return self
*/
public static function fromChosenASN1(UnspecifiedType $el): GeneralName
{
$octets = $el->asOctetString()
->string();
return match (mb_strlen($octets, '8bit')) {
4, 8 => IPv4Address::fromOctets($octets),
16, 32 => IPv6Address::fromOctets($octets),
default => throw new UnexpectedValueException('Invalid octet length for IP address.'),
};
}
public function string(): string
{
return $this->ip . (isset($this->mask) ? '/' . $this->mask : '');
}
/**
* Get IP address as a string.
*/
public function address(): string
{
return $this->ip;
}
/**
* Check whether mask is present.
*/
public function hasMask(): bool
{
return isset($this->mask);
}
/**
* Get subnet mask as a string.
*/
public function mask(): string
{
if (! $this->hasMask()) {
throw new LogicException('mask is not set.');
}
return $this->mask;
}
/**
* Get octet representation of the IP address.
*/
abstract protected function octets(): string;
protected function choiceASN1(): TaggedType
{
return ImplicitlyTaggedType::create($this->tag, OctetString::create($this->octets()));
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| DNSName.php | File | 1.23 KB | 0664 |
|
| DirectoryName.php | File | 1.53 KB | 0664 |
|
| EDIPartyName.php | File | 1.17 KB | 0664 |
|
| GeneralName.php | File | 3.27 KB | 0664 |
|
| GeneralNames.php | File | 4.47 KB | 0664 |
|
| IPAddress.php | File | 2.1 KB | 0664 |
|
| IPv4Address.php | File | 1.26 KB | 0664 |
|
| IPv6Address.php | File | 1.63 KB | 0664 |
|
| OtherName.php | File | 1.9 KB | 0664 |
|
| RFC822Name.php | File | 1.15 KB | 0664 |
|
| RegisteredID.php | File | 1.32 KB | 0664 |
|
| UniformResourceIdentifier.php | File | 1.16 KB | 0664 |
|
| X400Address.php | File | 1.13 KB | 0664 |
|