Decode and validate a canonical value.
(name: InodeAttrName, bytes: &[u8])
| 102 | |
| 103 | /// Decode and validate a canonical value. |
| 104 | pub fn from_canonical(name: InodeAttrName, bytes: &[u8]) -> Result<Self, AttrValueError> { |
| 105 | let value = match name { |
| 106 | InodeAttrName::Mode if bytes.len() == 2 => { |
| 107 | Self::Mode(u16::from_le_bytes([bytes[0], bytes[1]])) |
| 108 | } |
| 109 | InodeAttrName::Kind if bytes.len() == 1 => Self::Kind( |
| 110 | InodeKind::from_byte(bytes[0]).ok_or(AttrValueError::UnsupportedKind(bytes[0]))?, |
| 111 | ), |
| 112 | _ => { |
| 113 | return Err(AttrValueError::InvalidLength { |
| 114 | name, |
| 115 | actual: bytes.len(), |
| 116 | }); |
| 117 | } |
| 118 | }; |
| 119 | value.validate()?; |
| 120 | Ok(value) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /// Rejection reason for a malformed or unsupported attribute value. |