Method: Keychain.create

Defined in:
lib/keychain.rb

.create(path, password = nil) ⇒ Keychain::Keychain

creates a new keychain file and adds it to the keychain search path ( SecKeychainCreate )

See developer.apple.com/library/mac/documentation/security/Reference/keychainservices/Reference/reference.html#//apple_ref/c/func/SecKeychainCreate

Parameters:

  • path (String)

    The path to the keychain file to create If it is not absolute it is interpreted relative to ~/Library/Keychains

  • password (optional, String) (defaults to: nil)

    The password to use for the keychain. if not supplied, the user will be prompted for a password

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/keychain.rb', line 23

def create(path, password=nil)
  path = path.encode(Encoding::UTF_8)
  out_buffer = FFI::MemoryPointer.new(:pointer)

  if password
    password = password.encode(Encoding::UTF_8)
    status = Sec.SecKeychainCreate(path, password.bytesize, FFI::MemoryPointer.from_string(password), 0,
                                      nil, out_buffer)

  else
    status = Sec.SecKeychainCreate(path, 0, nil, 1, nil, out_buffer)
  end

  Sec.check_osstatus(status)
  Keychain.new(out_buffer.read_pointer).release_on_gc
end