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\Type;
12
13/**
14 * Represents an ASN1 set type.
15 *
16 * @author Chad Sikorra <Chad.Sikorra@gmail.com>
17 */
18class SetType extends AbstractType
19{
20    use SetTrait;
21
22    protected $tagNumber = self::TAG_TYPE_SET;
23
24    protected $isConstructed = true;
25
26    /**
27     * @param AbstractType ...$types
28     */
29    public function __construct(...$types)
30    {
31        parent::__construct(null);
32        $this->children = $types;
33    }
34
35    /**
36     * X.680, 8.6
37     *
38     * Used to determine if the set is in canonical order, which is required by some encodings for a SET.
39     */
40    public function isCanonical(): bool
41    {
42        return $this->children === $this->canonicalize(...$this->children);
43    }
44
45    /**
46     * @param int|string $tagNumber
47     * @param int $class
48     * @param array $children
49     * @return SetType
50     */
51    public static function withTag($tagNumber, int $class, array $children = [])
52    {
53        $type = new static();
54        $type->children = $children;
55        $type->tagNumber = $tagNumber;
56        $type->taggingClass = $class;
57
58        return $type;
59    }
60}
61