+CFDataRef
+Certificate::sha256Hash()
+{
+ StLock<Mutex>_(mMutex);
+ if (!mSha256Hash) {
+ SecCertificateRef certRef = handle(false);
+ CFAllocatorRef allocRef = (certRef) ? CFGetAllocator(certRef) : NULL;
+ CSSM_DATA certData = data();
+ if (certData.Length == 0 || !certData.Data) {
+ MacOSError::throwMe(errSecDataNotAvailable);
+ }
+ const UInt8 *dataPtr = (const UInt8 *)certData.Data;
+ CFIndex dataLen = (CFIndex)certData.Length;
+ CFMutableDataRef digest = CFDataCreateMutable(allocRef, CC_SHA256_DIGEST_LENGTH);
+ CFDataSetLength(digest, CC_SHA256_DIGEST_LENGTH);
+ CCDigest(kCCDigestSHA256, dataPtr, dataLen, CFDataGetMutableBytePtr(digest));
+ mSha256Hash = digest;
+ }
+ return mSha256Hash; /* object is owned by our instance; caller should NOT release it */
+}
+
+