Lines Matching defs:type

158         $type = $this->decodeBytes(true);
161 return $type;
167 public function complete(IncompleteType $type, int $tagType, array $tagMap = []): AbstractType
170 $this->startEncoding($type->getValue(), $tagMap);
171 $newType = $this->decodeBytes(false, $tagType, $this->maxLen, $type->getIsConstructed(), AbstractType::TAG_CLASS_UNIVERSAL);
173 $newType->setTagNumber($type->getTagNumber())
174 ->setTagClass($type->getTagClass());
183 public function encode(AbstractType $type): string
185 switch ($type) {
186 case $type instanceof BooleanType:
187 $bytes = $type->getValue() ? self::BOOL_TRUE : self::BOOL_FALSE;
189 case $type instanceof IntegerType:
190 case $type instanceof EnumeratedType:
191 $bytes = $this->encodeInteger($type);
193 case $type instanceof RealType:
194 $bytes = $this->encodeReal($type);
196 case $type instanceof AbstractStringType:
197 $bytes = $type->getValue();
199 case $type instanceof SetOfType:
200 $bytes = $this->encodeSetOf($type);
202 case $type instanceof SetType:
203 $bytes = $this->encodeSet($type);
205 case $type->getIsConstructed():
206 $bytes = $this->encodeConstructedType(...$type->getChildren());
208 case $type instanceof BitStringType:
209 $bytes = $this->encodeBitString($type);
211 case $type instanceof OidType:
212 $bytes = $this->encodeOid($type);
214 case $type instanceof RelativeOidType:
215 $bytes = $this->encodeRelativeOid($type);
217 case $type instanceof GeneralizedTimeType:
218 $bytes = $this->encodeGeneralizedTime($type);
220 case $type instanceof UtcTimeType:
221 $bytes = $this->encodeUtcTime($type);
223 case $type instanceof NullType:
228 'The type "%s" is not currently supported.',
229 get_class($type)
236 $tag = $type->getTagClass() | ($type->getIsConstructed() ? AbstractType::CONSTRUCTED_TYPE : 0);
238 $this->validateNumericInt($type->getTagNumber());
241 if ($type->getTagNumber() >= 31) {
242 $bytes = chr($tag | 0x1f) . $this->intToVlqBytes($type->getTagNumber()) . $bytes;
245 $bytes = chr($tag | $type->getTagNumber()) . $bytes;
376 $type = new IncompleteType(substr($this->binary, $this->pos, $length), $tagNumber, $class, $isConstructed);
379 return $type;
388 throw new EncoderException('The encoded boolean type is malformed.');
390 $type = EncodedType\BooleanType::withTag($tagNumber, $class, $this->decodeBoolean());
394 throw new EncoderException('The encoded null type is malformed.');
396 $type = EncodedType\NullType::withTag($tagNumber, $class);
400 throw new EncoderException('The encoded integer type is malformed.');
402 $type = EncodedType\IntegerType::withTag($tagNumber, $class, $this->decodeInteger($length));
406 throw new EncoderException('The encoded enumerated type is malformed.');
408 $type = EncodedType\EnumeratedType::withTag($tagNumber, $class, $this->decodeInteger($length));
412 throw new EncoderException('The encoded real type is malformed.');
414 $type = RealType::withTag($tagNumber, $class, $this->decodeReal($length));
417 $type = EncodedType\BitStringType::withTag($tagNumber, $class, $isConstructed, $this->decodeBitString($length));
421 throw new EncoderException('The encoded OID type is malformed.');
423 $type = OidType::withTag($tagNumber, $class, $this->decodeOid($length));
427 throw new EncoderException('The encoded relative OID type is malformed.');
429 $type = RelativeOidType::withTag($tagNumber, $class, $this->decodeRelativeOid($length));
432 $type = EncodedType\GeneralizedTimeType::withTag($tagNumber, $class, $isConstructed, ...$this->decodeGeneralizedTime($length));
435 $type = EncodedType\UtcTimeType::withTag($tagNumber, $class, $isConstructed, ...$this->decodeUtcTime($length));
438 $type = EncodedType\OctetStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
442 $type = EncodedType\GeneralStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
446 $type = EncodedType\VisibleStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
450 $type = EncodedType\BmpStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
454 $type = EncodedType\CharacterStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
458 $type = EncodedType\UniversalStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
462 $type = EncodedType\GraphicStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
466 $type = EncodedType\VideotexStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
470 $type = EncodedType\TeletexStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
474 $type = EncodedType\PrintableStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
478 $type = EncodedType\NumericStringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
482 $type = EncodedType\IA5StringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
486 $type = EncodedType\Utf8StringType::withTag($tagNumber, $class, $isConstructed, substr($this->binary, $this->pos, $length));
491 throw new EncoderException('The encoded sequence type is malformed.');
493 $type = EncodedType\SequenceType::withTag($tagNumber, $class, $this->decodeConstructedType($length));
497 throw new EncoderException('The encoded set type is malformed.');
499 $type = EncodedType\SetType::withTag($tagNumber, $class, $this->decodeConstructedType($length));
502 throw new EncoderException(sprintf('Unable to decode value to a type for tag %s.', $tagType));
505 return $type;
659 * @param BitStringType $type
662 protected function encodeBitString(BitStringType $type)
664 $data = $type->getValue();
682 * @param RelativeOidType $type
686 protected function encodeRelativeOid(RelativeOidType $type)
688 $oids = explode('.', $type->getValue());
699 * @param OidType $type
703 protected function encodeOid(OidType $type)
706 $oids = explode('.', $type->getValue());
711 $type->getValue()
738 * @param GeneralizedTimeType $type
742 protected function encodeGeneralizedTime(GeneralizedTimeType $type)
744 return $this->encodeTime($type, 'YmdH');
748 * @param UtcTimeType $type
752 protected function encodeUtcTime(UtcTimeType $type)
754 return $this->encodeTime($type, 'ymdH');
758 * @param AbstractTimeType $type
763 protected function encodeTime(AbstractTimeType $type, string $format)
765 if ($type->getDateTimeFormat() === GeneralizedTimeType::FORMAT_SECONDS || $type->getDateTimeFormat() === GeneralizedTimeType::FORMAT_FRACTIONS) {
767 } elseif ($type->getDateTimeFormat() === GeneralizedTimeType::FORMAT_MINUTES) {
772 if ($type->getValue()->format('H') === '24') {
777 clone $type->getValue(),
778 $type->getDateTimeFormat(),
779 $type->getTimeZoneFormat(),
817 * @param IntegerType|EnumeratedType $type
821 protected function encodeInteger(AbstractType $type): string
823 $int = $type->getValue();
825 $isBigInt = $type->isBigInt();
829 $int = $isBigInt ? gmp_abs($type->getValue()) : ($int * -1);
866 * @param RealType $type
870 protected function encodeReal(RealType $type)
872 $real = $type->getValue();
887 // @todo Real type encoding/decoding is rather complex. Need to implement this yet.
888 throw new EncoderException('Real type encoding of this value not yet implemented.');
981 throw new EncoderException('Zero length not permitted for an OID type.');
1012 throw new EncoderException('Zero length not permitted for an OID type.');
1090 throw new EncoderException('Zero length not permitted for an integer type.');
1152 // @todo Real type encoding/decoding is rather complex. Need to implement this yet.
1153 throw new EncoderException('The real type encoding encountered is not yet implemented.');
1189 foreach ($types as $type) {
1190 $bytes .= $this->encode($type);