aboutsummaryrefslogtreecommitdiffstats
path: root/src/trial.rs
AgeCommit message (Collapse)Author
2018-10-27trial: Fix unused import warningTeddy Wing
warning: unused import: `TimeZone` --> src/trial.rs:5:44 | 5 | use chrono::{DateTime, FixedOffset, Local, TimeZone}; | ^^^^^^^^ | = note: #[warn(unused_imports)] on by default
2018-10-27datetime_local_to_fixed_offset(): Remove unused variableTeddy Wing
No longer needed since 8369a753e24e1e2d986e9988793655f8923e182c. Forgot to remove this line at the time.
2018-10-27Make `do_trial()` accessible via FFITeddy Wing
Wrap the function in an `extern "C"` function, make it public, and export it.
2018-10-23trial: Rename `trial_expired()` to `exit_trial_expired()`Teddy Wing
Make it clearer that the function exits.
2018-10-23trial: Add docstrings, clean up commentsTeddy Wing
2018-10-23print_trial_days(): Add a real output messageTeddy Wing
Plus a little dumb pluralisation.
2018-10-23decode_datetime(): Fix incorrect encoded & IV string splittingTeddy Wing
I was using `rsplitn` to split the encoded value into an encrypted timestamp and initialisation vector. Originally, I had used `splitn`, but upon discovering `rsplitn` decided to use that instead to ensure we captured the initialisation vector first, and that anything else would be captured to a single string. Didn't realise, though, that `rsplitn` orders element in reverse order compared to `splitn`. Correct the capture order.
2018-10-23do_trial(): Fix unreachable `DurationError` patternsTeddy Wing
I was getting these warnings: warning: unreachable pattern --> src/trial.rs:41:17 | 40 | DurationError => return trial_expired(), | ------------- matches any value 41 | e => { | ^ unreachable pattern warning: unreachable pattern --> src/trial.rs:55:9 | 54 | DurationError => trial_expired(), | ------------- matches any value 55 | Err(e) => (), | ^^^^^^ unreachable pattern Wasn't correctly matching the `DurationError`s. Add an 'error-chain' `ErrorKind` for `DurationError` to make it the same type as the others matched in the first `match` pattern.
2018-10-23trial: Fix timezone errorTeddy Wing
Don't apply an offset to converted local times as the offset will incorrectly shift the correct time. Instead, treat the local time as 0/UTC so that no offset gets applied, even if that's not the correct local timezone.
2018-10-23trial: Implement `do_trial()`Teddy Wing
This function serves as the entry point to all trial functionality. When called, it will try to determine the number of days remaining in the trial. * If the trial period is in progress, the number of days remaining will be printed. * If an error is encountered involving the trial file, or the trial has expired, an error message is printed and the program exits. * Finally, if an unrelated error occurs, print the error without exiting. Change `DateTime<Local>`s to `DateTime<FixedOffset>`s in order to have uniform date types. Otherwise we run into trouble when comparing dates and when querying functions with different date typs. TODO: This fails the tests (unless your local timezone is UTC presumably) because the local time gets stripped of its offset and the correct offset gets reapplied, incorrectly shifting the time. Figure out a way to have uniform datetime types without muffing up the timezone offsets.
2018-10-22Add a description to `get_trial_start()`Teddy Wing
2018-10-22Fill in `get_trial_start()` functionTeddy Wing
Reads the encrypted timestamp from the trial file and returns a `DateTime`.
2018-10-22Move trial timestamp file to a hidden fileTeddy Wing
Make it not as obvious that it's there.
2018-10-22initialize_trial_start(): Don't rewrite the file if it already existsTeddy Wing
The `File::open` function will truncate the file if it exists already: > This function will create a file if it does not exist, and will > truncate it if it does. (https://doc.rust-lang.org/std/fs/struct.File.html#method.create) We don't want this behaviour, as the file should only be created & initialised a single time. The trial timestamp should always correspond to the first trial launch of the program. It doesn't do us any good if the file is overwritten by DomeKey and updates the trial start time to a more current value. Thanks to 'sarnold' (https://stackoverflow.com/users/377270/sarnold) on Stack Overflow for the clean pattern matching code to match the `std::io::ErrorKind::AlreadyExists` error: https://stackoverflow.com/questions/28491759/matching-on-a-specific-error-type/43884600#43884600
2018-10-22trial: Add a function to initialise a trial timestamp in a fileTeddy Wing
Save an encoded timestamp to a file. This function should be run once if no trial file is found. The encoded timestamp can then be read on subsequent launches to determine whether the trial period is still in effect. Also add a few function stubs for other actions that seem relevant.
2018-10-22decode_datetime(): Return a `Result`Teddy Wing
Make a custom error type because it's trickier to integrate with 'error-chain' given that 'magic-crypt''s `Error` type doesn't implement the `std::error::Error` trait. For the same reason, we can't use that as the `cause` for `DateCryptError::Decrypt`. This allows us to capture the errors without panicking. Include some additional cleanups as a result of removing the `use std::result` and `use errors::*` imports.
2018-10-22trial: Encrypt and decrypt timestampTeddy Wing
Add functions to encrypt and decrypt a timestamp. We'll be using those functions to write the encrypted timestamp of the first trial launch date to a file. Decided to go for some light encryption instead of just storing a plain or base64-encoded value. Still need to come up with a key, but that will be stored as a plain string in the binary. Need a way to capture the results so we don't end up panicking. Trouble is, 'magic-crypt' doesn't implement the required `Error` traits, so I can't just slot it into 'error-chain'. Still trying to work out how to deal with that. Also add a function to get the days remaining from now.
2018-10-21Add `trial` module, calculate days remainingTeddy Wing
This new module will contain functions to calculate trial days. Here we implement a function to calculate the days remaining in a trial period. If there are less than 0 days remaining, it returns an error result. Couldn't use 'error-chain' because it was complaining about `Debug` and `PartialEq` not being defined. Don't know if it's possible to implement those traits on 'error-chain''s ErrorKind`, but it was complicated enough that I ended up not bothering. Went with 'quick_error' instead to create a custom error type without having to `impl` all the required traits.