\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /proc/self/root/opt/chef/embedded/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/

Viewing File: packet.rb

require 'net/ssh/buffer'
require 'net/ssh/transport/constants'
require 'net/ssh/authentication/constants'
require 'net/ssh/connection/constants'

module Net
  module SSH

    # A specialization of Buffer that knows the format of certain common
    # packet types. It auto-parses those packet types, and allows them to
    # be accessed via the #[] accessor.
    #
    #   data = some_channel_request_packet
    #   packet = Net::SSH::Packet.new(data)
    #
    #   p packet.type #-> 98 (CHANNEL_REQUEST)
    #   p packet[:request]
    #   p packet[:want_reply]
    #
    # This is used exclusively internally by Net::SSH, and unless you're doing
    # protocol-level manipulation or are extending Net::SSH in some way, you'll
    # never need to use this class directly.
    class Packet < Buffer
      @@types = {}

      # Register a new packet type that should be recognized and auto-parsed by
      # Net::SSH::Packet. Note that any packet type that is not preregistered
      # will not be autoparsed.
      #
      # The +pairs+ parameter must be either empty, or an array of two-element
      # tuples, where the first element of each tuple is the name of the field,
      # and the second is the type.
      #
      #   register DISCONNECT, [:reason_code, :long], [:description, :string], [:language, :string]
      def self.register(type, *pairs)
        @@types[type] = pairs
      end

      include Connection::Constants
      include Authentication::Constants
      include Transport::Constants

      #--
      # These are the recognized packet types. All other packet types will be
      # accepted, but not auto-parsed, requiring the client to parse the
      # fields using the methods provided by Net::SSH::Buffer.
      #++

      register DISCONNECT,                %i[reason_code long], %i[description string], %i[language string]
      register IGNORE,                    %i[data string]
      register UNIMPLEMENTED,             %i[number long]
      register DEBUG,                     %i[always_display bool], %i[message string], %i[language string]
      register SERVICE_ACCEPT,            %i[service_name string]
      register USERAUTH_BANNER,           %i[message string], %i[language string]
      register USERAUTH_FAILURE,          %i[authentications string], %i[partial_success bool]
      register GLOBAL_REQUEST,            %i[request_type string], %i[want_reply bool], %i[request_data buffer]
      register CHANNEL_OPEN,              %i[channel_type string], %i[remote_id long], %i[window_size long], %i[packet_size long]
      register CHANNEL_OPEN_CONFIRMATION, %i[local_id long], %i[remote_id long], %i[window_size long], %i[packet_size long]
      register CHANNEL_OPEN_FAILURE,      %i[local_id long], %i[reason_code long], %i[description string], %i[language string]
      register CHANNEL_WINDOW_ADJUST,     %i[local_id long], %i[extra_bytes long]
      register CHANNEL_DATA,              %i[local_id long], %i[data string]
      register CHANNEL_EXTENDED_DATA,     %i[local_id long], %i[data_type long], %i[data string]
      register CHANNEL_EOF,               %i[local_id long]
      register CHANNEL_CLOSE,             %i[local_id long]
      register CHANNEL_REQUEST,           %i[local_id long], %i[request string], %i[want_reply bool], %i[request_data buffer]
      register CHANNEL_SUCCESS,           %i[local_id long]
      register CHANNEL_FAILURE,           %i[local_id long]

      # The (integer) type of this packet.
      attr_reader :type

      # Create a new packet from the given payload. This will automatically
      # parse the packet if it is one that has been previously registered with
      # Packet.register; otherwise, the packet will need to be manually parsed
      # using the methods provided in the Net::SSH::Buffer superclass.
      def initialize(payload)
        @named_elements = {}
        super
        @type = read_byte
        instantiate!
      end

      # Access one of the auto-parsed fields by name. Raises an error if no
      # element by the given name exists.
      def [](name)
        name = name.to_sym
        raise ArgumentError, "no such element #{name}" unless @named_elements.key?(name)
        @named_elements[name]
      end

      private

      # Parse the packet's contents and assign the named elements, as described
      # by the registered format for the packet.
      def instantiate!
        (@@types[type] || []).each do |name, datatype|
          @named_elements[name.to_sym] = if datatype == :buffer
                                           remainder_as_buffer
                                         else
                                           send("read_#{datatype}")
                                         end
        end
      end
    end
  end
end