views:

122

answers:

0

I'm trying to translate some of the following sample code into RubyCocoa :-

SecAccessRef createAccess(NSString *accessLabel)
{
    OSStatus err;
    SecAccessRef access=nil;
    NSArray *trustedApplications=nil;

    //Make an exception list of trusted applications; that is,
    // applications that are allowed to access the item without
    // requiring user confirmation:
    SecTrustedApplicationRef myself, someOther;

    //Create trusted application references; see SecTrustedApplications.h:
    err = SecTrustedApplicationCreateFromPath(NULL, &myself);
    err = SecTrustedApplicationCreateFromPath("/Applications/Mail.app",
                                                            &someOther);
    trustedApplications = [NSArray arrayWithObjects:(id)myself,
                                                    (id)someOther, nil];
    //Create an access object:
    err = SecAccessCreate((CFStringRef)accessLabel,
                            (CFArrayRef)trustedApplications, &access);
    if (err) return nil;

    return access;
}

This is what I have so far :-

require 'osx/cocoa'

include OSX

OSX.load_bridge_support_file('/path/to/Security.bridgesupport')

def create_access(access_label)
  err, myself = SecTrustedApplicationCreateFromPath(nil)
  err, some_other = SecTrustedApplicationCreateFromPath('/Applications/Mail.app')

  trusted_apps = NSArray.arrayWithObjects(myself, some_other, nil)

  err, access = SecAccessCreate(access_label, trusted_apps)

  return nil unless err == 0

  return access
end

However, I'm seeing two problems :-

  1. myself is set to nil
  2. the call to SecAccessCreate results in a segmentation fault

Does anyone know what I'm doing wrong?