Validate a `map ` field: entry count, key length, value length.
(
map: &std::collections::HashMap<String, String>,
max_entries: usize,
max_key_len: usize,
max_value_len: usize,
field_name: &str,
)
| 220 | |
| 221 | /// Validate a `map<string, string>` field: entry count, key length, value length. |
| 222 | pub(super) fn validate_string_map( |
| 223 | map: &std::collections::HashMap<String, String>, |
| 224 | max_entries: usize, |
| 225 | max_key_len: usize, |
| 226 | max_value_len: usize, |
| 227 | field_name: &str, |
| 228 | ) -> Result<(), Status> { |
| 229 | if map.len() > max_entries { |
| 230 | return Err(Status::invalid_argument(format!( |
| 231 | "{field_name} exceeds maximum entries ({} > {max_entries})", |
| 232 | map.len() |
| 233 | ))); |
| 234 | } |
| 235 | for (key, value) in map { |
| 236 | if key.len() > max_key_len { |
| 237 | return Err(Status::invalid_argument(format!( |
| 238 | "{field_name} key exceeds maximum length ({} > {max_key_len})", |
| 239 | key.len() |
| 240 | ))); |
| 241 | } |
| 242 | if value.len() > max_value_len { |
| 243 | return Err(Status::invalid_argument(format!( |
| 244 | "{field_name} value exceeds maximum length ({} > {max_value_len})", |
| 245 | value.len() |
| 246 | ))); |
| 247 | } |
| 248 | } |
| 249 | Ok(()) |
| 250 | } |
| 251 | |
| 252 | /// OPENSHELL_* keys that are allowed in exec environment. The Python SDK's |
| 253 | /// `exec_python()` sends a serialized callable via this key. |
no test coverage detected