Formatter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 3 1
A toAsn() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Mdanter\Ecc\Serializer\Signature\Der;
5
6
use FG\ASN1\Universal\Integer;
7
use FG\ASN1\Universal\Sequence;
8
use Mdanter\Ecc\Crypto\Signature\SignatureInterface;
9
10
class Formatter
11
{
12
    /**
13
     * @param SignatureInterface $signature
14
     * @return Sequence
15
     */
16
    public function toAsn(SignatureInterface $signature): Sequence
17
    {
18
        return new Sequence(
19
            new Integer(gmp_strval($signature->getR(), 10)),
0 ignored issues
show
Bug introduced by
gmp_strval($signature->getR(), 10) of type string is incompatible with the type integer expected by parameter $value of FG\ASN1\Universal\Integer::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
            new Integer(/** @scrutinizer ignore-type */ gmp_strval($signature->getR(), 10)),
Loading history...
20
            new Integer(gmp_strval($signature->getS(), 10))
21
        );
22
    }
23
24
    /**
25
     * @param SignatureInterface $signature
26
     * @return string
27
     */
28
    public function serialize(SignatureInterface $signature): string
29
    {
30
        return $this->toAsn($signature)->getBinary();
31
    }
32
}
33