Completed
Pull Request — master (#591)
by thomas
22:54 queued 09:12
created

PublicKeyFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 25
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromHex() 0 4 1
A fromBuffer() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Key;
6
7
use BitWasp\Bitcoin\Crypto\EcAdapter\Adapter\EcAdapterInterface;
8
use BitWasp\Bitcoin\Crypto\EcAdapter\EcSerializer;
9
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface;
10
use BitWasp\Bitcoin\Crypto\EcAdapter\Serializer\Key\PublicKeySerializerInterface;
11
use BitWasp\Buffertools\Buffer;
12
use BitWasp\Buffertools\BufferInterface;
13
14
class PublicKeyFactory
15
{
16
    /**
17
     * @param string $hex
18
     * @param EcAdapterInterface|null $ecAdapter
19
     * @return PublicKeyInterface
20
     * @throws \Exception
21
     */
22 84
    public static function fromHex(string $hex, EcAdapterInterface $ecAdapter = null): PublicKeyInterface
23
    {
24 84
        return self::fromBuffer(Buffer::hex($hex), $ecAdapter);
25
    }
26
27
    /**
28
     * @param BufferInterface $buffer
29
     * @param EcAdapterInterface|null $ecAdapter
30
     * @return PublicKeyInterface
31
     */
32 106
    public static function fromBuffer(BufferInterface $buffer, EcAdapterInterface $ecAdapter = null): PublicKeyInterface
33
    {
34 106
        return EcSerializer::getSerializer(PublicKeySerializerInterface::class, true, $ecAdapter)
35 106
            ->parse($buffer)
36
        ;
37
    }
38
}
39