File manager - Edit - /home/opticamezl/www/newok/ASN1.zip
Back
PK �f�\%��w w Construct.phpnu �[��� <?php /* * This file is part of the PHPASN1 library. * * Copyright © Friedrich Große <friedrich.grosse@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FG\ASN1; use ArrayAccess; use ArrayIterator; use Countable; use FG\ASN1\Exception\ParserException; use Iterator; abstract class Construct extends ASNObject implements Countable, ArrayAccess, Iterator, Parsable { /** @var \FG\ASN1\ASNObject[] */ protected $children; private $iteratorPosition; /** * @param \FG\ASN1\ASNObject[] $children the variadic type hint is commented due to https://github.com/facebook/hhvm/issues/4858 */ public function __construct(/* HH_FIXME[4858]: variadic + strict */ ...$children) { $this->children = $children; $this->iteratorPosition = 0; } public function getContent() { return $this->children; } #[\ReturnTypeWillChange] public function rewind() { $this->iteratorPosition = 0; } #[\ReturnTypeWillChange] public function current() { return $this->children[$this->iteratorPosition]; } #[\ReturnTypeWillChange] public function key() { return $this->iteratorPosition; } #[\ReturnTypeWillChange] public function next() { $this->iteratorPosition++; } #[\ReturnTypeWillChange] public function valid() { return isset($this->children[$this->iteratorPosition]); } #[\ReturnTypeWillChange] public function offsetExists($offset) { return array_key_exists($offset, $this->children); } #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->children[$offset]; } #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { if ($offset === null) { $offset = count($this->children); } $this->children[$offset] = $value; } #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->children[$offset]); } protected function calculateContentLength() { $length = 0; foreach ($this->children as $component) { $length += $component->getObjectLength(); } return $length; } protected function getEncodedValue() { $result = ''; foreach ($this->children as $component) { $result .= $component->getBinary(); } return $result; } public function addChild(ASNObject $child) { $this->children[] = $child; } public function addChildren(array $children) { foreach ($children as $child) { $this->addChild($child); } } public function __toString() { $nrOfChildren = $this->getNumberOfChildren(); $childString = $nrOfChildren == 1 ? 'child' : 'children'; return "[{$nrOfChildren} {$childString}]"; } public function getNumberOfChildren() { return count($this->children); } /** * @return \FG\ASN1\ASNObject[] */ public function getChildren() { return $this->children; } /** * @return \FG\ASN1\ASNObject */ public function getFirstChild() { return $this->children[0]; } /** * @param string $binaryData * @param int $offsetIndex * * @throws Exception\ParserException * * @return Construct|static */ #[\ReturnTypeWillChange] public static function fromBinary(&$binaryData, &$offsetIndex = 0) { $parsedObject = new static(); self::parseIdentifier($binaryData[$offsetIndex], $parsedObject->getType(), $offsetIndex++); $contentLength = self::parseContentLength($binaryData, $offsetIndex); $startIndex = $offsetIndex; $children = []; $octetsToRead = $contentLength; while ($octetsToRead > 0) { $newChild = ASNObject::fromBinary($binaryData, $offsetIndex); $octetsToRead -= $newChild->getObjectLength(); $children[] = $newChild; } if ($octetsToRead !== 0) { throw new ParserException("Sequence length incorrect", $startIndex); } $parsedObject->addChildren($children); $parsedObject->setContentLength($contentLength); return $parsedObject; } #[\ReturnTypeWillChange] public function count($mode = COUNT_NORMAL) { return count($this->children, $mode); } public function getIterator() { return new ArrayIterator($this->children); } }PK �f�\V�6E E AbstractString.phpnu �[��� <?php /* * This file is part of the PHPASN1 library. * * Copyright © Friedrich Große <friedrich.grosse@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FG\ASN1; use Exception; abstract class AbstractString extends ASNObject implements Parsable { /** @var string */ protected $value; private $checkStringForIllegalChars = true; private $allowedCharacters = []; /** * The abstract base class for ASN.1 classes which represent some string of character. * * @param string $string */ public function __construct($string) { $this->value = $string; } public function getContent() { return $this->value; } protected function allowCharacter($character) { $this->allowedCharacters[] = $character; } protected function allowCharacters(...$characters) { foreach ($characters as $character) { $this->allowedCharacters[] = $character; } } protected function allowNumbers() { foreach (range('0', '9') as $char) { $this->allowedCharacters[] = (string) $char; } } protected function allowAllLetters() { $this->allowSmallLetters(); $this->allowCapitalLetters(); } protected function allowSmallLetters() { foreach (range('a', 'z') as $char) { $this->allowedCharacters[] = $char; } } protected function allowCapitalLetters() { foreach (range('A', 'Z') as $char) { $this->allowedCharacters[] = $char; } } protected function allowSpaces() { $this->allowedCharacters[] = ' '; } protected function allowAll() { $this->checkStringForIllegalChars = false; } protected function calculateContentLength() { return strlen($this->value); } protected function getEncodedValue() { if ($this->checkStringForIllegalChars) { $this->checkString(); } return $this->value; } protected function checkString() { $stringLength = $this->getContentLength(); for ($i = 0; $i < $stringLength; $i++) { if (in_array($this->value[$i], $this->allowedCharacters) == false) { $typeName = Identifier::getName($this->getType()); throw new Exception("Could not create a {$typeName} from the character sequence '{$this->value}'."); } } } public static function fromBinary(&$binaryData, &$offsetIndex = 0) { $parsedObject = new static(''); self::parseIdentifier($binaryData[$offsetIndex], $parsedObject->getType(), $offsetIndex++); $contentLength = self::parseContentLength($binaryData, $offsetIndex); $string = substr($binaryData, $offsetIndex, $contentLength); $offsetIndex += $contentLength; $parsedObject->value = $string; $parsedObject->setContentLength($contentLength); return $parsedObject; } public static function isValid($string) { $testObject = new static($string); try { $testObject->checkString(); return true; } catch (Exception $exception) { return false; } } } PK �f�\Dbn� � Base128.phpnu �[��� <?php namespace FG\ASN1; use FG\Utility\BigInteger; use InvalidArgumentException; /** * A base-128 decoder. */ class Base128 { /** * @param int $value * * @return string */ public static function encode($value) { $value = BigInteger::create($value); $octets = chr($value->modulus(0x80)->toInteger()); $value = $value->shiftRight(7); while ($value->compare(0) > 0) { $octets .= chr(0x80 | $value->modulus(0x80)->toInteger()); $value = $value->shiftRight(7); } return strrev($octets); } /** * @param string $octets * * @throws InvalidArgumentException if the given octets represent a malformed base-128 value or the decoded value would exceed the the maximum integer length * * @return int */ public static function decode($octets) { $bitsPerOctet = 7; $value = BigInteger::create(0); $i = 0; while (true) { if (!isset($octets[$i])) { throw new InvalidArgumentException(sprintf('Malformed base-128 encoded value (0x%s).', strtoupper(bin2hex($octets)) ?: '0')); } $octet = ord($octets[$i++]); $l1 = $value->shiftLeft($bitsPerOctet); $r1 = $octet & 0x7f; $value = $l1->add($r1); if (0 === ($octet & 0x80)) { break; } } return (string)$value; } } PK �f�\>h�Ɩ � # Composite/AttributeTypeAndValue.phpnu �[��� <?php /* * This file is part of the PHPASN1 library. * * Copyright © Friedrich Große <friedrich.grosse@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FG\ASN1\Composite; use FG\ASN1\ASNObject; use FG\ASN1\Universal\Sequence; use FG\ASN1\Universal\ObjectIdentifier; class AttributeTypeAndValue extends Sequence { /** * @param ObjectIdentifier|string $objIdentifier * @param \FG\ASN1\ASNObject $value */ public function __construct($objIdentifier, ASNObject $value) { if ($objIdentifier instanceof ObjectIdentifier == false) { $objIdentifier = new ObjectIdentifier($objIdentifier); } parent::__construct($objIdentifier, $value); } public function __toString() { return $this->children[0].': '.$this->children[1]; } } PK �f�\��.r Composite/RDNString.phpnu �[��� <?php /* * This file is part of the PHPASN1 library. * * Copyright © Friedrich Große <friedrich.grosse@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FG\ASN1\Composite; use FG\ASN1\Universal\PrintableString; use FG\ASN1\Universal\IA5String; use FG\ASN1\Universal\UTF8String; class RDNString extends RelativeDistinguishedName { /** * @param string|\FG\ASN1\Universal\ObjectIdentifier $objectIdentifierString * @param string|\FG\ASN1\ASNObject $value */ public function __construct($objectIdentifierString, $value) { if (PrintableString::isValid($value)) { $value = new PrintableString($value); } else { if (IA5String::isValid($value)) { $value = new IA5String($value); } else { $value = new UTF8String($value); } } parent::__construct($objectIdentifierString, $value); } } PK �f�\���j j '