CFDataRef ExtractPubKey()

in macos/macos.c [54:68]


CFDataRef ExtractPubKey(SecKeyRef pubKey) {
  CFDataRef val = NULL;
  CFDataRef res = NULL;
  CFDictionaryRef keyAttrs = SecKeyCopyAttributes(pubKey);
  if (CFDictionaryContainsKey(keyAttrs, kSecValueData) == true)
    val = (CFDataRef)CFDictionaryGetValue(keyAttrs, kSecValueData);

  if (val)
    res = CFDataCreateCopy(kCFAllocatorDefault, val);

  if (keyAttrs)
    CFRelease((CFTypeRef)keyAttrs);

  return res;
}