Class: Nova::Starbound::Encryptor Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/nova/starbound/encryptor.rb

Overview

This class is abstract.

An encryptor is used to encrypt the data in the exchange for the starbound protocol.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEncryptor

Initialize the encryptor.

Raises:

  • (NotImplementedError)

    if available? returns false.



89
90
91
92
93
94
95
96
# File 'lib/nova/starbound/encryptor.rb', line 89

def initialize
  @options = {}

  unless self.class.available?
    raise NotImplementedError,
      "#{self.class.encryptor_name} is not avialable!"
  end
end

Class Attribute Details

.preferenceNumeric (readonly)

The preference for this encryptor. Used to sort the encryptors.

Returns:

  • (Numeric)


45
46
47
# File 'lib/nova/starbound/encryptor.rb', line 45

def preference
  @preference
end

Instance Attribute Details

#optionsHash<Symbol, Object> (readonly)

The options. These are mostly use internally.

Returns:

  • (Hash<Symbol, Object>)


84
85
86
# File 'lib/nova/starbound/encryptor.rb', line 84

def options
  @options
end

Class Method Details

.available?Boolean

Whether or not this encryptor is available. Defaults to false.

Returns:

  • (Boolean)


68
69
70
# File 'lib/nova/starbound/encryptor.rb', line 68

def self.available?
  false
end

.encryptor_name(name) ⇒ void .encryptor_nameString

Overloads:

  • .encryptor_name(name) ⇒ void

    This method returns an undefined value.

    Sets the encryptor’s name. Used for negotiation of encryption protocols.

    Parameters:

    • name (String)

      the name of the encryptor.

  • .encryptor_nameString

    Gets the encryptor’s name.

    Returns:

    • (String)


20
21
22
23
24
25
26
# File 'lib/nova/starbound/encryptor.rb', line 20

def self.encryptor_name(name = nil)
  if name
    @encryptor_name = name
  else
    @encryptor_name
  end
end

.encryptorsArray<Encryptor>

The encryptors that are defined.

Returns:



51
52
53
# File 'lib/nova/starbound/encryptor.rb', line 51

def self.encryptors
  @encryptors ||= []
end

.plaintext?Boolean

Returns whether or not this is a plaintext encryptor, or one equivalent. Defaults to false, so most encryptors shouldn’t have to overwrite this.

Returns:

  • (Boolean)


77
78
79
# File 'lib/nova/starbound/encryptor.rb', line 77

def self.plaintext?
  false
end

.register!(preference) ⇒ void

This method returns an undefined value.

Registers a subclass with the Encryptor class for use with the protocol.

Parameters:

  • preference (Numeric)

    a number that is used to sort the encryptors by preference.



34
35
36
37
# File 'lib/nova/starbound/encryptor.rb', line 34

def self.register!(preference)
  @preference = preference
  Encryptor.encryptors.push(self)
end

.sorted_encryptorsArray<Encryptor>

The encryptors, sorted by preference.

Returns:



58
59
60
61
62
# File 'lib/nova/starbound/encryptor.rb', line 58

def self.sorted_encryptors
  encryptors.sort do |a, b|
    b.preference <=> a.preference
  end
end

Instance Method Details

#decrypt(packet) ⇒ Packet

Decrypts the given packet with the encryptor.

Parameters:

  • packet (Packet)

    the packet to decrypt.

Returns:

  • (Packet)

    the decrypted packet.



121
122
123
124
125
126
127
128
# File 'lib/nova/starbound/encryptor.rb', line 121

[:encrypt, :decrypt, :private_key!, :public_key,
  :other_public_key=].each do |m|

  define_method(m) do |*args|
    raise NotImplementedError,
      "tried to call #{m} on #{self.class.encryptor_name}"
  end
end

#encrypt(packet) ⇒ Packet

Encrypts the given packet with the encryptor.

Parameters:

  • packet (Packet)

    the packet to encrypt.

Returns:

  • (Packet)

    the encrypted packet.



121
122
123
124
125
126
127
128
# File 'lib/nova/starbound/encryptor.rb', line 121

[:encrypt, :decrypt, :private_key!, :public_key,
  :other_public_key=].each do |m|

  define_method(m) do |*args|
    raise NotImplementedError,
      "tried to call #{m} on #{self.class.encryptor_name}"
  end
end

#other_public_key=(pub_key) ⇒ void

This method returns an undefined value.

Sets the public key of the other remote.

Parameters:

  • pub_key (String)

    the public key of the remote.



121
122
123
124
125
126
127
128
# File 'lib/nova/starbound/encryptor.rb', line 121

[:encrypt, :decrypt, :private_key!, :public_key,
  :other_public_key=].each do |m|

  define_method(m) do |*args|
    raise NotImplementedError,
      "tried to call #{m} on #{self.class.encryptor_name}"
  end
end

#private_key!void

This method returns an undefined value.

Generates the private key for this encryptor.



121
122
123
124
125
126
127
128
# File 'lib/nova/starbound/encryptor.rb', line 121

[:encrypt, :decrypt, :private_key!, :public_key,
  :other_public_key=].each do |m|

  define_method(m) do |*args|
    raise NotImplementedError,
      "tried to call #{m} on #{self.class.encryptor_name}"
  end
end

#public_keyString

Returns the public key to be sent to the other remote.

Returns:

  • (String)


121
122
123
124
125
126
127
128
# File 'lib/nova/starbound/encryptor.rb', line 121

[:encrypt, :decrypt, :private_key!, :public_key,
  :other_public_key=].each do |m|

  define_method(m) do |*args|
    raise NotImplementedError,
      "tried to call #{m} on #{self.class.encryptor_name}"
  end
end