<commit_before># This file is part of PacketGen
# See https://github.com/sdaubert/packetgen for more informations
# Copyright (C) 2016 <NAME> <<EMAIL>>
# This program is published under MIT license.

module PacketGen
  module Header

    # IEEE 802.1X / EAPOL
    #
    # A IEEE 802.1X header consists of:
    # * a {#version} ({Types::Int8}),
    # * a packet {#type} ({Types::Int8}),
    # * a {#length} ({Types::Int16}),
    # * and a body (a {Types::String} or another Header class).
    # == Create a Dot1x header
    #   pkt1 = PacketGen.gen('Eth').add('Dot1x', type: 1)
    #   pkt2 = PacketGen.gen('Eth').add('Dot1x')
    #   pkt2.dot1x.type = 'EAP Packet'
    #   pkt2.dot1x.body.read 'body'
    # @author <NAME>
    class Dot1x < Base

      # IEEE 802.1x Ether type
      ETHERTYPE = 0x888e

      # IEEE 802.1X packet types
      TYPES = {
        'EAP Packet'      => 0,
        'Start'           => 1,
        'Logoff'          => 2,
        'Key'             => 3,
        'Encap-ASF-Alert' => 4
      }.freeze

      # @!attribute version
      #  @return [Integer] 8-bit Protocol Version
      define_field :version, Types::Int8, default: 1
      # @!attribute type
      #  @return [Integer] 8-bit Packet Type
      define_field :type, Types::Int8Enum, enum: TYPES
      # @!attribute length
      #  @return [Integer] 16-bit body length
      define_field :length, Types::Int16
      # @!attribute body
      #  @return [Types::String,Header::Base]
      define_field :body, Types::String

      # Populate object from string
      # @param [String] str
      # @return [self]
      def read(str)
        return self if str.nil?
        self[:version].read(str[0, 1])
        self[:type].read(str[1, 1])
        self[:length].read(str[2, 2])
        self[:body].read(str[4, self.length])
        self
      end

      # Get human readable type
      # @return [String]
      def human_type
        self[:type].to_human
      end

      # Calculate and set body length
      # @return [Integer]
      def calc_length
        self.length = bosy.sz
      end
    end

    Eth.bind_header Dot1x, ethertype: Dot1x::ETHERTYPE
    SNAP.bind_header Dot1x, proto_id: Dot1x::ETHERTYPE
  end
end<commit_msg>Fix Header::Dot1x#calc_length<commit_after># This file is part of PacketGen
# See https://github.com/sdaubert/packetgen for more informations
# Copyright (C) 2016 <NAME> <<EMAIL>>
# This program is published under MIT license.

module PacketGen
  module Header

    # IEEE 802.1X / EAPOL
    #
    # A IEEE 802.1X header consists of:
    # * a {#version} ({Types::Int8}),
    # * a packet {#type} ({Types::Int8}),
    # * a {#length} ({Types::Int16}),
    # * and a body (a {Types::String} or another Header class).
    # == Create a Dot1x header
    #   pkt1 = PacketGen.gen('Eth').add('Dot1x', type: 1)
    #   pkt2 = PacketGen.gen('Eth').add('Dot1x')
    #   pkt2.dot1x.type = 'EAP Packet'
    #   pkt2.dot1x.body.read 'body'
    # @author <NAME>
    class Dot1x < Base

      # IEEE 802.1x Ether type
      ETHERTYPE = 0x888e

      # IEEE 802.1X packet types
      TYPES = {
        'EAP Packet'      => 0,
        'Start'           => 1,
        'Logoff'          => 2,
        'Key'             => 3,
        'Encap-ASF-Alert' => 4
      }.freeze

      # @!attribute version
      #  @return [Integer] 8-bit Protocol Version
      define_field :version, Types::Int8, default: 1
      # @!attribute type
      #  @return [Integer] 8-bit Packet Type
      define_field :type, Types::Int8Enum, enum: TYPES
      # @!attribute length
      #  @return [Integer] 16-bit body length
      define_field :length, Types::Int16
      # @!attribute body
      #  @return [Types::String,Header::Base]
      define_field :body, Types::String

      # Populate object from string
      # @param [String] str
      # @return [self]
      def read(str)
        return self if str.nil?
        self[:version].read(str[0, 1])
        self[:type].read(str[1, 1])
        self[:length].read(str[2, 2])
        self[:body].read(str[4, self.length])
        self
      end

      # Get human readable type
      # @return [String]
      def human_type
        self[:type].to_human
      end

      # Calculate and set body length
      # @return [Integer]
      def calc_length
        self.length = body.sz
      end
    end

    Eth.bind_header Dot1x, ethertype: Dot1x::ETHERTYPE
    SNAP.bind_header Dot1x, proto_id: Dot1x::ETHERTYPE
  end
end
{'fraction_non_alphanumeric': 0.13022941970310392, 'fraction_numerical': 0.029014844804318488, 'mean_word_length': 2.171897289586305, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1855312', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1454, 'n_words': 396}