Closed dex-r closed 7 years ago
Great work. However, there are a few places in the current code where I would like to be explicitly returning an Err.
poly_substitute
function in the vigenere cipher should return an err when sub_ok
fails. A better solution would be to return an Err on every branch of the if let
statements to indicate what explicitly went wrong. For example the first branch would return something like Err("fitted key to small for message length")
.shift_substitution
in the common::substitute
module should return err when the calculated si
is an invalid index. Something like Err("calculated an index outside of the known alphabet")
would suffice.So I've added the return types as requested, which has resulted in the ROT13 cipher needing a Result return type as well, which i guess makes it consistant with the other ciphers. However it means that the example in the README is a bit cluttered with unwraps, so if you agree i think we should split that into multiple lines. I've also snuck in a fix for the exhaustive_encrypt()
test in caeser.rs which wasnt testing the last shift. It seemed too small for its own issue.
Thanks for those changes, however I dont think the rot13 apply
function should need to return a Result
type. It doesnt implement the cipher trait, and there is no case where it would fail.
If you have a strong opinion I'd be happy to discuss but otherwise - I dont think it needs to have it.
Its only that it uses the shift_substitution() in common, that now returns a Result. I agree that it shouldn't return an Err though. Should I change it to unwrap automatically?
Yeah, perhaps it makes more sense to just let it panic if something goes wrong. Perhaps just add a comment for our reasoning
I've added result return types for both the encrypt and decrypt traits, and have added unwraps everywhere in the tests and docstrings. So many unwraps. Currently, none of the ciphers actually return an Err.