<commit_before>class CertValidator
  class RealOcspValidator
    class Extractor
      attr_reader :certificate

      def initialize(cert)
        @certificate = cert
      end

      def endpoint
        return nil unless has_ocsp_extension?

        ocsp_extension_payload
      end

      def has_ocsp_extension?
        !! (ocsp_extension && ocsp_extension_payload)
      end

      def ocsp_extension
        @ocsp_extension ||= certificate.extensions.detect{ |e| e.oid == 'authorityInfoAccess' }
      end

      def decoded_extension
        @decoded_extension ||= Asn1.new(Asn1.new(ocsp_extension).extension_payload).decode
      end

      def ocsp_extension_payload
        return @ocsp_extension_payload if defined? @ocsp_extension_payload

        intermediate = decoded_extension.value.detect do |v|
          v.first.value == 'OCSP'
        end.value[1].value

        @ocsp_extension_payload = descend_to_string(intermediate)
      end

      def descend_to_string(asn_data)
        seen = Set.new
        current = asn_data
        loop do
          raise RecursiveExtractError.new if seen.include? current
          seen.add current
          current = current.first.value

          return current if current.is_a? String
        end
      end
    end
  end
end<commit_msg>pass a string if we don’t have to descend to it<commit_after>class CertValidator
  class RealOcspValidator
    class Extractor
      attr_reader :certificate

      def initialize(cert)
        @certificate = cert
      end

      def endpoint
        return nil unless has_ocsp_extension?

        ocsp_extension_payload
      end

      def has_ocsp_extension?
        !! (ocsp_extension && ocsp_extension_payload)
      end

      def ocsp_extension
        @ocsp_extension ||= certificate.extensions.detect{ |e| e.oid == 'authorityInfoAccess' }
      end

      def decoded_extension
        @decoded_extension ||= Asn1.new(Asn1.new(ocsp_extension).extension_payload).decode
      end

      def ocsp_extension_payload
        return @ocsp_extension_payload if defined? @ocsp_extension_payload

        intermediate = decoded_extension.value.detect do |v|
          v.first.value == 'OCSP'
        end.value[1].value

        @ocsp_extension_payload = descend_to_string(intermediate)
      end

      def descend_to_string(asn_data)
        return asn_data if asn_data.is_a? String
        seen = Set.new
        current = asn_data
        loop do
          raise RecursiveExtractError.new if seen.include? current
          seen.add current
          current = current.first.value

          return current if current.is_a? String
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06036745406824147, 'fraction_numerical': 0.0022497187851518562, 'mean_word_length': 2.3142857142857145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4652190', 'n_tokens_mistral': 781, 'n_tokens_neox': 756, 'n_words': 180}