Kibou is a federated social networking server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validator.rs 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. pub fn validate_activity(activity: serde_json::Value) -> Result<serde_json::Value, &'static str>
  2. {
  3. let known_type = match activity["type"].as_str() {
  4. Some("Create") => true,
  5. Some("Update") => true,
  6. Some("Delete") => true,
  7. Some("Follow") => true,
  8. Some("Unfollow") => true,
  9. Some("Like") => true,
  10. Some("Announce") => true,
  11. _ => false
  12. };
  13. if known_type { Ok(activity) } else { Err("Activity could not be validated") }
  14. }
  15. pub fn validate_object(object: serde_json::Value) -> Result<serde_json::Value, &'static str>
  16. {
  17. let known_type = match object["type"].as_str() {
  18. Some("Note") => true,
  19. Some("Article") => true,
  20. _ => false
  21. };
  22. if known_type { Ok(object) } else { Err("Object could not be validated") }
  23. }
  24. pub fn validate_actor(actor: serde_json::Value) -> Result<serde_json::Value, &'static str>
  25. {
  26. let known_type = match actor["type"].as_str() {
  27. Some("Person") => true,
  28. _ => false
  29. };
  30. if known_type { Ok(actor) } else { Err("Object could not be validated") }
  31. }