Class: Noise::ProtocolName
- Inherits:
-
Data
- Object
- Data
- Noise::ProtocolName
- Defined in:
- lib/noise/protocol_name.rb
Overview
A Noise protocol name, split into the parts that name a handshake pattern and the three functions the protocol runs on.
A name has five parts joined with '_': the prefix 'Noise', the handshake pattern with its modifiers, the DH function, the cipher function and the hash function, for example 'Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s'.
Two of those parts hold a list of their own. The pattern part is a pattern name followed by the modifiers applied to it, and the DH part is a list joined with '+', because a hybrid handshake names two DH functions at once ('Noise_NNhfs_25519+448_ChaChaPoly_BLAKE2s'). Both are split here, so that every rule about the shape of a name lives in this class alone.
Which functions exist is Noise::Protocol's question, not this one's: a name that asks for a cipher, hash or DH function this gem does not implement still parses. Modifiers are the one exception, because a modifier has to be understood before it can be held as a value, so an unknown one is rejected here.
The members are the names as written, not the functions themselves. Noise::Protocol resolves them, and calls its resolved functions cipher_fn, hash_fn and dh_fn.
Instance Attribute Summary collapse
-
#cipher_name ⇒ Object
readonly
Returns the value of attribute cipher_name.
-
#dh_names ⇒ Object
readonly
Returns the value of attribute dh_names.
-
#hash_name ⇒ Object
readonly
Returns the value of attribute hash_name.
-
#modifiers ⇒ Object
readonly
Returns the value of attribute modifiers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pattern_name ⇒ Object
readonly
Returns the value of attribute pattern_name.
Class Method Summary collapse
-
.parse(name) ⇒ Noise::ProtocolName
Parses a protocol name.
Instance Method Summary collapse
-
#to_s ⇒ String
The name this was parsed from.
Instance Attribute Details
#cipher_name ⇒ Object (readonly)
Returns the value of attribute cipher_name
23 24 25 |
# File 'lib/noise/protocol_name.rb', line 23 def cipher_name @cipher_name end |
#dh_names ⇒ Object (readonly)
Returns the value of attribute dh_names
23 24 25 |
# File 'lib/noise/protocol_name.rb', line 23 def dh_names @dh_names end |
#hash_name ⇒ Object (readonly)
Returns the value of attribute hash_name
23 24 25 |
# File 'lib/noise/protocol_name.rb', line 23 def hash_name @hash_name end |
#modifiers ⇒ Object (readonly)
Returns the value of attribute modifiers
23 24 25 |
# File 'lib/noise/protocol_name.rb', line 23 def modifiers @modifiers end |
#name ⇒ Object (readonly)
Returns the value of attribute name
23 24 25 |
# File 'lib/noise/protocol_name.rb', line 23 def name @name end |
#pattern_name ⇒ Object (readonly)
Returns the value of attribute pattern_name
23 24 25 |
# File 'lib/noise/protocol_name.rb', line 23 def pattern_name @pattern_name end |
Class Method Details
.parse(name) ⇒ Noise::ProtocolName
Parses a protocol name.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/noise/protocol_name.rb', line 33 def self.parse(name) # 'Noise', the pattern with its modifiers, the DH functions, the cipher and the hash. parts = name.split('_') malformed!(name) unless parts.size == 5 prefix, pattern_part, dh_part, cipher_name, hash_name = parts malformed!(name) unless prefix == 'Noise' # A pattern name is capitals, plus the digit 1 that deferred patterns use (X1K1). Whatever # follows it is the modifiers. matched = /\A([A-Z1]+)([^A-Z]*)\z/.match(pattern_part) malformed!(name) unless matched new(name: name, pattern_name: matched[1], modifiers: parse_modifiers(matched[2]), dh_names: split_dh(dh_part), cipher_name: cipher_name, hash_name: hash_name) end |
Instance Method Details
#to_s ⇒ String
Returns the name this was parsed from.
74 75 76 |
# File 'lib/noise/protocol_name.rb', line 74 def to_s name end |