Module: Keychain
- Defined in:
- lib/keychain.rb,
lib/keychain/version.rb,
lib/keychain/keychain.rb
Overview
top level constant for this library
Defined Under Namespace
Modules: Protocols Classes: AuthFailedError, DuplicateItemError, Error, InteractionNotAllowedError, Item, Keychain, NoSuchKeychainError, Scope, UserCancelledError
Constant Summary collapse
- VERSION =
The current version string
'0.1.2'
Class Method Summary collapse
-
.create(path, password = nil) ⇒ Keychain::Keychain
creates a new keychain file and adds it to the keychain search path ( SecKeychainCreate ).
-
.default ⇒ Keychain::Keychain
Gets the default keychain object ( SecKeychainCopyDefault ).
-
.generic_passwords ⇒ Keychain::Scope
Returns a scope for generic passwords in all keychains.
-
.internet_passwords ⇒ Keychain::Scope
Returns a scope for internet passwords contained in all keychains.
-
.open(path) ⇒ Keychain::Keychain
Opens the keychain file at the specified path and adds it to the keychain search path ( SecKeychainOpen ).
-
.user_interaction_allowed=(value) ⇒ Object
sets whether user interaction is allowed If false then operations that would require user interaction (for example prompting the user for a password to unlock a keychain) will raise InteractionNotAllowedError.
-
.user_interaction_allowed? ⇒ Boolean
Returns whether user interaction is allowed If false then operations that would require user interaction (for example prompting the user for a password to unlock a keychain) will raise InteractionNotAllowedError.
Class Method Details
.create(path, password = nil) ⇒ Keychain::Keychain
creates a new keychain file and adds it to the keychain search path ( SecKeychainCreate )
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/keychain.rb', line 20 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 |
.default ⇒ Keychain::Keychain
Gets the default keychain object ( SecKeychainCopyDefault )
41 42 43 44 45 46 47 |
# File 'lib/keychain.rb', line 41 def default out_buffer = FFI::MemoryPointer.new(:pointer) status = Sec.SecKeychainCopyDefault(out_buffer); Sec.check_osstatus(status) Keychain.new(out_buffer.read_pointer).release_on_gc end |
.generic_passwords ⇒ Keychain::Scope
Returns a scope for generic passwords in all keychains
74 75 76 |
# File 'lib/keychain.rb', line 74 def generic_passwords Scope.new(Sec::Classes::GENERIC) end |
.internet_passwords ⇒ Keychain::Scope
Returns a scope for internet passwords contained in all keychains
67 68 69 |
# File 'lib/keychain.rb', line 67 def internet_passwords Scope.new(Sec::Classes::INTERNET) end |
.open(path) ⇒ Keychain::Keychain
Opens the keychain file at the specified path and adds it to the keychain search path ( SecKeychainOpen )
Will succeed even if the file doesn’t exists (however most operations on the keychain will then fail)
56 57 58 59 60 61 62 |
# File 'lib/keychain.rb', line 56 def open(path) raise ArgumentError unless path out_buffer = FFI::MemoryPointer.new(:pointer) status = Sec.SecKeychainOpen(path,out_buffer); Sec.check_osstatus(status) Keychain.new(out_buffer.read_pointer).release_on_gc end |
.user_interaction_allowed=(value) ⇒ Object
sets whether user interaction is allowed If false then operations that would require user interaction (for example prompting the user for a password to unlock a keychain) will raise InteractionNotAllowedError
82 83 84 85 86 |
# File 'lib/keychain.rb', line 82 def user_interaction_allowed= value status = Sec.SecKeychainSetUserInteractionAllowed( value ? 1 : 0) Sec.check_osstatus(status) value end |
.user_interaction_allowed? ⇒ Boolean
Returns whether user interaction is allowed If false then operations that would require user interaction (for example prompting the user for a password to unlock a keychain) will raise InteractionNotAllowedError
92 93 94 95 96 97 |
# File 'lib/keychain.rb', line 92 def user_interaction_allowed? out_buffer = FFI::MemoryPointer.new(:uchar) status = Sec.SecKeychainGetUserInteractionAllowed(out_buffer) Sec.check_osstatus(status) out_buffer.read_uchar.nonzero? end |