/// <summary>
 /// Initializes a new instance of the <see cref="FileSpecialCharsRepository"/> class.
 /// </summary>
 /// <param name="path">The path to the file.</param>
 /// <param name="indexLength">The repository's <see cref="DicewareIndexLength"/>.</param>
 /// <param name="cryptoRandom">The cryptographic random utility.</param>
 public FileSpecialCharsRepository(string path, DicewareIndexLength indexLength, RandomUtil cryptoRandom)
 {
     this.Path        = path;
     this.IndexLength = indexLength;
     this.Random      = cryptoRandom;
     this.PopulateData(DicewareFileType.Special);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Make an instance of the Diceware Repository.
        /// </summary>
        /// <param name="random">Cryptographic Random Utility instance.</param>
        /// <returns>Returns an instance of the Diceware Repository.</returns>
        public IPhraseRepository Make(RandomUtil random)
        {
            string path             = this.sysConfig.GetPathForFileType(this.userConfig.Wordlist);
            DicewareIndexLength len = this.userConfig.Wordlist == DicewareFileType.Short ? DicewareIndexLength.Short : DicewareIndexLength.Long;

            return(new FilePhraseRepository(path, len, random));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilePhraseRepository"/> class.
 /// </summary>
 /// <param name="path">The path to the file.</param>
 /// <param name="indexLength">The repository's <see cref="DicewareIndexLength"/>.</param>
 /// <param name="random">The cryptographic random utility.</param>
 public FilePhraseRepository(string path, DicewareIndexLength indexLength, RandomUtil random)
 {
     this.Path        = path;
     this.IndexLength = indexLength;
     this.Random      = random;
     this.PopulateData(DicewareFileType.Long);
 }
Ejemplo n.º 4
0
        public void TestGetRandom(DicewareFileType fileType, DicewareIndexLength index, int count)
        {
            var repo = new FilePhraseRepository(this.sysConfig.GetPathForFileType(fileType), index, this.util);

            var result = repo.GetRandom(count);

            Assert.AreEqual(count, result.Count, "Assert that the returned number of items matches expectations.");
        }
Ejemplo n.º 5
0
        public void TestInvalidRange(DicewareFileType fileType, DicewareIndexLength index)
        {
            var repo = new FilePhraseRepository(this.sysConfig.GetPathForFileType(fileType), index, this.util);

            Assert.Throws <ArgumentOutOfRangeException>(() => repo.GetRandom(0), "Assert that the count value must be greater than zero.");
        }