Exemple #1
0
        /// <summary>
        /// Returns the users configured options for the plugin.
        /// </summary>
        /// <param name="strCurrentOptions">A string of previously set options.</param>
        /// <returns>A string of configured options.</returns>
        public override string GetOptions(string strCurrentOptions)
        {
            UserConfig config  = UserConfig.Deserialize(strCurrentOptions);
            Options    options = new Options(config);

            options.ShowDialog();

            return(UserConfig.Serialize(config));
        }
Exemple #2
0
        public void TestDefaultDeserializedValues()
        {
            var config = UserConfig.Deserialize(string.Empty);

            Assert.AreEqual(6, config.NumberOfWords, "Assert that the default NumberOfWords matches expectations.");
            Assert.AreEqual(false, config.StudlyCaps, "Assert that StudlyCaps are disabled by default.");
            Assert.AreEqual(DicewareFileType.Short, config.Wordlist, "Assert that the short filetype is used by default.");
            Assert.AreEqual(" ", config.Separator, "Assert that the default Separator matches expectations.");
            Assert.AreEqual(false, config.SpecialChars, "Assert that SpecialChars are disabled by default");
        }
Exemple #3
0
        public void TestDeserialize()
        {
            const string RawXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xml:space=\"preserve\"><NumberOfWords>3</NumberOfWords><StudlyCaps>true</StudlyCaps><Wordlist>Long</Wordlist><Separator /><SpecialChars>false</SpecialChars></Config>";
            var          config = UserConfig.Deserialize(RawXml);

            Assert.IsInstanceOf(typeof(UserConfig), config, "Assert that a valid config is returned.");
            Assert.AreEqual(3, config.NumberOfWords, "Assert that the NumberOfWords matches expectations.");
            Assert.AreEqual(true, config.StudlyCaps, "Assert that StudlyCaps setting is restored as expected.");
            Assert.AreEqual(DicewareFileType.Long, config.Wordlist, "Assert that the filetype is restored as expected.");
            Assert.AreEqual(string.Empty, config.Separator, "Assert that the default Separator matches expectations.");
            Assert.AreEqual(false, config.SpecialChars, "Assert that SpecialChars retains default configration.");
        }
Exemple #4
0
        /// <summary>
        /// Generates and returns a password as a protected string.
        /// </summary>
        /// <param name="prf">Password profile.</param>
        /// <param name="crsRandomSource">Cryptographic random source.</param>
        /// <returns>The generated password.</returns>
        public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource)
        {
            UserConfig              config           = UserConfig.Deserialize(prf.CustomAlgorithmOptions);
            SystemConfig            sysConfig        = new SystemConfig();
            RandomUtil              random           = new RandomUtil(crsRandomSource);
            IRepositoryFactory      factory          = new FileRepositoryFactory(config, sysConfig);
            IPhraseRepository       repo             = factory.Make(random);
            ISpecialCharsRepository specialCharsRepo = factory.MakeSpecialChars(random);

            IPhraseGenerator generator = new PhraseGenerator(config, repo, specialCharsRepo);

            return(generator.Generate());
        }
Exemple #5
0
        public void TestDeserializeInvalidSource()
        {
            var config = UserConfig.Deserialize(string.Empty);

            Assert.IsInstanceOf(typeof(UserConfig), config, "Assert that providing an invalid string results in a valid, default configuration.");
        }