Completed
Push — master ( 36c960...526274 )
by Sam
03:50
created

Parser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Jalle19\CertificateParser;
4
5
use AcmePhp\Ssl\Certificate;
6
use AcmePhp\Ssl\Exception\CertificateParsingException;
7
use AcmePhp\Ssl\Parser\CertificateParser;
8
use Jalle19\CertificateParser\Provider\ProviderInterface;
9
10
/**
11
 * Class Parser
12
 * @package Jalle19\CertificateParser
13
 */
14
class Parser
15
{
16
17
    /**
18
     * Attempts to parse the certificate using the specified provider
19
     *
20
     * @param ProviderInterface $provider
21
     *
22
     * @throws CertificateParsingException
23
     *
24
     * @return ParserResults
25
     */
26
    public function parse(ProviderInterface $provider)
27
    {
28
        $rawCertificate = $provider->getRawCertificate();
29
30
        // Convert the raw certificate to a PEM string and parse it
31
        openssl_x509_export($rawCertificate, $pemString);
32
        $parser            = new CertificateParser();
33
        $parsedCertificate = $parser->parse(new Certificate($pemString));
34
35
        return new ParserResults($parsedCertificate, openssl_x509_parse($rawCertificate));
36
    }
37
38
}
39