Class: LetsCert::OpenSSLIOPlugin

Inherits:
IOPlugin
  • Object
show all
Defined in:
lib/letscert/io_plugins/openssl_io_plugin.rb

Overview

OpenSSL IOPlugin

Author:

  • Sylvain Daubert

Direct Known Subclasses

CertFile, ChainFile, KeyFile

Constant Summary collapse

PEM_RE =
/^-----BEGIN CERTIFICATE-----\n.*?\n-----END CERTIFICATE-----\n/m

Instance Attribute Summary

Attributes inherited from IOPlugin

#name

Instance Method Summary collapse

Methods inherited from IOPlugin

empty_data, #load, register, #save

Methods included from Loggable

included, #logger

Constructor Details

#initialize(name, type) ⇒ OpenSSLIOPlugin

Returns a new instance of OpenSSLIOPlugin.

Parameters:

  • name (String)

    filename

  • type (:pem, :der)

Raises:

  • (ArgumentError)

    unsupported type



34
35
36
37
38
39
40
41
# File 'lib/letscert/io_plugins/openssl_io_plugin.rb', line 34

def initialize(name, type)
  unless [:pem, :der].include? type
    raise ArgumentError, 'type should be :pem or :der'
  end

  @type = type
  super(name)
end

Instance Method Details

#dump_key(key) ⇒ String Also known as: dump_cert

Dump key/cert data

Parameters:

  • key (OpenSSL::PKey)

Returns:

  • (String)


53
54
55
56
57
58
59
60
# File 'lib/letscert/io_plugins/openssl_io_plugin.rb', line 53

def dump_key(key)
  case @type
  when :pem
    key.to_pem
  when :der
    key.to_der
  end
end

#load_cert(data) ⇒ OpenSSL::X509::Certificate

Load certificate from raw data

Parameters:

  • data (String)

Returns:

  • (OpenSSL::X509::Certificate)


66
67
68
# File 'lib/letscert/io_plugins/openssl_io_plugin.rb', line 66

def load_cert(data)
  OpenSSL::X509::Certificate.new data
end

#load_key(data) ⇒ OpenSSL::PKey

Load key from raw data

Parameters:

  • data (String)

Returns:

  • (OpenSSL::PKey)


46
47
48
# File 'lib/letscert/io_plugins/openssl_io_plugin.rb', line 46

def load_key(data)
  OpenSSL::PKey::RSA.new data
end