aws_iot_device_sdk_embedded_rust/
tunneling.rs1use crate::common::*;
2
3const API_BRIDGE: &str = "/tunnels/";
4const API_CHANGED: &str = "notify";
5
6pub fn match_topic(topic: &str) -> Result<(), Error> {
17 is_valid_mqtt_topic(topic)?;
19
20 let s = is_valid_prefix(topic, AWS_THINGS_PREFIX)?;
21
22 let mid = s.find('/').ok_or(Error::FAIL);
23 let (thing_name, mut s) = s.split_at(mid?);
24 is_valid_thing_name(thing_name)?;
25
26 s = is_valid_bridge(s, API_BRIDGE)?;
27
28 if s == API_CHANGED {
29 return Ok(());
30 }
31 Err(Error::NoMatch)
32}
33
34#[cfg(test)]
35mod tests {
36 use crate::tunneling;
37 #[test]
38 fn tunnels_match_topic() {
39 let tunnels = tunneling::match_topic("$aws/things/chloe/tunnels/notify");
40 assert_eq!(tunnels, Ok(()));
41 }
42}