Class: Sec::Base Abstract
- Inherits:
-
CF::Base
- Object
- CF::Base
- Sec::Base
- Defined in:
- lib/keychain/sec.rb
Overview
This class is abstract.
The base class of all CF types from the security framework
Direct Known Subclasses
Keychain::Access, Keychain::Certificate, Keychain::Identity, Keychain::Item, Keychain::Key, Keychain::Keychain, Keychain::TrustedApplication
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ptr) ⇒ Base
constructor
A new instance of Base.
-
#keychain ⇒ Keychain::Keychain
Returns the keychain the item is in.
- #load_attributes ⇒ Object
- #update_self_from_dictionary(cf_dict) ⇒ Object
Constructor Details
#initialize(ptr) ⇒ Base
Returns a new instance of Base.
133 134 135 136 |
# File 'lib/keychain/sec.rb', line 133 def initialize(ptr) super @attributes = {} end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
113 114 115 |
# File 'lib/keychain/sec.rb', line 113 def attributes @attributes end |
Class Method Details
.define_attributes(attr_map) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# 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 |
Instance Method Details
#keychain ⇒ Keychain::Keychain
Returns the keychain the item is in
150 151 152 153 154 155 |
# 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 ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# 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) ⇒ Object
138 139 140 141 142 143 144 145 |
# 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 |