Class: KeyControl::KeyRing

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

Instance Attribute Summary collapse

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.



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

#systemObject (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

#inspectObject

Public: Inspect the structure of and data stored in the current keyring.

Returns



43
44
45
# File 'lib/key_control/key_ring.rb', line 43

def inspect
  system.get(:describe, @keyring)
end