macOS documentation for structs in Security.h

前提是你 提交于 2019-12-12 15:07:02

问题


I'm trying to use the Security.h macOS framework via Java and JNA. That means I need to reconstruct certain structs as Java classes.

The problem is, when I look at the docs for a struct (this one, for example), all I see is a brief description of the struct without any mention of its fields. Where can I get a full description of a struct in Apple's documentation?


回答1:


For a quick look, you can find the headers on Apple's open source site, but it's difficult to navigate, especially as the headers are under different locations depending on the version of the OS you want to check. In all cases I've found it's defined in SecBase.h. For example here is the one for latest macOS.

And there you get this:

typedef struct CF_BRIDGED_TYPE(id) SECTYPE(SecKeychainItem) *SecKeychainItemRef;

So you'll probably need other headers to track down the exact fields of the struct. A better way to do that would be to install XCode with frameworks for the OS you want, and you'll get the headers on your local system. For example:

$ ls /Applications/Xcode.app/Contents/Developer/Platforms/*.platform/Developer/SDKs/*.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator9.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator2.2.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h

I don't have a good solution with the online docs, though.

Another way, from memory it was more helpful for the task of recreating the struct in Java for JNA, would be to build a minimal C program (But I'm not sure how to do that on macOS, linking with Security framework, perhaps you do), and give it to gdb to print the structure layout using ptype:

(gdb) whatis v
type = struct complex
(gdb) ptype v
type = struct complex {
    double real;
    double imag;
}

But as noted in comments, if we try this here, we get this:

(gdb) ptype SecKeychainItemRef
type = struct OpaqueSecKeychainItemRef {
  <incomplete type>
}

I'm afraid this symbol is voluntarily made opaque... Confirmed by Brendan in comments:

every macOS type I can think of that ends in Ref is an opaque type (really a pointer), only meant to be passed to functions

Here is a debug session with Xcode:



来源:https://stackoverflow.com/questions/43949920/macos-documentation-for-structs-in-security-h

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!