Module: Ccrypto::Ruby::PEMStore::ClassMethods

Defined in:
lib/ccrypto/ruby/keybundle_store/pem_store.rb

Instance Method Summary collapse

Instance Method Details

#from_pem(input, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ccrypto/ruby/keybundle_store/pem_store.rb', line 28

def from_pem(input, &block)

  begin
    # try with no password first to check if the keystore is really encrypted
    # If not the library will prompt at command prompt which might halt the flow of program
    pKey = OpenSSL::PKey.read(input,"")
    ECCKeyBundle.new(pKey)
  rescue OpenSSL::PKey::PKeyError => ex
    raise PEMStoreException, "block is required" if not block
    pass = block.call(:store_pass)
    begin
      pKey = OpenSSL::PKey.read(input, pass)
      ECCKeyBundle.new(pKey)
    rescue OpenSSL::PKey::PKeyError => exx
      raise PEMStoreException, exx
    end
  end

end

#is_pem?(input) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ccrypto/ruby/keybundle_store/pem_store.rb', line 12

def is_pem?(input)
  if is_empty?(input)
    false
  else
    begin
      (input =~ /BEGIN/) != nil
    rescue ArgumentError => ex
      if ex.message =~ /invalid byte sequence/
        false
      else
        raise KeypairEngineException, ex
      end
    end
  end
end