mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
feat: make policy length limits configurable per engine (#624)
- Add PolicyLengthConfig struct with max_col, max_file_bytes, and max_lines fields, replacing hardcoded constants in the lexer. - Add Engine::set_policy_length_config and clear_policy_length_config to allow callers to override the default limits. - Add Source::from_contents_with_limits and from_file_with_limits for direct Source construction with custom limits; existing from_contents and from_file signatures are preserved using defaults. - Add tests for default rejection, custom limits, and engine plumbing. - Add bindings for C, C++, Python, WASM/JS, Java, Ruby, C#, Go
This commit is contained in:
@@ -214,3 +214,32 @@ func (e *Engine) TakePrints() (string, error) {
|
||||
|
||||
return C.GoString(result.output), nil
|
||||
}
|
||||
|
||||
type PolicyLengthConfig struct {
|
||||
MaxCol uint32
|
||||
MaxFileBytes uint
|
||||
MaxLines uint
|
||||
}
|
||||
|
||||
func (e *Engine) SetPolicyLengthConfig(config PolicyLengthConfig) error {
|
||||
c := C.RegorusPolicyLengthConfig{
|
||||
max_col: C.uint32_t(config.MaxCol),
|
||||
max_file_bytes: C.size_t(config.MaxFileBytes),
|
||||
max_lines: C.size_t(config.MaxLines),
|
||||
}
|
||||
result := C.regorus_engine_set_policy_length_config(e.e, c)
|
||||
defer C.regorus_result_drop(result)
|
||||
if result.status != C.Ok {
|
||||
return fmt.Errorf("%s", C.GoString(result.error_message))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Engine) ClearPolicyLengthConfig() error {
|
||||
result := C.regorus_engine_clear_policy_length_config(e.e)
|
||||
defer C.regorus_result_drop(result)
|
||||
if result.status != C.Ok {
|
||||
return fmt.Errorf("%s", C.GoString(result.error_message))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user