syntax = "proto3";

package xds.type.matcher.v3;

import "validate/validate.proto";

option java_package = "com.github.xds.type.matcher.v3";
option java_outer_classname = "RegexProto";
option java_multiple_files = true;
option go_package = "github.com/cncf/xds/go/xds/type/matcher/v3";

// [#protodoc-title: Regex matcher]

// A regex matcher designed for safety when used with untrusted input.
message RegexMatcher {
  // Google's `RE2 <https://github.com/google/re2>`_ regex engine. The regex
  // string must adhere to the documented `syntax
  // <https://github.com/google/re2/wiki/Syntax>`_. The engine is designed to
  // complete execution in linear time as well as limit the amount of memory
  // used.
  //
  // Envoy supports program size checking via runtime. The runtime keys
  // `re2.max_program_size.error_level` and `re2.max_program_size.warn_level`
  // can be set to integers as the maximum program size or complexity that a
  // compiled regex can have before an exception is thrown or a warning is
  // logged, respectively. `re2.max_program_size.error_level` defaults to 100,
  // and `re2.max_program_size.warn_level` has no default if unset (will not
  // check/log a warning).
  //
  // Envoy emits two stats for tracking the program size of regexes: the
  // histogram `re2.program_size`, which records the program size, and the
  // counter `re2.exceeded_warn_level`, which is incremented each time the
  // program size exceeds the warn level threshold.
  message GoogleRE2 {}

  oneof engine_type {
    option (validate.required) = true;

    // Google's RE2 regex engine.
    GoogleRE2 google_re2 = 1 [ (validate.rules).message = {required : true} ];
  }

  // The regex match string. The string must be supported by the configured
  // engine.
  string regex = 2 [ (validate.rules).string = {min_len : 1} ];
}
