@@ -302,39 +302,15 @@ fn cdi_nvidia_gpu_suffix(id: &str) -> Option<&str> {
302302 id. strip_prefix ( CDI_NVIDIA_GPU_PREFIX )
303303}
304304
305- // Local equivalent of the upstream CDI parser until its public API is released:
306- // https://github.com/cncf-tags/container-device-interface-rs/pull/177
307- fn is_qualified_name ( device : & str ) -> bool {
308- let Some ( ( kind, name) ) = device. split_once ( '=' ) else {
309- return false ;
310- } ;
311- let Some ( ( vendor, class) ) = kind. split_once ( '/' ) else {
312- return false ;
313- } ;
314- let valid_component = |value : & str , device_name : bool | {
315- let bytes = value. as_bytes ( ) ;
316- bytes. first ( ) . is_some_and ( |byte| {
317- if device_name {
318- byte. is_ascii_alphanumeric ( )
319- } else {
320- byte. is_ascii_alphabetic ( )
321- }
322- } ) && bytes. last ( ) . is_some_and ( u8:: is_ascii_alphanumeric)
323- && bytes. iter ( ) . all ( |byte| {
324- byte. is_ascii_alphanumeric ( )
325- || matches ! ( byte, b'_' | b'-' | b'.' )
326- || ( device_name && * byte == b':' )
327- } )
328- } ;
329- valid_component ( vendor, false ) && valid_component ( class, false ) && valid_component ( name, true )
330- }
331-
332305/// Validate vendor-agnostic CDI qualified names without resolving or authorizing devices.
333306///
334307/// # Errors
335308/// Returns an error for host paths or malformed `<vendor>/<class>=<name>` selectors.
336309pub fn validate_cdi_device_names ( devices : & [ String ] , field : & str ) -> Result < ( ) , String > {
337- if devices. iter ( ) . any ( |device| !is_qualified_name ( device) ) {
310+ if devices
311+ . iter ( )
312+ . any ( |device| !crate :: cdi_name:: is_qualified_name ( device) )
313+ {
338314 return Err ( format ! (
339315 "{field} must contain CDI qualified names (<vendor>/<class>=<name>)"
340316 ) ) ;
0 commit comments