class SecretService::Item

Attributes

path[RW]

Public Class Methods

new(collection, path) click to toggle source
# File lib/secret_service/item.rb, line 6
def initialize(collection, path)
  @collection = collection
  @path = path
  @proxy = collection.service.get_proxy @path, IFACE[:item]
end

Public Instance Methods

attributes() click to toggle source
# File lib/secret_service/item.rb, line 41
def attributes
  get_property(:attributes)
end
attributes=(new_attrs) click to toggle source

TODO: this keeps throwing type errors

# File lib/secret_service/item.rb, line 46
def attributes= new_attrs
  set_property(:attributes, new_attrs)
end
created() click to toggle source
# File lib/secret_service/item.rb, line 16
def created
  Time.at get_property(:created)
end
delete() click to toggle source
# File lib/secret_service/item.rb, line 66
def delete
  prompt = @proxy.Delete
  return true if prompt_path == "/"
  @collection.service.prompt!(prompt_path)
end
get_property(name) click to toggle source
# File lib/secret_service/item.rb, line 54
def get_property name
  @proxy.Get(IFACE[:item], name.to_s.downcase.capitalize)[0]
end
get_secret() click to toggle source
# File lib/secret_service/item.rb, line 62
def get_secret
  secret_decode(@proxy.GetSecret(session[1]))
end
label() click to toggle source
# File lib/secret_service/item.rb, line 33
def label
  get_property(:label)
end
label=(new_label) click to toggle source
# File lib/secret_service/item.rb, line 37
def label= new_label
  set_property(:label, new_label)
end
lock!() click to toggle source
# File lib/secret_service/item.rb, line 24
def lock!
  locked, prompt_path = @collection.service.proxy.Lock [@path]
  return true if prompt_path == "/" and locked.include? @path

  # otherwise we have to handle the prompt
  @collection.service.prompt!(prompt_path)
  get_property(:locked)
end
locked?() click to toggle source
# File lib/secret_service/item.rb, line 20
def locked?
  get_property(:locked)
end
modified() click to toggle source
# File lib/secret_service/item.rb, line 12
def modified
  Time.at get_property(:modified)
end
secret_decode(secret_arr) click to toggle source

standards.freedesktop.org/secret-service/ch14.html#type-Secret

# File lib/secret_service/item.rb, line 73
def secret_decode secret_arr
  secret_struct = secret_arr[0]
  s = {}
  [:session, :params, :bytes, :mime].each do |x|
    s[x] = secret_struct.shift
  end

  secret_string = (s[:bytes].map {|x| x.chr}).join
  if(secret_string.respond_to? "encoding" and
     s[:mime] != "application/octet-stream")
    charset = s[:mime].match(/charset=(.+)/)[1]
    unless charset.nil?
      charset.upcase!.sub! /\AUTF([\w\d])/, "UTF-#{$1}"
      secret_string.force_encoding charset
    end
  end
  secret_string
end
session() click to toggle source
# File lib/secret_service/item.rb, line 58
def session
  @collection.session
end
set_property(name, new_val) click to toggle source
# File lib/secret_service/item.rb, line 50
def set_property name, new_val
  @proxy.Set(IFACE[:item], name.to_s.downcase.capitalize, new_val)
end