Module: Noise

Defined in:
lib/noise.rb,
lib/noise/key.rb,
lib/noise/state.rb,
lib/noise/pattern.rb,
lib/noise/version.rb,
lib/noise/key_pair.rb,
lib/noise/protocol.rb,
lib/noise/functions.rb,
lib/noise/connection.rb,
lib/noise/exceptions.rb,
lib/noise/functions/dh.rb,
lib/noise/utils/string.rb,
lib/noise/functions/hash.rb,
lib/noise/connection/base.rb,
lib/noise/functions/cipher.rb,
lib/noise/functions/dh/ed448.rb,
lib/noise/state/cipher_state.rb,
lib/noise/connection/initiator.rb,
lib/noise/connection/responder.rb,
lib/noise/functions/dh/ed25519.rb,
lib/noise/functions/hash/blake3.rb,
lib/noise/functions/hash/sha256.rb,
lib/noise/functions/hash/sha512.rb,
lib/noise/state/handshake_state.rb,
lib/noise/state/symmetric_state.rb,
lib/noise/functions/dh/secp256k1.rb,
lib/noise/functions/hash/blake2b.rb,
lib/noise/functions/hash/blake2s.rb,
lib/noise/exceptions/decrypt_error.rb,
lib/noise/exceptions/encrypt_error.rb,
lib/noise/functions/cipher/aes_gcm.rb,
lib/noise/exceptions/max_nonce_error.rb,
lib/noise/exceptions/noise_psk_error.rb,
lib/noise/exceptions/psk_value_error.rb,
lib/noise/functions/cipher/cha_cha_poly.rb,
lib/noise/exceptions/invalid_nonce_error.rb,
lib/noise/exceptions/protocol_name_error.rb,
lib/noise/exceptions/noise_handshake_error.rb,
lib/noise/exceptions/message_too_long_error.rb,
lib/noise/exceptions/noise_validation_error.rb,
lib/noise/exceptions/invalid_public_key_error.rb,
lib/noise/exceptions/missing_dependency_error.rb,
lib/noise/exceptions/unsupported_modifier_error.rb

Defined Under Namespace

Modules: Connection, Exceptions, Functions, KeyPair, Modifier, State, Token, Utils Classes: DeferredPattern, Key, OneWayPattern, Pattern, PatternI1K, PatternI1K1, PatternI1N, PatternI1X, PatternI1X1, PatternIK, PatternIK1, PatternIN, PatternIX, PatternIX1, PatternK, PatternK1K, PatternK1K1, PatternK1N, PatternK1X, PatternK1X1, PatternKK, PatternKK1, PatternKN, PatternKX, PatternKX1, PatternN, PatternNK, PatternNK1, PatternNN, PatternNX, PatternNX1, PatternX, PatternX1K, PatternX1K1, PatternX1N, PatternX1X, PatternX1X1, PatternXK, PatternXK1, PatternXN, PatternXX, PatternXX1, Protocol

Constant Summary collapse

VERSION =
'0.13.0'

Class Method Summary collapse

Class Method Details

.optional_dependency!(name) ⇒ Object

Raises MissingDependencyError if the named optional backend failed to load earlier. Call it from the entry point of a function that needs the backend, so the failure surfaces where the backend is used rather than at require time.



48
49
50
51
52
53
# File 'lib/noise.rb', line 48

def optional_dependency!(name)
  reason = @unavailable_dependencies[name]
  return if reason.nil?

  raise Noise::Exceptions::MissingDependencyError, "'#{name}' could not be loaded: #{reason}"
end

.require_optional(name) ⇒ Object

Requires an optional backend gem and yields once it is loaded. A LoadError is not fatal: the reason is recorded so optional_dependency! can raise it later, and a warning goes to $stderr so the missing backend is visible at load time. Kernel#warn is used rather than a Logger because logger is no longer a default gem on Ruby 4.0, and this single message does not justify a runtime dependency on it.



34
35
36
37
38
39
40
41
42
43
# File 'lib/noise.rb', line 34

def require_optional(name)
  require name
rescue LoadError => e
  @unavailable_dependencies[name] = e.message
  warn("Optional dependency '#{name}' is unavailable: #{e.message}")
else
  # The block runs outside the rescue on purpose: a LoadError raised by the block itself is
  # about something other than this dependency, and swallowing it here would hide the cause.
  yield if block_given?
end