@@ -47,7 +47,10 @@ template <typename T>
47
47
class cf_ref
48
48
{
49
49
public:
50
- cf_ref (T v) : value(v) {}
50
+ cf_ref (T v) : value(v)
51
+ {
52
+ static_assert (sizeof (cf_ref<T>) == sizeof (T), " Code assumes just a wrapper, see usage in CFArrayCreate below." );
53
+ }
51
54
cf_ref () : value(nullptr ) {}
52
55
cf_ref (cf_ref &&other) : value(other.value) { other.value = nullptr ; }
53
56
@@ -77,8 +80,7 @@ bool verify_X509_cert_chain(const std::vector<std::string> &certChain, const std
77
80
std::vector<cf_ref<SecCertificateRef>> certs;
78
81
for (const auto & certBuf : certChain)
79
82
{
80
- cf_ref<CFDataRef> certDataRef;
81
- certDataRef.get () = CFDataCreateWithBytesNoCopy (kCFAllocatorDefault ,
83
+ cf_ref<CFDataRef> certDataRef = CFDataCreateWithBytesNoCopy (kCFAllocatorDefault ,
82
84
reinterpret_cast <const unsigned char *>(certBuf.c_str ()),
83
85
certBuf.size (),
84
86
kCFAllocatorNull );
@@ -94,8 +96,7 @@ bool verify_X509_cert_chain(const std::vector<std::string> &certChain, const std
94
96
}
95
97
certs.push_back (std::move (certObj));
96
98
}
97
- cf_ref<CFArrayRef> certsArray;
98
- certsArray.get () = CFArrayCreate (kCFAllocatorDefault , const_cast <const void **>(reinterpret_cast <void **>(&certs[0 ])), certs.size (), nullptr );
99
+ cf_ref<CFArrayRef> certsArray = CFArrayCreate (kCFAllocatorDefault , const_cast <const void **>(reinterpret_cast <void **>(&certs[0 ])), certs.size (), nullptr );
99
100
if (certsArray.get () == nullptr )
100
101
{
101
102
return false ;
@@ -104,17 +105,15 @@ bool verify_X509_cert_chain(const std::vector<std::string> &certChain, const std
104
105
// Create trust management object with certificates and SSL policy.
105
106
// Note: SecTrustCreateWithCertificates expects the certificate to be
106
107
// verified is the first element.
107
- cf_ref<CFStringRef> cfHostName;
108
- cfHostName.get () = CFStringCreateWithCStringNoCopy (kCFAllocatorDefault ,
108
+ cf_ref<CFStringRef> cfHostName = CFStringCreateWithCStringNoCopy (kCFAllocatorDefault ,
109
109
hostName.c_str (),
110
110
kCFStringEncodingASCII ,
111
111
kCFAllocatorNull );
112
112
if (cfHostName.get () == nullptr )
113
113
{
114
114
return false ;
115
115
}
116
- cf_ref<SecPolicyRef> policy;
117
- policy.get () = SecPolicyCreateSSL (true /* client side */ , cfHostName.get ());
116
+ cf_ref<SecPolicyRef> policy = SecPolicyCreateSSL (true /* client side */ , cfHostName.get ());
118
117
cf_ref<SecTrustRef> trust;
119
118
OSStatus status = SecTrustCreateWithCertificates (certsArray.get (), policy.get (), &trust.get ());
120
119
if (status == noErr)
0 commit comments