(&self, args: &[Value], _context: &Context)
| 31 | } |
| 32 | |
| 33 | fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> { |
| 34 | debug!("{}", t!("functions.cidrHost.invoked")); |
| 35 | |
| 36 | let cidr_string = args[0].as_str().unwrap(); |
| 37 | let host_index = args[1].as_i64().unwrap(); |
| 38 | |
| 39 | if host_index < 0 { |
| 40 | return Err(DscError::FunctionArg( |
| 41 | "cidrHost".to_string(), |
| 42 | t!("functions.cidrHost.negativeHostIndex").to_string(), |
| 43 | )); |
| 44 | } |
| 45 | |
| 46 | let network = cidr_string.parse::<IpNetwork>().map_err(|_| { |
| 47 | DscError::FunctionArg( |
| 48 | "cidrHost".to_string(), |
| 49 | t!("functions.cidrHost.invalidCidr", cidr = cidr_string).to_string(), |
| 50 | ) |
| 51 | })?; |
| 52 | |
| 53 | let result = match network { |
| 54 | IpNetwork::V4(net) => calculate_ipv4_host(&net, host_index as u32)?, |
| 55 | IpNetwork::V6(net) => calculate_ipv6_host(&net, host_index as u128)?, |
| 56 | }; |
| 57 | |
| 58 | Ok(Value::String(result)) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | fn calculate_ipv4_host(net: &Ipv4Network, host_index: u32) -> Result<String, DscError> { |
nothing calls this directly
no test coverage detected