Module: Ronin::Support::Crypto::Key::Methods Private

Included in:
DH, DSA, EC, RSA
Defined in:
lib/ronin/support/crypto/key/methods.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Common methods for Ronin::Support::Crypto::Key classes.

Since:

  • 1.0.0

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(key_class) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extends ClassMethods.

Parameters:

Since:

  • 1.0.0



39
40
41
# File 'lib/ronin/support/crypto/key/methods.rb', line 39

def self.included(key_class)
  key_class.extend ClassMethods
end

Instance Method Details

#save(path, encoding: :pem, cipher: 'aes-256-cbc', password: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Saves the key to the given path.

Parameters:

  • path (String)

    The path to write the exported key to.

  • encoding (:pem, :der) (defaults to: :pem)

    The desired encoding of the exported key.

    • :pem - PEM encoding.
    • :der - DER encoding.
  • cipher (String, nil) (defaults to: 'aes-256-cbc')

    Optional cipher to use to encrypt the key file.

  • password (String, nil) (defaults to: nil)

    Optional password to use to encrypt the key file.

Raises:

  • (ArgumentError)

    The endcoding: value must be either :pem or :der.

Since:

  • 1.0.0



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/ronin/support/crypto/key/methods.rb', line 145

def save(path, encoding: :pem, cipher: 'aes-256-cbc', password: nil)
  encoding_method = case encoding
                    when :pem then method(:to_pem)
                    when :der then method(:to_der)
                    else
                      raise(ArgumentError,"encoding: keyword argument (#{encoding.inspect}) must be either :pem or :der")
                    end

  exported = if password
               cipher = OpenSSL::Cipher.new(cipher)
               encoding_method.call(cipher,password)
             else
               encoding_method.call
             end

  File.write(path,exported)
end