inspec/lib/utils/pkey_reader.rb
Omar J. Irizarry a278ae921b Require a key attribute for the key_rsa resource (#2891)
Bug Fix #2865
* Defining an attribute without a default value generates a stacktrace
* Fix string quotes
* Moved logic out of the initilize method.
* Refactoring for better clarity.
* Fixing trailing white spaces
Signed-off-by: Omar J Irizarry <irizarry_omar_j@network.lilly.com>
2018-04-12 16:15:04 -04:00

15 lines
454 B
Ruby

module PkeyReader
def read_pkey(filecontent, passphrase)
raise_if_default(passphrase)
OpenSSL::PKey.read(filecontent, passphrase)
rescue OpenSSL::PKey::PKeyError
raise Inspec::Exceptions::ResourceFailed, 'passphrase error'
end
def raise_if_default(passphrase)
if passphrase.is_a? Inspec::Attribute::DEFAULT_ATTRIBUTE
raise Inspec::Exceptions::ResourceFailed, 'Please provide default value for attribute'
end
end
end