O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading Data From an Item

Of course, once you have fetched the item, you can do all sorts of nifty things with it. For example, if you wanted to read the password, the account name, the description, and the modification date from an item, you would create an attribute list containing those attributes and call SecKeychainItemCopyContent():

OSStatus SecKeychainItemCopyContent (SecKeychainItemRef  itemRef,
                                           SecItemClass *itemClass, 
                               SecKeychainAttributeList *attrList,
                                                 UInt32 *length, 
                                                   void **outData);

Note that here the attrList is specifying what data you want and is also acting as a receptacle. Add these functions to dumpem.m:

/​/​ ​G​i​v​e​n​ ​a​ ​c​a​r​b​o​n​-​s​t​y​l​e​ ​f​o​u​r​ ​c​h​a​r​a​c​t​e​r​ ​c​o​d​e​,​ ​m​a​k​e​ ​a​ ​C​ ​s​t​r​i​n​g​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required