Advertisement
Nicba1010

Untitled

May 21st, 2023
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. use std::{
  2. fs::File,
  3. io::Read,
  4. };
  5.  
  6. struct FlagChecker {
  7. path_to_flag: String,
  8. }
  9.  
  10. impl FlagChecker {
  11. #[allow(dead_code)]
  12. pub fn new(path_to_flag: String) -> Self {
  13. Self { path_to_flag }
  14. }
  15.  
  16. #[allow(dead_code)]
  17. pub fn check(self) -> bool {
  18. let mut file_handle = File::open(self.path_to_flag).expect("Flag file not found!");
  19. let mut flag = String::new();
  20.  
  21. file_handle
  22. .read_to_string(&mut flag)
  23. .expect("Can't read file");
  24.  
  25. return flag.starts_with("TBTL{") && flag.ends_with("}\n");
  26. }
  27. }
  28. /// ```
  29. /// /// Some documentation.
  30. /// # fn foo() {} // this function will be hidden
  31. /// println!("Hello, World!");
  32. /// ```
  33.  
  34. #[cfg(test)]
  35. mod tests {
  36. use super::*;
  37.  
  38. const PATH_TO_FLAG: &str = "resources/flag.txt";
  39.  
  40. #[test]
  41. fn check_flag() {
  42. let flag_checker = FlagChecker::new(PATH_TO_FLAG.to_string());
  43. assert!(flag_checker.check());
  44. }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement