Method: PKCS11::Session#find_objects

Defined in:
lib/pkcs11/session.rb

#find_objects(template = {}) ⇒ Array<PKCS11::Object>

Convenience method for the #C_FindObjectsInit, #C_FindObjects, #C_FindObjectsFinal cycle.

  • If called with block, it iterates over all found objects.

  • If called without block, it returns with an array of all found Object instances.

Examples:

prints subject of all certificates stored in the token:

session.find_objects(CLASS:  PKCS11::CKO_CERTIFICATE) do |obj|
  p OpenSSL::X509::Name.new(obj[:SUBJECT])
end

Returns:


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pkcs11/session.rb', line 115

def find_objects(template={})
  all_objs = [] unless block_given?
  C_FindObjectsInit(template)
  begin
    loop do
      objs = C_FindObjects(20)
      break if objs.empty?
      if block_given?
        objs.each{|obj| yield obj }
      else
        all_objs += objs
      end
    end
  ensure
    C_FindObjectsFinal()
  end
  return all_objs
end