Skip to content

Instantly share code, notes, and snippets.

@iolate
Created April 10, 2022 11:38
Show Gist options
  • Save iolate/eddf4270361f64b57f0e86ac67125d54 to your computer and use it in GitHub Desktop.
Save iolate/eddf4270361f64b57f0e86ac67125d54 to your computer and use it in GitHub Desktop.
// Method 1: Copy
let certificate = SecCertificateCreateWithData(kCFAllocatorDefault, derData as CFData)
// Method 2: No Copy
cert.withUnsafeBytes { unsafeBytes in
let bytes = unsafeBytes.bindMemory(to: UInt8.self).baseAddress!
let cFData = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, bytes, unsafeBytes.count, kCFAllocatorNull)!
let certificate = SecCertificateCreateWithData(kCFAllocatorDefault, cFData)
}
// * certificate is nil if cert is not valid DER-encoded X.509 certificate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment