Class: KeyControl::KeyRing
- Inherits:
-
Object
- Object
- KeyControl::KeyRing
- Defined in:
- lib/key_control/key_ring.rb
Instance Attribute Summary collapse
-
#system ⇒ Object
readonly
Returns the value of attribute system.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Public: Get the data matching the passed description from the keychain.
-
#[]=(name, data) ⇒ Object
Public: Add the requested data to the keychain for the given description.
-
#delete(name) ⇒ Object
Public: Remove the data matching the passed description from the keychain.
-
#initialize(keyring) ⇒ KeyRing
constructor
Public: Get a new KeyControl::KeyRing instance with the specified keyring identifier.
-
#set_timeout(name, timeout) ⇒ Object
Public: Set a timeout for the data matching the passed description.
Constructor Details
#initialize(keyring) ⇒ KeyRing
Public: Get a new KeyControl::KeyRing instance with the specified keyring identifier.
keyring - A String or Integer identifying the desired keyring.
Returns a KeyControl::KeyRing instance.
13 14 15 16 |
# File 'lib/key_control/key_ring.rb', line 13 def initialize(keyring) @keyring = keyring @system = System.new end |
Instance Attribute Details
#system ⇒ Object (readonly)
Returns the value of attribute system.
5 6 7 |
# File 'lib/key_control/key_ring.rb', line 5 def system @system end |
Instance Method Details
#[](name) ⇒ Object
Public: Get the data matching the passed description from the keychain.
name - The description of the data for which to search.
Returns the requested data or nil.
33 34 35 36 37 38 |
# File 'lib/key_control/key_ring.rb', line 33 def [](name) handle = system.run(:search, "user", name, nil, @keyring) return nil if handle == -1 system.get(:read, handle) end |
#[]=(name, data) ⇒ Object
Public: Add the requested data to the keychain for the given description.
name - The description of the data. data - The data to store in the keychain.
Returns nothing.
24 25 26 |
# File 'lib/key_control/key_ring.rb', line 24 def []=(name, data) system.run(:add, "user", name, data, data.length, @keyring) end |
#delete(name) ⇒ Object
Public: Remove the data matching the passed description from the keychain.
name - The description of the data to remove.
Returns nothing.
45 46 47 48 |
# File 'lib/key_control/key_ring.rb', line 45 def delete(name) handle = system.run!(:search, "user", name, nil, @keyring) system.run!(:unlink, handle, @keyring) end |
#set_timeout(name, timeout) ⇒ Object
Public: Set a timeout for the data matching the passed description.
name - The description of the data for which to set a timeout. timeout - The timeout to set in seconds.
Returns nothing.
56 57 58 59 |
# File 'lib/key_control/key_ring.rb', line 56 def set_timeout(name, timeout) handle = system.run!(:search, "user", name, nil, @keyring) system.run!(:set_timeout, handle, timeout) end |