| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace SpomkyLabs\Pki\ASN1\Feature; |
| 6 | |
| 7 | use SpomkyLabs\Pki\ASN1\Element; |
| 8 | use SpomkyLabs\Pki\ASN1\Type\TaggedType; |
| 9 | use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; |
| 10 | |
| 11 | /** |
| 12 | * Base interface for ASN.1 type elements. |
| 13 | */ |
| 14 | interface ElementBase extends Encodable |
| 15 | { |
| 16 | /** |
| 17 | * Get the class of the ASN.1 type. |
| 18 | * |
| 19 | * One of `Identifier::CLASS_*` constants. |
| 20 | */ |
| 21 | public function typeClass(): int; |
| 22 | |
| 23 | /** |
| 24 | * Check whether the element is constructed. |
| 25 | * |
| 26 | * Otherwise it's primitive. |
| 27 | */ |
| 28 | public function isConstructed(): bool; |
| 29 | |
| 30 | /** |
| 31 | * Get the tag of the element. |
| 32 | * |
| 33 | * Interpretation of the tag depends on the context. For example, it may represent a universal type tag or a tag of |
| 34 | * an implicitly or explicitly tagged type. |
| 35 | */ |
| 36 | public function tag(): int; |
| 37 | |
| 38 | /** |
| 39 | * Check whether the element is a type of given tag. |
| 40 | * |
| 41 | * @param int $tag Type tag |
| 42 | */ |
| 43 | public function isType(int $tag): bool; |
| 44 | |
| 45 | /** |
| 46 | * Check whether the element is a type of a given tag. |
| 47 | * |
| 48 | * Throws an exception if expectation fails. |
| 49 | * |
| 50 | * @param int $tag Type tag |
| 51 | */ |
| 52 | public function expectType(int $tag): self; |
| 53 | |
| 54 | /** |
| 55 | * Check whether the element is tagged (context specific). |
| 56 | */ |
| 57 | public function isTagged(): bool; |
| 58 | |
| 59 | /** |
| 60 | * Check whether the element is tagged (context specific) and optionally has a given tag. |
| 61 | * |
| 62 | * Throws an exception if the element is not tagged or tag differs from the expected. |
| 63 | * |
| 64 | * @param null|int $tag Optional type tag |
| 65 | */ |
| 66 | public function expectTagged(?int $tag = null): TaggedType; |
| 67 | |
| 68 | /** |
| 69 | * Get the object as an abstract `Element` instance. |
| 70 | */ |
| 71 | public function asElement(): Element; |
| 72 | |
| 73 | /** |
| 74 | * Get the object as an `UnspecifiedType` instance. |
| 75 | */ |
| 76 | public function asUnspecified(): UnspecifiedType; |
| 77 | } |