Completed
Pull Request — master (#334)
by thomas
147:16 queued 143:27
created

Signature::getBuffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Signature;
4
5
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Adapter\EcAdapter;
6
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Serializer\Signature\DerSignatureSerializer;
7
use BitWasp\Bitcoin\Serializable;
8
9
class Signature extends Serializable implements SignatureInterface
10
{
11
    /**
12
     * @var \GMP
13
     */
14
    private $r;
15
16
    /**
17
     * @var  \GMP
18
     */
19
    private $s;
20
21
    /**
22
     * @var EcAdapter
23
     */
24
    private $ecAdapter;
25
26
    /**
27
     * @var resource
28
     */
29
    private $secp256k1_sig;
30
31
    /**
32
     * @param EcAdapter $adapter
33
     * @param \GMP $r
34
     * @param \GMP $s
35
     * @param resource $secp256k1_ecdsa_signature_t
36
     */
37
    public function __construct(EcAdapter $adapter, \GMP $r, \GMP $s, $secp256k1_ecdsa_signature_t)
38
    {
39
        if (!is_resource($secp256k1_ecdsa_signature_t) ||
40
            !get_resource_type($secp256k1_ecdsa_signature_t) === SECP256K1_TYPE_SIG
41
        ) {
42
            throw new \InvalidArgumentException('Secp256k1\Signature\Signature expects ' . SECP256K1_TYPE_SIG . ' resource');
43
        }
44
45
        $this->secp256k1_sig = $secp256k1_ecdsa_signature_t;
46
        $this->ecAdapter = $adapter;
47
        $this->r = $r;
48
        $this->s = $s;
49
    }
50
51
    /**
52
     * @return \GMP
53
     */
54
    public function getR()
55
    {
56
        return $this->r;
57
    }
58
59
    /**
60
     * @return \GMP
61
     */
62
    public function getS()
63
    {
64
        return $this->s;
65
    }
66
67
    /**
68
     * @return resource
69
     */
70
    public function getResource()
71
    {
72
        return $this->secp256k1_sig;
73
    }
74
75
    /**
76
     * @return \BitWasp\Buffertools\BufferInterface
77
     */
78
    public function getBuffer()
79
    {
80
        return (new DerSignatureSerializer($this->ecAdapter))->serialize($this);
81
    }
82
}
83