1<?php
2/**
3 * This file is part of the FreeDSx ASN1 package.
4 *
5 * (c) Chad Sikorra <Chad.Sikorra@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11namespace FreeDSx\Asn1\Encoder;
12
13use FreeDSx\Asn1\Exception\EncoderException;
14use FreeDSx\Asn1\Exception\PartialPduException;
15use FreeDSx\Asn1\Type\AbstractType;
16use FreeDSx\Asn1\Type\IncompleteType;
17
18/**
19 * The ASN1 encoder interface.
20 *
21 * @author Chad Sikorra <Chad.Sikorra@gmail.com>
22 */
23interface EncoderInterface
24{
25    /**
26     * Encode a type to its binary form.
27     *
28     * @param AbstractType $type
29     * @return string
30     * @throws EncoderException
31     */
32    public function encode(AbstractType $type): string;
33
34    /**
35     * Decodes (completes) an incomplete type to a specific universal tag type object.
36     *
37     * @param IncompleteType $type
38     * @param int $tagType
39     * @param array $tagMap
40     * @return AbstractType
41     * @throws EncoderException
42     */
43    public function complete(IncompleteType $type, int $tagType, array $tagMap = []): AbstractType;
44
45    /**
46     * Decode binary data to its ASN1 object representation.
47     *
48     * @param string $binary
49     * @param array $tagMap
50     * @return AbstractType
51     * @throws EncoderException
52     * @throws PartialPduException
53     */
54    public function decode($binary, array $tagMap = []): AbstractType;
55
56    /**
57     * Get the last position of the binary byte stream after a decode operation.
58     *
59     * @return int|null
60     */
61    public function getLastPosition(): ?int;
62}
63