Module: PkeyReader

Included in:
Inspec::Resources::RsaKey
Defined in:
lib/inspec/utils/pkey_reader.rb

Instance Method Summary collapse

Instance Method Details

#raise_if_unset(passphrase) ⇒ Object



12
13
14
15
16
# File 'lib/inspec/utils/pkey_reader.rb', line 12

def raise_if_unset(passphrase)
  if passphrase.is_a? Inspec::Input::NO_VALUE_SET
    raise Inspec::Exceptions::ResourceFailed, "Please provide a value for input for openssl key passphrase"
  end
end

#read_pkey(filecontent, passphrase) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/inspec/utils/pkey_reader.rb', line 4

def read_pkey(filecontent, passphrase)
  raise_if_unset(passphrase)

  OpenSSL::PKey.read(filecontent, passphrase)
rescue OpenSSL::PKey::PKeyError
  raise Inspec::Exceptions::ResourceFailed, "passphrase error"
end