Class: Noise::Protocol
- Inherits:
-
Object
- Object
- Noise::Protocol
- Defined in:
- lib/noise/protocol.rb
Constant Summary collapse
- CIPHER =
{ 'AESGCM': Noise::Functions::Cipher::AesGcm, 'ChaChaPoly': Noise::Functions::Cipher::ChaChaPoly }.stringify_keys.freeze
- DH =
{ '25519': Noise::Functions::DH::ED25519, '448': Noise::Functions::DH::ED448, 'secp256k1': Noise::Functions::DH::Secp256k1 }.stringify_keys.freeze
- HASH =
{ 'BLAKE2b': Noise::Functions::Hash::Blake2b, 'BLAKE2s': Noise::Functions::Hash::Blake2s, 'SHA256': Noise::Functions::Hash::Sha256, 'SHA512': Noise::Functions::Hash::Sha512 }.stringify_keys.freeze
Instance Attribute Summary collapse
-
#cipher_fn ⇒ Object
Returns the value of attribute cipher_fn.
-
#dh_fn ⇒ Object
Returns the value of attribute dh_fn.
-
#hash_fn ⇒ Object
Returns the value of attribute hash_fn.
-
#hkdf_fn ⇒ Object
Returns the value of attribute hkdf_fn.
-
#is_psk_handshake ⇒ Object
Returns the value of attribute is_psk_handshake.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, pattern_name, cipher_name, hash_name, dh_name) ⇒ Protocol
constructor
A new instance of Protocol.
- #initialize_fn!(cipher_name, hash_name, dh_name) ⇒ Object
- #psk_handshake? ⇒ Boolean
Constructor Details
#initialize(name, pattern_name, cipher_name, hash_name, dh_name) ⇒ Protocol
Returns a new instance of Protocol.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/noise/protocol.rb', line 33 def initialize(name, pattern_name, cipher_name, hash_name, dh_name) @name = name @pattern = Noise::Pattern.create(pattern_name) @hkdf_fn = Noise::Functions::Hash.create_hkdf_fn(hash_name) @is_psk_handshake = @pattern.modifiers.any? { |m| m.start_with?('psk') } @pattern.apply_pattern_modifiers initialize_fn!(cipher_name, hash_name, dh_name) end |
Instance Attribute Details
#cipher_fn ⇒ Object
Returns the value of attribute cipher_fn.
6 7 8 |
# File 'lib/noise/protocol.rb', line 6 def cipher_fn @cipher_fn end |
#dh_fn ⇒ Object
Returns the value of attribute dh_fn.
6 7 8 |
# File 'lib/noise/protocol.rb', line 6 def dh_fn @dh_fn end |
#hash_fn ⇒ Object
Returns the value of attribute hash_fn.
6 7 8 |
# File 'lib/noise/protocol.rb', line 6 def hash_fn @hash_fn end |
#hkdf_fn ⇒ Object
Returns the value of attribute hkdf_fn.
6 7 8 |
# File 'lib/noise/protocol.rb', line 6 def hkdf_fn @hkdf_fn end |
#is_psk_handshake ⇒ Object
Returns the value of attribute is_psk_handshake.
5 6 7 |
# File 'lib/noise/protocol.rb', line 5 def is_psk_handshake @is_psk_handshake end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/noise/protocol.rb', line 7 def name @name end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
7 8 9 |
# File 'lib/noise/protocol.rb', line 7 def pattern @pattern end |
Class Method Details
.create(name) ⇒ Object
27 28 29 30 31 |
# File 'lib/noise/protocol.rb', line 27 def self.create(name) prefix, pattern_name, dh_name, cipher_name, hash_name = name.split('_') raise Noise::Exceptions::ProtocolNameError if prefix != 'Noise' new(name, pattern_name, cipher_name, hash_name, dh_name) end |
Instance Method Details
#initialize_fn!(cipher_name, hash_name, dh_name) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/noise/protocol.rb', line 44 def initialize_fn!(cipher_name, hash_name, dh_name) @cipher_fn = CIPHER[cipher_name]&.new @hash_fn = HASH[hash_name]&.new @dh_fn = DH[dh_name]&.new raise Noise::Exceptions::ProtocolNameError unless @cipher_fn && @hash_fn && @dh_fn end |
#psk_handshake? ⇒ Boolean
51 52 53 |
# File 'lib/noise/protocol.rb', line 51 def psk_handshake? @is_psk_handshake end |