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 |