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

PublicKeyFactory::fromBuffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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