Class: CertificateAuthority::MemoryKeyMaterial

Inherits:
Object
  • Object
show all
Includes:
KeyMaterial, Validations
Defined in:
lib/certificate_authority/key_material.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validations

#errors, #valid?

Methods included from KeyMaterial

from_x509_key_pair, from_x509_public_key

Constructor Details

#initializeMemoryKeyMaterial

Returns a new instance of MemoryKeyMaterial.



47
48
# File 'lib/certificate_authority/key_material.rb', line 47

def initialize
end

Instance Attribute Details

#keypairObject

Returns the value of attribute keypair.



43
44
45
# File 'lib/certificate_authority/key_material.rb', line 43

def keypair
  @keypair
end

#private_keyObject

Returns the value of attribute private_key.



44
45
46
# File 'lib/certificate_authority/key_material.rb', line 44

def private_key
  @private_key
end

#public_keyObject

Returns the value of attribute public_key.



45
46
47
# File 'lib/certificate_authority/key_material.rb', line 45

def public_key
  @public_key
end

Instance Method Details

#generate_key(modulus_bits = 2048) ⇒ Object



67
68
69
70
71
72
# File 'lib/certificate_authority/key_material.rb', line 67

def generate_key(modulus_bits=2048)
  self.keypair = OpenSSL::PKey::RSA.new(modulus_bits)
  self.private_key = keypair
  self.public_key = keypair.public_key
  self.keypair
end

#is_in_hardware?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/certificate_authority/key_material.rb', line 59

def is_in_hardware?
  false
end

#is_in_memory?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/certificate_authority/key_material.rb', line 63

def is_in_memory?
  true
end

#validateObject



50
51
52
53
54
55
56
57
# File 'lib/certificate_authority/key_material.rb', line 50

def validate
  if private_key.nil?
    errors.add :private_key, "cannot be blank"
  end
  if public_key.nil?
    errors.add :public_key, "cannot be blank"
  end
end