//sets AppOptions when crypting method changes public static bool SetOptions(CipherBase cipher) { if (cipher == null) { MessageBox.Show("Setting the crypting method failed"); return(false); } Options.CryptingMethod = cipher; Options.LbKeyText = buildLbKeyText(Options.CryptingMethod); if (Options.CryptingMethod.IsKeyBasedCipher()) { CipherKeyBase keyCipherMethod = (CipherKeyBase)Options.CryptingMethod; Options.NudKeyVisible = true; Options.NudKeyMinimum = keyCipherMethod.KeyMinConstraint; Options.NudKeyMaximum = keyCipherMethod.KeyMaxConstraint; Options.KeyValue = keyCipherMethod.KeyValue; } else { Options.NudKeyVisible = false; } return(true); }
public void testSetOptions_cryptingMethodWithoutKey() { CipherBase testCipher = CipherTestInstances.cipherWithoutKey; OptionsService.SetOptions(testCipher); Assert.Equal(Options.CryptingMethod, testCipher); Assert.Equal(Options.LbKeyText, testCipher.Name + OptionsService.CIPHER_WITHOUT_KEY_LABEL_PREFIX); OptionsService.SetOptions(testCipher); // TODO find out why is not changing CipherMethod after first SetOptions Assert.False(Options.CryptingMethod.IsKeyBasedCipher()); }
public static string buildLbKeyText(CipherBase cipher) { return(string.Format($"{cipher.Name}" + (cipher.IsKeyBasedCipher() ? CIPHER_WITH_KEY_LABEL_PREFIX + $"({((CipherKeyBase)cipher).KeyMinConstraint}" + $" - {((CipherKeyBase)cipher).KeyMaxConstraint})" : CIPHER_WITHOUT_KEY_LABEL_PREFIX))); }