Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(934)

Unified Diff: net/cert/internal/trust_store_test_helpers.cc

Issue 2126803004: WIP: NSS trust store integration for path builder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert-command-line-path-builder-add_certpathbuilder
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cert/internal/trust_store_test_helpers.h ('k') | net/cert/internal/verify_certificate_chain.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/internal/trust_store_test_helpers.cc
diff --git a/net/cert/internal/trust_store_test_helpers.cc b/net/cert/internal/trust_store_test_helpers.cc
new file mode 100644
index 0000000000000000000000000000000000000000..df4bd09f1ece9f17347de41c1e1536389442dd85
--- /dev/null
+++ b/net/cert/internal/trust_store_test_helpers.cc
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/cert/internal/trust_store_test_helpers.h"
+
+#include "base/bind.h"
+#include "base/callback_helpers.h"
+#include "base/location.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/thread_task_runner_handle.h"
+
+namespace net {
+
+namespace {
+
+class StaticAsyncRequest : public TrustStore::Request {
+ public:
+ StaticAsyncRequest(const TrustStore::TrustCallback& callback)
+ : callback_(callback), weak_ptr_factory_(this) {}
+ ~StaticAsyncRequest() override = default;
+
+ void PostTrustCallback(bool trusted) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&StaticAsyncRequest::DoTrustCallback,
+ weak_ptr_factory_.GetWeakPtr(), trusted));
+ }
+
+ private:
+ void DoTrustCallback(bool trusted) {
+ base::ResetAndReturn(&callback_).Run(trusted);
+ // |this| may be deleted here.
+ }
+
+ TrustStore::TrustCallback callback_;
+ base::WeakPtrFactory<StaticAsyncRequest> weak_ptr_factory_;
+};
+
+}
+
+void AsyncTrustStoreStatic::IsTrustedCertificate(
+ scoped_refptr<ParsedCertificate> cert,
+ const TrustCallback& callback,
+ bool* out_trusted,
+ std::unique_ptr<TrustStore::Request>* out_req) const {
+ if (callback.is_null()) {
+ *out_trusted = false;
+ out_req->reset();
+ return;
+ }
+ std::unique_ptr<StaticAsyncRequest> req(new StaticAsyncRequest(callback));
+ std::unique_ptr<TrustStore::Request> unused_req;
+ bool is_trusted;
+ trust_store_static_.IsTrustedCertificate(cert, TrustCallback(), &is_trusted,
+ &unused_req);
+ DCHECK(!unused_req);
+ req->PostTrustCallback(is_trusted);
+ *out_req = std::move(req);
+}
+
+// CertIssuerSource implementation:
+void AsyncTrustStoreStatic::SyncGetIssuersOf(const ParsedCertificate* cert,
+ ParsedCertificateList* issuers) {
+ trust_store_static_.SyncGetIssuersOf(std::move(cert), issuers);
+}
+
+void AsyncTrustStoreStatic::AsyncGetIssuersOf(
+ scoped_refptr<ParsedCertificate> cert,
+ const IssuerCallback& callback,
+ std::unique_ptr<CertIssuerSource::Request>* out_req) {
+ trust_store_static_.AsyncGetIssuersOf(std::move(cert), callback, out_req);
+}
+
+TrustResultRecorder::TrustResultRecorder() = default;
+TrustResultRecorder::~TrustResultRecorder() = default;
+
+TrustStore::TrustCallback TrustResultRecorder::Callback() {
+ return base::Bind(&TrustResultRecorder::HandleResult, base::Unretained(this));
+}
+
+void TrustRequestDeleter(std::unique_ptr<TrustStore::Request>* req_owner,
+ base::Closure done_callback,
+ bool trusted) {
+ req_owner->reset();
+ done_callback.Run();
+}
+
+} // namespace net
« no previous file with comments | « net/cert/internal/trust_store_test_helpers.h ('k') | net/cert/internal/verify_certificate_chain.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698