| 1 | <?php |
||
| 12 | */ |
||
| 13 | class Set extends Structure |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Constructor. |
||
| 17 | * |
||
| 18 | * @param Element ...$elements Any number of elements |
||
| 19 | */ |
||
| 20 | 12 | public function __construct(Element ...$elements) |
|
| 24 | 12 | } |
|
| 25 | |||
| 26 | /** |
||
| 27 | * Sort by canonical ascending order. |
||
| 28 | * |
||
| 29 | * Used for DER encoding of SET type. |
||
| 30 | * |
||
| 31 | * @return self |
||
| 32 | */ |
||
| 33 | 3 | public function sortedSet(): self |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Sort by encoding ascending order. |
||
| 51 | * |
||
| 52 | * Used for DER encoding of SET OF type. |
||
| 53 | * |
||
| 54 | * @return self |
||
| 55 | */ |
||
| 56 | 1 | public function sortedSetOf(): self |
|
| 57 | { |
||
| 58 | 1 | $obj = clone $this; |
|
| 59 | 1 | usort($obj->_elements, |
|
| 60 | function (Element $a, Element $b) { |
||
| 61 | 1 | $a_der = $a->toDER(); |
|
| 62 | 1 | $b_der = $b->toDER(); |
|
| 63 | 1 | return strcmp($a_der, $b_der); |
|
| 64 | 1 | }); |
|
| 65 | 1 | return $obj; |
|
| 68 |