Fix Telemetry media seek action flakiness.
[chromium-blink-merge.git] / net / cert / test_root_certs_openssl.cc
blob3d5cf3d72d17e0e72498c9188f3e0e8016aee0e1
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/cert/test_root_certs.h"
7 #include <openssl/err.h>
8 #include <openssl/x509v3.h>
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "crypto/openssl_util.h"
13 #include "net/cert/x509_certificate.h"
15 namespace net {
17 bool TestRootCerts::Add(X509Certificate* certificate) {
18 if (!X509_STORE_add_cert(X509Certificate::cert_store(),
19 certificate->os_cert_handle())) {
20 unsigned long error_code = ERR_peek_error();
21 if (ERR_GET_LIB(error_code) != ERR_LIB_X509 ||
22 ERR_GET_REASON(error_code) != X509_R_CERT_ALREADY_IN_HASH_TABLE) {
23 crypto::ClearOpenSSLERRStack(FROM_HERE);
24 return false;
26 ERR_clear_error();
29 empty_ = false;
30 return true;
33 void TestRootCerts::Clear() {
34 if (empty_)
35 return;
37 X509Certificate::ResetCertStore();
38 empty_ = true;
41 bool TestRootCerts::IsEmpty() const {
42 return empty_;
45 TestRootCerts::~TestRootCerts() {}
47 void TestRootCerts::Init() {
48 empty_ = true;
51 } // namespace net