Class: Inspec::Resources::RsaKey

Inherits:
Object
  • Object
show all
Includes:
FileReader, PkeyReader
Defined in:
lib/inspec/resources/key_rsa.rb

Instance Method Summary collapse

Methods included from PkeyReader

#raise_if_unset, #read_pkey

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(keypath, passphrase = nil) ⇒ RsaKey

Returns a new instance of RsaKey.



26
27
28
29
30
# File 'lib/inspec/resources/key_rsa.rb', line 26

def initialize(keypath, passphrase = nil)
  @key_path = keypath
  @passphrase = passphrase
  @key = read_pkey(read_file_content(@key_path, allow_empty: true), @passphrase)
end

Instance Method Details

#key_lengthObject



52
53
54
55
# File 'lib/inspec/resources/key_rsa.rb', line 52

def key_length
  return if @key.nil?
  @key.public_key.n.num_bytes * 8
end

#private?Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/inspec/resources/key_rsa.rb', line 42

def private?
  return if @key.nil?
  @key.private?
end

#private_keyObject



47
48
49
50
# File 'lib/inspec/resources/key_rsa.rb', line 47

def private_key
  return if @key.nil?
  @key.to_s
end

#public?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/inspec/resources/key_rsa.rb', line 32

def public?
  return if @key.nil?
  @key.public?
end

#public_keyObject



37
38
39
40
# File 'lib/inspec/resources/key_rsa.rb', line 37

def public_key
  return if @key.nil?
  @key.public_key.to_s
end

#to_sObject



57
58
59
# File 'lib/inspec/resources/key_rsa.rb', line 57

def to_s
  "rsa_key #{@key_path}"
end