Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::{
- fs::File,
- io::Read,
- };
- struct FlagChecker {
- path_to_flag: String,
- }
- impl FlagChecker {
- #[allow(dead_code)]
- pub fn new(path_to_flag: String) -> Self {
- Self { path_to_flag }
- }
- #[allow(dead_code)]
- pub fn check(self) -> bool {
- let mut file_handle = File::open(self.path_to_flag).expect("Flag file not found!");
- let mut flag = String::new();
- file_handle
- .read_to_string(&mut flag)
- .expect("Can't read file");
- return flag.starts_with("TBTL{") && flag.ends_with("}\n");
- }
- }
- /// ```
- /// /// Some documentation.
- /// # fn foo() {} // this function will be hidden
- /// println!("Hello, World!");
- /// ```
- #[cfg(test)]
- mod tests {
- use super::*;
- const PATH_TO_FLAG: &str = "resources/flag.txt";
- #[test]
- fn check_flag() {
- let flag_checker = FlagChecker::new(PATH_TO_FLAG.to_string());
- assert!(flag_checker.check());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement