pub fn decode_hex_or_b64(value: &str, byte_size: usize) -> Result<Vec<u8>, Error> {
    if value.len() == byte_size * 2 {
        return hex::decode(value).map_err(|_| Error::InvalidRpcCall);
    }
    let b64_min = (byte_size * 4 + 2) / 3;
    let b64_max = (b64_min + 3) & !3;
    if value.len() >= b64_min && value.len() <= b64_max {
        if let Ok(val) = base64::decode(value) {
            if val.len() == byte_size {
                return Ok(val);
            }
        }
    }
    return Err(Error::InvalidRpcCall);
}
/// Attempts to decode a received parameter of a fixed size; the parameter can be passed as either
/// hex or base64 (the latter with or without padding).  Returns Error::InvalidRpcCall if neither
/// hex nor base64.
Attempts to decode a received parameter of a fixed size; the parameter can be passed as either
hex or base64 (the latter with or without padding).  Returns Error::InvalidRpcCall if neither
hex nor base64.
Attempts to decode a received parameter of a fixed size ; the parameter can be passed as either hex or base64 ( the latter with or without padding ) . Returns Error :: InvalidRpcCall if neither hex nor base64 .
pub fn decode_hex_or_b64(value: &str, byte_size: usize) -> Result<Vec<u8>, Error> {
    if value.len() == byte_size * 2 {
        return hex::decode(value).map_err(|_| Error::InvalidRpcCall);
    }
    let b64_min = (byte_size * 4 + 2) / 3;
    let b64_max = (b64_min + 3) & !3;
    if value.len() >= b64_min && value.len() <= b64_max {
        if let Ok(val) = base64::decode(value) {
            if val.len() == byte_size {
                return Ok(val);
            }
        }
    }
    return Err(Error::InvalidRpcCall);
}
pub fn decode_hex_or_b64 ( value : & str , byte_size : usize ) -> Result < Vec < u8 > , Error > { if value . len ( ) == byte_size * 2 { return hex :: decode ( value ) . map_err ( | _ | Error :: InvalidRpcCall ) ; } let b64_min = ( byte_size * 4 + 2 ) / 3 ; let b64_max = ( b64_min + 3 ) & ! 3 ; if value . len ( ) >= b64_min && value . len ( ) <= b64_max { if let Ok ( val ) = base64 :: decode ( value ) { if val . len ( ) == byte_size { return Ok ( val ) ; } } } return Err ( Error :: InvalidRpcCall ) ; }
Attempts to decode a received parameter of a fixed size; the parameter can be passed as either
hex or base64 (the latter with or without padding).
Attempts to decode a received parameter of a fixed size ; the parameter can be passed as either hex or base64 ( the latter with or without padding ) .
value
&str
byte_size
usize
value
&str
byte_size
usize