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

Unified Diff: net/base/temporary_root_certs_mac.cc

Issue 4646001: Implement LoadTemporaryRoot for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/net/base
Patch Set: Feedback from phajdan.jr and bulach Created 10 years, 1 month 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
Index: net/base/temporary_root_certs_mac.cc
diff --git a/net/base/temporary_root_certs_mac.cc b/net/base/temporary_root_certs_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..92216e4719aeab39a1488a0e55b07db9f310df58
--- /dev/null
+++ b/net/base/temporary_root_certs_mac.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2010 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/base/temporary_root_certs.h"
+
+#include <Security/Security.h>
+
+#include "net/base/x509_certificate.h"
+
+namespace net {
+
+namespace {
+
+Boolean OurSecCertificateEqual(const void* value1, const void* value2) {
+ if (CFGetTypeID(value1) != SecCertificateGetTypeID() ||
+ CFGetTypeID(value2) != SecCertificateGetTypeID())
+ return CFEqual(value1, value2);
+ return X509Certificate::IsSameOSCert(
+ reinterpret_cast<SecCertificateRef>(const_cast<void*>(value1)),
+ reinterpret_cast<SecCertificateRef>(const_cast<void*>(value2)));
bulach 2010/11/09 16:21:09 indent+2 the 20-21
+}
+
+const void* DummyRetain(CFAllocatorRef unused, const void* value) {
bulach 2010/11/09 16:21:09 maybe RetainWrapper?
+ return CFRetain(value);
+}
+
+void DummyRelease(CFAllocatorRef unused, const void* value) {
bulach 2010/11/09 16:21:09 maybe ReleaseWrapper?
+ CFRelease(value);
+}
+
+// CFEqual prior to 10.6 only performed pointer checks on SecCertificateRefs,
+// rather than checking if they were the same (logical) certificate, so a
+// custom structure is used for the array callbacks.
+static CFArrayCallBacks kCertArrayCallbacks = {
bulach 2010/11/09 16:21:09 const? also, since it's in a local namespace, coul
+ 0, /* version */
wtc 2010/11/16 23:24:01 Nit: use C++ style comment: 0, // version
+ DummyRetain,
+ DummyRelease,
+ CFCopyDescription,
+ OurSecCertificateEqual
+};
+
+} // namespace
+
+bool TemporaryRootCerts::Add(X509Certificate* certificate) {
+ if (CFArrayContainsValue(temporary_roots_,
+ CFRangeMake(0, CFArrayGetCount(temporary_roots_)),
+ certificate->os_cert_handle()))
+ return true;
+ CFArrayAppendValue(temporary_roots_, certificate->os_cert_handle());
+ return true;
+}
+
+void TemporaryRootCerts::Remove(X509Certificate* certificate) {
+ CFIndex cert_index = CFArrayGetFirstIndexOfValue(
+ temporary_roots_,
+ CFRangeMake(0, CFArrayGetCount(temporary_roots_)),
+ certificate->os_cert_handle());
+ if (cert_index == -1)
+ return;
+ CFArrayRemoveValueAtIndex(temporary_roots_, cert_index);
+}
+
+TemporaryRootCerts::TemporaryRootCerts() {
+ temporary_roots_.reset(CFArrayCreateMutable(kCFAllocatorDefault, 0,
+ &kCertArrayCallbacks));
+}
+
+TemporaryRootCerts::~TemporaryRootCerts() {
+}
+
+bool TemporaryRootCerts::IsEmpty() const {
+ return CFArrayGetCount(temporary_roots_) == 0;
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698