Class: Keychain::Keychain
- Defined in:
- lib/keychain/keychain.rb
Overview
Wrapper class for individual keychains. Corresponds to a SecKeychainRef
Instance Method Summary collapse
-
#delete ⇒ Object
Removes the keychain from the search path and deletes the corresponding file (SecKeychainDelete).
- #exists? ⇒ Boolean
-
#generic_passwords ⇒ Keychain::Scope
Returns a scope for generic passwords contained in this keychain.
-
#inspect ⇒ String
returns a description of the keychain.
-
#internet_passwords ⇒ Keychain::Scope
Returns a scope for internet passwords contained in this keychain.
-
#lock! ⇒ Object
Locks the keychain.
-
#lock_interval ⇒ Boolean
Returns the duration (in seconds) after which the keychain will be locked.
-
#lock_interval=(value) ⇒ Object
Sets the duration (in seconds) after which the keychain will be locked.
-
#lock_on_sleep=(value) ⇒ Object
Set whether the keychain will be locked if the machine goes to sleep.
-
#lock_on_sleep? ⇒ Boolean
Returns whether the keychain will be locked if the machine goes to sleep.
-
#locked? ⇒ Boolean
Returns whether the keychain is locked.
-
#path ⇒ String
Returns the path at which the keychain is stored.
-
#readable? ⇒ Boolean
Returns whether the keychain is readable.
-
#unlock!(password = nil) ⇒ Object
Unlocks the keychain.
-
#writeable? ⇒ Boolean
Returns whether the keychain is writable.
Methods inherited from Sec::Base
Instance Method Details
#delete ⇒ Object
Removes the keychain from the search path and deletes the corresponding file (SecKeychainDelete)
96 97 98 99 100 |
# File 'lib/keychain/keychain.rb', line 96 def delete status = Sec.SecKeychainDelete(self) Sec.check_osstatus(status) self end |
#exists? ⇒ Boolean
156 157 158 159 160 161 162 163 |
# File 'lib/keychain/keychain.rb', line 156 def exists? begin readable? true rescue NoSuchKeychainError false end end |
#generic_passwords ⇒ Keychain::Scope
Returns a scope for generic passwords contained in this keychain
82 83 84 |
# File 'lib/keychain/keychain.rb', line 82 def generic_passwords Scope.new(Sec::Classes::GENERIC, self) end |
#inspect ⇒ String
returns a description of the keychain
88 89 90 |
# File 'lib/keychain/keychain.rb', line 88 def inspect "<SecKeychain 0x#{@ptr.address.to_s(16)}: #{path}>" end |
#internet_passwords ⇒ Keychain::Scope
Returns a scope for internet passwords contained in this keychain
75 76 77 |
# File 'lib/keychain/keychain.rb', line 75 def internet_passwords Scope.new(Sec::Classes::INTERNET, self) end |
#lock! ⇒ Object
Locks the keychain
120 121 122 123 |
# File 'lib/keychain/keychain.rb', line 120 def lock! status = Sec.SecKeychainLock(self) Sec.check_osstatus status end |
#lock_interval ⇒ Boolean
Returns the duration (in seconds) after which the keychain will be locked
52 53 54 |
# File 'lib/keychain/keychain.rb', line 52 def lock_interval get_settings[:lock_interval] end |
#lock_interval=(value) ⇒ Object
Sets the duration (in seconds) after which the keychain will be locked
68 69 70 |
# File 'lib/keychain/keychain.rb', line 68 def lock_interval= value put_settings(get_settings.tap {|s| s[:lock_interval] = value}) end |
#lock_on_sleep=(value) ⇒ Object
Set whether the keychain will be locked if the machine goes to sleep
60 61 62 |
# File 'lib/keychain/keychain.rb', line 60 def lock_on_sleep= value put_settings(get_settings.tap {|s| s[:lock_on_sleep] = value ? 1 : 0}) end |
#lock_on_sleep? ⇒ Boolean
Returns whether the keychain will be locked if the machine goes to sleep
44 45 46 |
# File 'lib/keychain/keychain.rb', line 44 def lock_on_sleep? get_settings[:lock_on_sleep] != 0 end |
#locked? ⇒ Boolean
Returns whether the keychain is locked
140 141 142 |
# File 'lib/keychain/keychain.rb', line 140 def locked? !status_flag?(:kSecUnlockStateStatus) end |
#path ⇒ String
Returns the path at which the keychain is stored
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/keychain/keychain.rb', line 107 def path out_buffer = FFI::MemoryPointer.new(:uchar, 2048) io_size = FFI::MemoryPointer.new(:uint32) io_size.put_uint32(0, out_buffer.size) status = Sec.SecKeychainGetPath(self,io_size, out_buffer) Sec.check_osstatus(status) out_buffer.read_string(io_size.get_uint32(0)).force_encoding(Encoding::UTF_8) end |
#readable? ⇒ Boolean
Returns whether the keychain is readable
146 147 148 |
# File 'lib/keychain/keychain.rb', line 146 def readable? status_flag?(:kSecReadPermStatus) end |
#unlock!(password = nil) ⇒ Object
Unlocks the keychain
128 129 130 131 132 133 134 135 136 |
# File 'lib/keychain/keychain.rb', line 128 def unlock! password=nil if password password = password.encode(Encoding::UTF_8) status = Sec.SecKeychainUnlock self, password.bytesize, password, 1 else status = Sec.SecKeychainUnlock self, 0, nil, 0 end Sec.check_osstatus status end |
#writeable? ⇒ Boolean
Returns whether the keychain is writable
152 153 154 |
# File 'lib/keychain/keychain.rb', line 152 def writeable? status_flag?(:kSecWritePermStatus) end |