Class: Nova::Starbound::Encryptor Abstract
- Inherits:
-
Object
- Object
- Nova::Starbound::Encryptor
- Defined in:
- lib/nova/starbound/encryptor.rb
Overview
An encryptor is used to encrypt the data in the exchange for the starbound protocol.
Direct Known Subclasses
Nova::Starbound::Encryptors::OpenSSL, Nova::Starbound::Encryptors::Plaintext, Nova::Starbound::Encryptors::RbNaCl
Class Attribute Summary collapse
-
.preference ⇒ Numeric
readonly
The preference for this encryptor.
Instance Attribute Summary collapse
-
#options ⇒ Hash<Symbol, Object>
readonly
The options.
Class Method Summary collapse
-
.available? ⇒ Boolean
Whether or not this encryptor is available.
- .encryptor_name(name = nil) ⇒ Object
-
.encryptors ⇒ Array<Encryptor>
The encryptors that are defined.
-
.plaintext? ⇒ Boolean
Returns whether or not this is a plaintext encryptor, or one equivalent.
-
.register!(preference) ⇒ void
Registers a subclass with the Encryptor class for use with the protocol.
-
.sorted_encryptors ⇒ Array<Encryptor>
The encryptors, sorted by preference.
Instance Method Summary collapse
-
#decrypt(packet) ⇒ Packet
Decrypts the given packet with the encryptor.
-
#encrypt(packet) ⇒ Packet
Encrypts the given packet with the encryptor.
-
#initialize ⇒ Encryptor
constructor
Initialize the encryptor.
-
#other_public_key=(pub_key) ⇒ void
Sets the public key of the other remote.
-
#private_key! ⇒ void
Generates the private key for this encryptor.
-
#public_key ⇒ String
Returns the public key to be sent to the other remote.
Constructor Details
#initialize ⇒ Encryptor
Initialize the encryptor.
89 90 91 92 93 94 95 96 |
# File 'lib/nova/starbound/encryptor.rb', line 89 def initialize = {} unless self.class.available? raise NotImplementedError, "#{self.class.encryptor_name} is not avialable!" end end |
Class Attribute Details
.preference ⇒ Numeric (readonly)
The preference for this encryptor. Used to sort the encryptors.
45 46 47 |
# File 'lib/nova/starbound/encryptor.rb', line 45 def preference @preference end |
Instance Attribute Details
#options ⇒ Hash<Symbol, Object> (readonly)
The options. These are mostly use internally.
84 85 86 |
# File 'lib/nova/starbound/encryptor.rb', line 84 def end |
Class Method Details
.available? ⇒ Boolean
Whether or not this encryptor is available. Defaults to false.
68 69 70 |
# File 'lib/nova/starbound/encryptor.rb', line 68 def self.available? false end |
.encryptor_name(name) ⇒ void .encryptor_name ⇒ 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 |
.encryptors ⇒ Array<Encryptor>
The encryptors that are defined.
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.
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.
34 35 36 37 |
# File 'lib/nova/starbound/encryptor.rb', line 34 def self.register!(preference) @preference = preference Encryptor.encryptors.push(self) end |
.sorted_encryptors ⇒ Array<Encryptor>
The encryptors, sorted by preference.
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.
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.
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.
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_key ⇒ String
Returns the public key to be sent to the other 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 |