MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / validate_field

Function validate_field

crates/openshell-core/src/forward.rs:893–912  ·  view source on GitHub ↗
(
    name: &'static str,
    value: &str,
    max_len: usize,
    byte_ok: fn(u8) -> bool,
)

Source from the content-addressed store, hash-verified

891}
892
893fn validate_field(
894 name: &'static str,
895 value: &str,
896 max_len: usize,
897 byte_ok: fn(u8) -> bool,
898) -> std::result::Result<(), SshSessionResponseError> {
899 if value.is_empty() {
900 return Err(SshSessionResponseError::Empty { field: name });
901 }
902 if value.len() > max_len {
903 return Err(SshSessionResponseError::TooLong {
904 field: name,
905 max: max_len,
906 });
907 }
908 if !value.bytes().all(byte_ok) {
909 return Err(SshSessionResponseError::InvalidChars { field: name });
910 }
911 Ok(())
912}
913
914/// Build notes string for a sandbox based on active forwards.
915///

Callers 1

Calls 2

lenMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected