Conditions | 6 |
Paths | 5 |
Total Lines | 25 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | public function parse(string $binary): SignatureInterface |
||
21 | { |
||
22 | $offsetIndex = 0; |
||
23 | $asnObject = ASNObject::fromBinary($binary, $offsetIndex); |
||
24 | |||
25 | if ($offsetIndex != strlen($binary)) { |
||
26 | throw new SignatureDecodeException('Invalid data.'); |
||
27 | } |
||
28 | |||
29 | // Set inherits from Sequence, so use getType! |
||
30 | if ($asnObject->getType() !== Identifier::SEQUENCE) { |
||
31 | throw new SignatureDecodeException('Invalid tag for sequence.'); |
||
32 | } |
||
33 | |||
34 | if ($asnObject->getNumberofChildren() !== 2) { |
||
|
|||
35 | throw new SignatureDecodeException('Invalid data.'); |
||
36 | } |
||
37 | |||
38 | if (!($asnObject[0] instanceof Integer && $asnObject[1] instanceof Integer)) { |
||
39 | throw new SignatureDecodeException('Invalid data.'); |
||
40 | } |
||
41 | |||
42 | return new Signature( |
||
43 | gmp_init($asnObject[0]->getContent(), 10), |
||
44 | gmp_init($asnObject[1]->getContent(), 10) |
||
45 | ); |
||
48 |