lib/keychain/keychain.rb in ruby-keychain-0.1.1 vs lib/keychain/keychain.rb in ruby-keychain-0.1.2

- old
+ new

@@ -6,10 +6,13 @@ attach_function 'SecKeychainGetPath', [:keychainref, :pointer, :pointer], :osstatus attach_function 'SecKeychainCreate', [:string, :uint32, :pointer, :char, :pointer, :pointer], :osstatus attach_function 'SecItemCopyMatching', [:pointer, :pointer], :osstatus + attach_function 'SecKeychainSetSearchList', [:pointer], :osstatus + attach_function 'SecKeychainCopySearchList', [:pointer], :osstatus + #@private class KeychainSettings < FFI::Struct layout :version, :uint32, :lock_on_sleep, :uchar, :use_lock_interval, :uchar, #apple ignores this @@ -38,9 +41,22 @@ # Wrapper class for individual keychains. Corresponds to a SecKeychainRef # class Keychain < Sec::Base register_type 'SecKeychain' + # Add the keychain to the default searchlist + # + # + def add_to_search_list + list = FFI::MemoryPointer.new(:pointer) + status = Sec.SecKeychainCopySearchList(list) + Sec.check_osstatus(status) + ruby_list = CF::Base.typecast(list.read_pointer).to_ruby + ruby_list << self unless ruby_list.include?(self) + status = Sec.SecKeychainSetSearchList(CF::Array.immutable(ruby_list)) + Sec.check_osstatus(status) + self + end # Returns whether the keychain will be locked if the machine goes to sleep # # @return [Boolean] # def lock_on_sleep? \ No newline at end of file