public function publicKey(): PublicKey
    {
        $algo = $this->algorithmIdentifier();
        switch ($algo->oid()) {
            // RSA
            case AlgorithmIdentifier::OID_RSA_ENCRYPTION:
                return RSA\RSAPublicKey::fromDER($this->_publicKeyData);
            // elliptic curve
            case AlgorithmIdentifier::OID_EC_PUBLIC_KEY:
                if (!$algo instanceof ECPublicKeyAlgorithmIdentifier) {
                    throw new \UnexpectedValueException("Not an EC algorithm.");
                }
                // ECPoint is directly mapped into public key data
                return new EC\ECPublicKey($this->_publicKeyData,
                    $algo->namedCurve());
        }
        throw new \RuntimeException(
            "Public key " . $algo->name() . " not supported.");
    }