class Sec::Base

The base class of all CF types from the security framework

@abstract

Attributes

attributes[R]

Public Class Methods

define_attributes(attr_map) click to toggle source
# File lib/keychain/sec.rb, line 120
def self.define_attributes(attr_map)
  attr_map.values.each do |ruby_name|
    unless method_defined?(ruby_name)
      define_method ruby_name do
        self.attributes[ruby_name]
      end
      define_method ruby_name.to_s+'=' do |value|
        self.attributes[ruby_name] = value
      end
    end
  end
end
new(ptr) click to toggle source
Calls superclass method
# File lib/keychain/sec.rb, line 133
def initialize(ptr)
  super
  @attributes = {}
end
register_type(type_name) click to toggle source
# File lib/keychain/sec.rb, line 115
def self.register_type(type_name)
  Sec.attach_function "#{type_name}GetTypeID", [], CF.find_type(:cftypeid)
  @@type_map[Sec.send("#{type_name}GetTypeID")] = self
end

Public Instance Methods

keychain() click to toggle source

Returns the keychain the item is in

@return [Keychain::Keychain]

# File lib/keychain/sec.rb, line 150
def keychain
  out = FFI::MemoryPointer.new :pointer
  status = Sec.SecKeychainItemCopyKeychain(self,out)
  Sec.check_osstatus(status)
  CF::Base.new(out.read_pointer).release_on_gc
end
load_attributes() click to toggle source
# File lib/keychain/sec.rb, line 157
def load_attributes
  result = FFI::MemoryPointer.new :pointer
  status = Sec.SecItemCopyMatching({Sec::Query::SEARCH_LIST => [self.keychain],
                                    Sec::Query::ITEM_LIST => [self],
                                    Sec::Query::CLASS => self.klass,
                                    Sec::Query::RETURN_ATTRIBUTES => true,
                                    Sec::Query::RETURN_REF => false}.to_cf, result)
  Sec.check_osstatus(status)

  cf_dict = CF::Base.typecast(result.read_pointer).release_on_gc
  update_self_from_dictionary(cf_dict)
end
update_self_from_dictionary(cf_dict) click to toggle source
# File lib/keychain/sec.rb, line 138
def update_self_from_dictionary(cf_dict)
  @attributes = cf_dict.inject({}) do |memo, (k,v)|
    if ruby_name = self.class::ATTR_MAP[k]
      memo[ruby_name] = v.to_ruby
    end
    memo
  end
end