Sha256: aed432c27e2583e4ddc7495dd6bccfb48d289a0deab2ac6d04cf46fedb6f7d06

Contents?: true

Size: 1.96 KB

Versions: 25

Compression:

Stored size: 1.96 KB

Contents

require 'net/ssh/transport/key_expander'
require 'net/ssh/transport/hmac/md5'
require 'net/ssh/transport/hmac/md5_96'
require 'net/ssh/transport/hmac/sha1'
require 'net/ssh/transport/hmac/sha1_96'
require 'net/ssh/transport/hmac/sha2_256'
require 'net/ssh/transport/hmac/sha2_256_96'
require 'net/ssh/transport/hmac/sha2_512'
require 'net/ssh/transport/hmac/sha2_512_96'
require 'net/ssh/transport/hmac/sha2_256_etm'
require 'net/ssh/transport/hmac/sha2_512_etm'
require 'net/ssh/transport/hmac/ripemd160'
require 'net/ssh/transport/hmac/none'

# Implements a simple factory interface for fetching hmac implementations, or
# for finding the key lengths for hmac implementations.s
module Net::SSH::Transport::HMAC
  # The mapping of SSH hmac algorithms to their implementations
  MAP = {
    'hmac-md5'                      => MD5,
    'hmac-md5-96'                   => MD5_96,
    'hmac-sha1'                     => SHA1,
    'hmac-sha1-96'                  => SHA1_96,
    'hmac-sha2-256'                 => SHA2_256,
    'hmac-sha2-256-96'              => SHA2_256_96,
    'hmac-sha2-512'                 => SHA2_512,
    'hmac-sha2-512-96'              => SHA2_512_96,
    'hmac-sha2-256-etm@openssh.com' => SHA2_256_Etm,
    'hmac-sha2-512-etm@openssh.com' => SHA2_512_Etm,
    'hmac-ripemd160'                => RIPEMD160,
    'hmac-ripemd160@openssh.com'    => RIPEMD160,
    'none'                          => None
  }

  # Retrieves a new hmac instance of the given SSH type (+name+). If +key+ is
  # given, the new instance will be initialized with that key.
  def self.get(name, key="", parameters = {})
    impl = MAP[name] or raise ArgumentError, "hmac not found: #{name.inspect}"
    impl.new(Net::SSH::Transport::KeyExpander.expand_key(impl.key_length, key, parameters))
  end

  # Retrieves the key length for the hmac of the given SSH type (+name+).
  def self.key_length(name)
    impl = MAP[name] or raise ArgumentError, "hmac not found: #{name.inspect}"
    impl.key_length
  end
end

Version data entries

25 entries across 24 versions & 3 rubygems

Version Path
net-ssh-backports-6.3.6.backports lib/net/ssh/transport/hmac.rb
net-ssh-backports-6.3.5.backports lib/net/ssh/transport/hmac.rb
net-ssh-backports-6.3.4.backports lib/net/ssh/transport/hmac.rb
net-ssh-backports-6.3.3.backports lib/net/ssh/transport/hmac.rb
net-ssh-backports-6.3.2.backports lib/net/ssh/transport/hmac.rb
net-ssh-backports-6.3.1.backports lib/net/ssh/transport/hmac.rb
net-ssh-backports-6.3.0.backports lib/net/ssh/transport/hmac.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/hmac.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/hmac.rb
net-ssh-6.3.0.beta1 lib/net/ssh/transport/hmac.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.2.0.rc1/lib/net/ssh/transport/hmac.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/hmac.rb
net-ssh-6.2.0.rc2 lib/net/ssh/transport/hmac.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.2.0.rc1/lib/net/ssh/transport/hmac.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/hmac.rb
net-ssh-6.2.0.rc1 lib/net/ssh/transport/hmac.rb
net-ssh-6.2.0.beta1 lib/net/ssh/transport/hmac.rb
net-ssh-6.1.0 lib/net/ssh/transport/hmac.rb
net-ssh-6.1.0.rc1 lib/net/ssh/transport/hmac.rb
net-ssh-6.0.2 lib/net/ssh/transport/hmac.rb