_number = BigInt::create($number); } public static function create(BigInteger|int|string $number): static { return new static($number, self::TYPE_INTEGER); } /** * Get the number as a base 10. * * @return string Integer as a string */ public function number(): string { return $this->_number->base10(); } public function getValue(): BigInteger { return $this->_number->getValue(); } /** * Get the number as an integer type. */ public function intNumber(): int { return $this->_number->toInt(); } protected function encodedAsDER(): string { return $this->_number->signedOctets(); } protected static function decodeFromDER(Identifier $identifier, string $data, int &$offset): ElementBase { $idx = $offset; $length = Length::expectFromDER($data, $idx)->intLength(); $bytes = mb_substr($data, $idx, $length, '8bit'); $idx += $length; $num = BigInt::fromSignedOctets($bytes)->getValue(); $offset = $idx; // late static binding since enumerated extends integer type return static::create($num); } /** * Test that number is valid for this context. */ private static function validateNumber(mixed $num): bool { if (is_int($num)) { return true; } if (is_string($num) && preg_match('/-?\d+/', $num) === 1) { return true; } if ($num instanceof BigInteger) { return true; } return false; } }