From c776dad96f3e9f74a65db681e31f3d24c0e069c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Fri, 2 Dec 2016 12:58:10 -0500 Subject: [PATCH] crypto: add Certificate::getExpiration() --- include/opendht/crypto.h | 2 ++ src/crypto.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/opendht/crypto.h b/include/opendht/crypto.h index 82163aef..f961c59e 100644 --- a/include/opendht/crypto.h +++ b/include/opendht/crypto.h @@ -298,6 +298,8 @@ struct OPENDHT_PUBLIC Certificate { /** Read certificate alternative names */ std::vector<std::pair<NameType, std::string>> getAltNames() const; + std::chrono::system_clock::time_point getExpiration() const; + /** * Returns true if the certificate is marked as a Certificate Authority. */ diff --git a/src/crypto.cpp b/src/crypto.cpp index f40337c3..c00781bc 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -759,6 +759,15 @@ Certificate::addRevocationList(std::shared_ptr<RevocationList> list) revocation_lists.emplace_back(std::move(list)); } +std::chrono::system_clock::time_point +Certificate::getExpiration() const +{ + auto t = gnutls_x509_crt_get_expiration_time(cert); + if (t == (time_t)-1) + return std::chrono::system_clock::time_point::min(); + return std::chrono::system_clock::from_time_t(t); +} + PrivateKey PrivateKey::generate(unsigned key_length) { -- GitLab