<?php

namespace Buckhill\U2F\Cert;

class Attestation
{
    protected $cert;
    protected $parsed = [];

    public function __construct($cert)
    {
        $this->cert = $cert;

        $this->parse();
    }


    /**
     * @return array
     */
    public function toArray()
    {
        return $this->parsed;
    }

    /**
     * @return $this
     */
    protected function parse()
    {
        $parsed = openssl_x509_parse($this->cert);

        if(!is_array($parsed))
        {
            throw new \UnexpectedValueException(sprintf("Unable to parse the attestation certificate. Error reported: %s", openssl_error_string()));
        }

        $this->parsed = $parsed;

        return $this;
    }
}