Sha256: 83c46f84095efc6f678fe155a3986405c7e01ee92c2efb9acd0fd415d575b86b

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

cs__scoped_require 'contrast/utils/object_share'
cs__scoped_require 'contrast/utils/string_utils'

module Contrast
  module Api
    module Decorators
      # Used to decorate the TraceTaintRange protobuf model
      module TraceTaintRange
        def self.included klass
          klass.extend(ClassMethods)
        end

        # Class methods for TraceEventObject
        module ClassMethods
          # Convert the tags from Contrast::Agent::Assess::Property::Tagged to
          # the form required for their Event's DTM.
          #
          # @param tags [Hash{String => Array<Contrast::Agent::Assess::Tag>}]
          # @return [Array<Contrast::Api::Dtm::TraceTaintRange>]
          def build_for_event tags
            return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags&.any?

            ranges = []
            tags.each_value do |value|
              next if value.empty?

              value.each { |tag| ranges << build(tag) }
            end
            ranges
          end

          # Convert our Tags to their DTM equivalent
          #
          # @param tag [Contrast::Agent::Assess::Tag]
          # @return [Contrast::Api::Dtm::TraceTaintRange]
          def build tag
            range = Contrast::Api::Dtm::TraceTaintRange.new
            range.tag = Contrast::Utils::StringUtils.protobuf_safe_string(tag.label)
            range.range = tag.start_idx.to_s + Contrast::Utils::ObjectShare::COLON + tag.end_idx.to_s
            range
          end
        end
      end
    end
  end
end

Contrast::Api::Dtm::TraceTaintRange.include(Contrast::Api::Decorators::TraceTaintRange)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contrast-agent-3.13.2 lib/contrast/api/decorators/trace_taint_range.rb
contrast-agent-3.13.1 lib/contrast/api/decorators/trace_taint_range.rb
contrast-agent-3.13.0 lib/contrast/api/decorators/trace_taint_range.rb