class SignatureVerifierImpl implements SignatureVerifier {

    @Override
    public boolean verify(String signature, String tppEncodedCert, Map<String, String> headers, String method, String url) {
        X509Certificate certificate = X509CertUtils.parse(
            CertificateUtils.normalizeCertificate(tppEncodedCert)
        );

        if (certificate == null) {
            log.warn("TPP Certificate couldn't be parsed!");
            return false;
        }

        Signature signatureData = Signature.fromString(signature);
        if (!isKeyIdValid(certificate, signatureData.getKeyId())) {
            log.warn("Key ID is invalid!");
            return false;
        }

        Map<String, String> headersMap = RequestHeaders.fromMap(headers).toMap();

        try {
            Verifier verifier = new Verifier(certificate.getPublicKey(), signatureData);
            return verifier.verify(method, url, headersMap);

        } catch (Exception e) {
            log.warn("Signature verification has an error: {}", e.getMessage());
            return false;
        }
    }

}