Class: Ronin::CLI::Commands::CipherCommand Private

Inherits:
FileProcessorCommand show all
Includes:
KeyOptions
Defined in:
lib/ronin/cli/cipher_command.rb

Overview

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

Base class for all commands which use ciphers.

Since:

  • 2.0.0

Direct Known Subclasses

Decrypt, Encrypt

Instance Attribute Summary

Attributes included from KeyOptions

#key

Instance Method Summary collapse

Methods included from KeyOptions

included

Methods inherited from FileProcessorCommand

#process_file

Instance Method Details

#cipher(**kwargs) ⇒ Ronin::Support::Crypto::Cipher

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.

Initializes a new cipher.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Ronin::Support::Crypto::Cipher#initialize.

Returns:

  • (Ronin::Support::Crypto::Cipher)

    The new cipher object.

Since:

  • 2.0.0



129
130
131
132
133
134
135
136
# File 'lib/ronin/cli/cipher_command.rb', line 129

def cipher(**kwargs)
  Support::Crypto::Cipher.new(
    options[:cipher], key:       @key,
                      hash:      options[:hash],
                      password:  options[:password],
                      **kwargs
  )
end

#open_file(path) {|file| ... } ⇒ File?

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.

Opens the file in binary mode.

Parameters:

  • path (String)

    The path to the file to open.

Yields:

  • (file)

    If a block is given, the newly opened file will be yielded. Once the block returns the file will automatically be closed.

Yield Parameters:

  • file (File)

    The newly opened file.

Returns:

  • (File, nil)

    If no block is given, the newly opened file object will be returned. If no block was given, then nil will be returned.

Since:

  • 2.0.0



115
116
117
# File 'lib/ronin/cli/cipher_command.rb', line 115

def open_file(path,&block)
  super(path,'rb',&block)
end

#process_input(input) ⇒ 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.

Decrypts the input stream.

Parameters:

  • input (IO, StringIO)

    The input stream to decrypt.

Since:

  • 2.0.0



144
145
146
# File 'lib/ronin/cli/cipher_command.rb', line 144

def process_input(input)
  cipher.stream(input, block_size: @block_size, output: stdout)
end

#run(*files) ⇒ 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.

Runs the ronin encrypt command.

Parameters:

  • files (Array<String>)

    Optional files to encrypt.

Since:

  • 2.0.0



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ronin/cli/cipher_command.rb', line 84

def run(*files)
  if options[:list_ciphers]
    puts Support::Crypto::Cipher.supported
    return
  end

  unless (options[:key] || options[:key_file] || options[:password])
    print_error "must specify --password, --key, or --key-file"
    exit(1)
  end

  super(*files)
end