Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
11 / 11 |
| SimpleDecoder | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
11 / 11 |
| decodeBase64 | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| decode | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
| decodeAttributesSet | |
100.00% |
1 / 1 |
1 | |
100.00% |
7 / 7 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Proton\IosReceiptParser\ASN1; |
| 4 | |
| 5 | use phpseclib3\File\ASN1; |
| 6 | |
| 7 | /** |
| 8 | * @internal |
| 9 | * @psalm-import-type AttributeSequence from \Proton\IosReceiptParser\Attribute\AttributeSet |
| 10 | */ |
| 11 | final class SimpleDecoder |
| 12 | { |
| 13 | public function decodeBase64(string $base64, $type) |
| 14 | { |
| 15 | return $this->decode(base64_decode($base64), $type); |
| 16 | } |
| 17 | |
| 18 | public function decode(string $binary, $type) |
| 19 | { |
| 20 | return ASN1::asn1map( |
| 21 | ASN1::decodeBER($binary)[0], |
| 22 | is_array($type) ? $type : ['type' => $type], |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @psalm-return list<AttributeSequence> |
| 28 | */ |
| 29 | public function decodeAttributesSet(string $binary): array |
| 30 | { |
| 31 | return $this->decode($binary, [ |
| 32 | 'type' => ASN1::TYPE_SET, |
| 33 | // Present of both 'min' and 'max' for ans1map means this is SetOf, |
| 34 | // so 'children' can be specification for the child template instead of per-child definitions |
| 35 | 'min' => -1, 'max' => 1, |
| 36 | 'children' => [ |
| 37 | 'type' => ASN1::TYPE_SEQUENCE, |
| 38 | 'children' => [ |
| 39 | 'type' => [ |
| 40 | 'type' => ASN1::TYPE_INTEGER, |
| 41 | ], |
| 42 | 'version' => [ |
| 43 | 'type' => ASN1::TYPE_INTEGER, |
| 44 | ], |
| 45 | 'value' => [ |
| 46 | 'type' => ASN1::TYPE_OCTET_STRING, |
| 47 | ], |
| 48 | ], |
| 49 | ], |
| 50 | ]); |
| 51 | } |
| 52 | } |