DerSignatureSerializer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 3 1
A serialize() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Mdanter\Ecc\Serializer\Signature;
5
6
use Mdanter\Ecc\Crypto\Signature\SignatureInterface;
7
8
class DerSignatureSerializer implements DerSignatureSerializerInterface
9
{
10
    /**
11
     * @var Der\Parser
12
     */
13
    private $parser;
14
15
    /**
16
     * @var Der\Formatter
17
     */
18
    private $formatter;
19
20
    public function __construct()
21
    {
22
        $this->parser = new Der\Parser();
23
        $this->formatter = new Der\Formatter();
24
    }
25
26
    /**
27
     * @param SignatureInterface $signature
28
     * @return string
29
     */
30
    public function serialize(SignatureInterface $signature): string
31
    {
32
        return $this->formatter->serialize($signature);
33
    }
34
35
    /**
36
     * @param string $binary
37
     * @return SignatureInterface
38
     * @throws \FG\ASN1\Exception\ParserException
39
     */
40
    public function parse(string $binary): SignatureInterface
41
    {
42
        return $this->parser->parse($binary);
43
    }
44
}
45