Class: KeyControl::KeyRing

Inherits:
Object
  • Object
show all
Defined in:
lib/key_control/key_ring.rb

Instance Method Summary collapse

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.



11
12
13
14
# File 'lib/key_control/key_ring.rb', line 11

def initialize(keyring)
  @keyring = keyring
  @system = System.new
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.



31
32
33
34
35
36
37
38
39
40
# File 'lib/key_control/key_ring.rb', line 31

def [](name)
  handle = execute(:search, "user", name, nil, @keyring)
  return nil if handle == -1

  length = execute(:read, handle, "", 0)
  buffer = "0" * length
  execute(:read, handle, buffer, length)

  buffer
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.



22
23
24
# File 'lib/key_control/key_ring.rb', line 22

def []=(name, data)
  execute(:add, "user", name, data, data.length, @keyring)
end