pub struct ProtectedInteger<T> { /* private fields */ }Expand description
The protected integer
use protected_integer::ProtectedInteger;
let mut my_number = ProtectedInteger::new(114514); // initialize this variable
println!("{}", my_number.get().to_value());Implementations§
Source§impl<T: Integer + Copy + BitXor<Output = T>> ProtectedInteger<T>where
Standard: Distribution<T>,
impl<T: Integer + Copy + BitXor<Output = T>> ProtectedInteger<T>where
Standard: Distribution<T>,
Sourcepub fn new(value: T) -> ProtectedInteger<T>
pub fn new(value: T) -> ProtectedInteger<T>
Create a new protected integer A random value will be generated for the verification key
Examples found in repository?
examples/hacking_test.rs (line 4)
3fn main() {
4 let mut money:ProtectedInteger<i16> = ProtectedInteger::new(123);
5 println!("The initial amount of money is {}", money.get().to_value());
6 println!("Press Enter to increment it by 1");
7 println!("Try searching and modifying this value with Cheat Engine");
8 println!("Input 'quit' to exit");
9 loop {
10 let mut input = String::new();
11 std::io::stdin().read_line(&mut input).unwrap();
12 let input = input.trim();
13 if input == "quit" {
14 println!("Exiting...");
15 break;
16 }
17 if !money.check() {
18 println!("Hacking detected!");
19 }
20 money.set(money.get().to_value() + 1);
21 println!("The money is now {}", money.get().to_value());
22 }
23}Sourcepub fn get(&self) -> State<T>
pub fn get(&self) -> State<T>
Get the value of the protected integer and check if it is tampered
Examples found in repository?
examples/hacking_test.rs (line 5)
3fn main() {
4 let mut money:ProtectedInteger<i16> = ProtectedInteger::new(123);
5 println!("The initial amount of money is {}", money.get().to_value());
6 println!("Press Enter to increment it by 1");
7 println!("Try searching and modifying this value with Cheat Engine");
8 println!("Input 'quit' to exit");
9 loop {
10 let mut input = String::new();
11 std::io::stdin().read_line(&mut input).unwrap();
12 let input = input.trim();
13 if input == "quit" {
14 println!("Exiting...");
15 break;
16 }
17 if !money.check() {
18 println!("Hacking detected!");
19 }
20 money.set(money.get().to_value() + 1);
21 println!("The money is now {}", money.get().to_value());
22 }
23}Sourcepub fn set(&mut self, value: T)
pub fn set(&mut self, value: T)
Set the value of the protected integer, and update the verification key
Examples found in repository?
examples/hacking_test.rs (line 20)
3fn main() {
4 let mut money:ProtectedInteger<i16> = ProtectedInteger::new(123);
5 println!("The initial amount of money is {}", money.get().to_value());
6 println!("Press Enter to increment it by 1");
7 println!("Try searching and modifying this value with Cheat Engine");
8 println!("Input 'quit' to exit");
9 loop {
10 let mut input = String::new();
11 std::io::stdin().read_line(&mut input).unwrap();
12 let input = input.trim();
13 if input == "quit" {
14 println!("Exiting...");
15 break;
16 }
17 if !money.check() {
18 println!("Hacking detected!");
19 }
20 money.set(money.get().to_value() + 1);
21 println!("The money is now {}", money.get().to_value());
22 }
23}Sourcepub fn check(&self) -> bool
pub fn check(&self) -> bool
Check if the value is not tampered
Examples found in repository?
examples/hacking_test.rs (line 17)
3fn main() {
4 let mut money:ProtectedInteger<i16> = ProtectedInteger::new(123);
5 println!("The initial amount of money is {}", money.get().to_value());
6 println!("Press Enter to increment it by 1");
7 println!("Try searching and modifying this value with Cheat Engine");
8 println!("Input 'quit' to exit");
9 loop {
10 let mut input = String::new();
11 std::io::stdin().read_line(&mut input).unwrap();
12 let input = input.trim();
13 if input == "quit" {
14 println!("Exiting...");
15 break;
16 }
17 if !money.check() {
18 println!("Hacking detected!");
19 }
20 money.set(money.get().to_value() + 1);
21 println!("The money is now {}", money.get().to_value());
22 }
23}Auto Trait Implementations§
impl<T> Freeze for ProtectedInteger<T>where
T: Freeze,
impl<T> RefUnwindSafe for ProtectedInteger<T>where
T: RefUnwindSafe,
impl<T> Send for ProtectedInteger<T>where
T: Send,
impl<T> Sync for ProtectedInteger<T>where
T: Sync,
impl<T> Unpin for ProtectedInteger<T>where
T: Unpin,
impl<T> UnwindSafe for ProtectedInteger<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more