class KeyControl::KeyRing

Attributes

system[R]

Public Class Methods

new(keyring) click to toggle source

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.

# File lib/key_control/key_ring.rb, line 13
def initialize(keyring)
  @keyring = keyring
  @system = System.new
end

Public Instance Methods

[](name) click to toggle source

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.

# 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) click to toggle source

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.

# File lib/key_control/key_ring.rb, line 24
def []=(name, data)
  system.run(:add, "user", name, data, data.length, @keyring)
end
delete(name) click to toggle source

Public: Remove the data matching the passed description from the keychain.

name - The description of the data to remove.

Returns nothing.

# 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) click to toggle source

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.

# 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