Пример #1
0
 /// <summary>
 /// Generates a single branch of X.690 node tree.
 /// </summary>
 /// <param name="lengthEncoding">Definite, indefinite or random.</param>
 /// <returns>A tree branch.</returns>
 static X690.Node RandomBranch(LengthEncoding lengthEncoding = LengthEncoding.Definite) => PRNG.NextBool()
         ? new X690.Sequence()
 {
     IsDefiniteLength = lengthEncoding.IsDefiniteLength()
 } as X690.Node
         : new X690.Set()
 {
     IsDefiniteLength = lengthEncoding.IsDefiniteLength()
 } as X690.Node;
Пример #2
0
    /// <summary>
    /// Generates a single random leaf of X.690 node tree.
    /// </summary>
    /// <param name="lengthEncoding">Definite, indefinite or random.</param>
    /// <returns>A tree leaf.</returns>
    static X690.Node RandomLeaf(LengthEncoding lengthEncoding = LengthEncoding.Definite)
    {
        switch (PRNG.Next(0, 4))
        {
        case 0: return(new X690.Null());

        case 1: return(new X690.Boolean(PRNG.NextBool()));

        case 2: return(new X690.Integer(PRNG.Next(int.MinValue, int.MaxValue)));

        case 3: return(new X690.Text(RandomString())
            {
                IsDefiniteLength = lengthEncoding.IsDefiniteLength()
            });
        }
        throw new InvalidOperationException();
    }