added X509Certificate::equals()

This commit is contained in:
Guenter Obiltschnig 2016-02-25 22:15:32 +01:00
parent 53353d6ec1
commit fdd68b17f3
3 changed files with 21 additions and 0 deletions

View File

@ -130,6 +130,14 @@ public:
/// Returns true if verification against the issuer certificate
/// was successful, false otherwise.
bool equals(const X509Certificate& otherCertificate) const;
/// Checks whether the certificate is equal to
/// the other certificate, by comparing the hashes
/// of both certificates.
///
/// Returns true if both certificates are identical,
/// otherwise false.
const X509* certificate() const;
/// Returns the underlying OpenSSL certificate.

View File

@ -284,4 +284,12 @@ bool X509Certificate::issuedBy(const X509Certificate& issuerCertificate) const
}
bool X509Certificate::equals(const X509Certificate& otherCertificate) const
{
X509* pCert = const_cast<X509*>(_pCert);
X509* pOtherCert = const_cast<X509*>(otherCertificate.certificate());
return X509_cmp(pCert, pOtherCert) == 0;
}
} } // namespace Poco::Crypto

View File

@ -304,6 +304,11 @@ void CryptoTest::testCertificate()
// fails with recent OpenSSL versions:
// assert (cert.issuedBy(cert));
std::istringstream otherCertStream(APPINF_PEM);
X509Certificate otherCert(otherCertStream);
assert (cert.equals(otherCert));
}