Пример #1
0
        //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);
        }
Пример #2
0
        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());
        }
Пример #3
0
 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)));
 }