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



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

def key_length
  return if @key.nil?

  @key.public_key.n.num_bytes * 8
end

#private?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
# File 'lib/inspec/resources/key_rsa.rb', line 44

def private?
  return if @key.nil?

  @key.private?
end

#private_keyObject



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

def private_key
  return if @key.nil?

  @key.to_s
end

#public?Boolean

Returns:

  • (Boolean)


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

def public?
  return if @key.nil?

  @key.public?
end

#public_keyObject



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

def public_key
  return if @key.nil?

  @key.public_key.to_s
end

#resource_idObject



62
63
64
# File 'lib/inspec/resources/key_rsa.rb', line 62

def resource_id
  @key_path || "RSA Key"
end

#to_sObject



66
67
68
# File 'lib/inspec/resources/key_rsa.rb', line 66

def to_s
  "rsa_key #{@key_path}"
end