Example #1
0
 public void T15_Sequence_Nested_BER_Stream_IO()
 {
     using (var stream = new MemoryStream()) {
         var x      = new X690.Sequence();
         var s      = new X690.Sequence();
         var leaves = new X690.Node[] {
             new X690.Null(),
             new X690.Boolean(false),
             new X690.Boolean(true),
             new X690.Integer(-1),
             new X690.Integer(0),
             new X690.Integer(1),
             new X690.Text("WOOF!")
             {
                 IsDefiniteLength = false
             },
             new X690.Text("GRR.."),
             new X690.Text("WOOF!")
             {
                 IsDefiniteLength = false
             },
             new X690.Sequence()
         };
         foreach (var leaf in leaves)
         {
             s.Nodes.Add(leaf);
         }
         x.Nodes.Add(s);
         x.Write(stream);
         stream.Position = 0;
         TT.Peek(x, stream);
         var y = X690.Read(stream);
         Assert.Equal(x, y);
     }
 }
Example #2
0
 public void T03_Null_Stream_IO()
 {
     using (var stream = new MemoryStream()) {
         var x = new X690.Null();
         x.Write(stream);
         TT.Peek(x, stream);
         stream.Position = 0;
         var y = X690.Read(stream);
         Assert.Equal(x, y);
     }
 }
Example #3
0
    public void T04_Null_Buffered_IO()
    {
        var buffer = new byte[3];
        var x      = new X690.Null();
        var length = x.Write(buffer, 0);

        TT.Peek(x, buffer, length);
        var y = X690.Read(buffer, 0, length);

        Assert.Equal(x, y);
        Assert.Equal(y.Header.MessageLength, length);
    }
Example #4
0
    public void T06_Boolean_Buffered_IO()
    {
        var buffer = new byte[3];

        foreach (var i in new bool[] { true, false })
        {
            var x      = new X690.Boolean(i);
            var length = x.Write(buffer, 0);
            TT.Peek(x, buffer, length);
            var y = (X690.Read(buffer, 0, length)) as X690.Boolean;
            Assert.Equal(x, y);
            Assert.Equal(y.Header.MessageLength, length);
            Assert.Equal(i, x.Value);
            Assert.Equal(i, y.Value);
        }
    }
Example #5
0
 public void T05_Boolean_Stream_IO()
 {
     foreach (var i in new bool[] { true, false })
     {
         using (var stream = new MemoryStream()) {
             var x = new X690.Boolean(i);
             x.Write(stream);
             TT.Peek(x, stream);
             stream.Position = 0;
             var y = (X690.Read(stream)) as X690.Boolean;
             Assert.Equal(x, y);
             Assert.Equal(i, x.Value);
             Assert.Equal(i, y.Value);
         }
     }
 }
Example #6
0
    public void T10_Text_DER_Buffered_IO()
    {
        var buffer = new byte[10];

        foreach (var i in new string[] { "", "WOOF!" })
        {
            var x      = new X690.Text(i);
            var length = x.Write(buffer, 0);
            TT.Peek(x, buffer, length);
            var y = (X690.Read(buffer, 0, length)) as X690.Text;
            Assert.Equal(i, x.Value);
            Assert.Equal(i, y.Value);
            Assert.Equal(x.Header.MessageLength, length);
            Assert.Equal(x, y);
        }
    }
Example #7
0
 public void T09_Text_DER_Stream_IO()
 {
     foreach (var i in new string[] { "", "WOOF!" })
     {
         using (var stream = new MemoryStream()) {
             var x = new X690.Text(i);
             x.Write(stream);
             TT.Peek(x, stream);
             stream.Position = 0;
             var y = (X690.Read(stream)) as X690.Text;
             Assert.Equal(i, x.Value);
             Assert.Equal(i, y.Value);
             Assert.Equal(x, y);
         }
     }
 }
Example #8
0
    public void T08_Integer_Buffered_IO()
    {
        var buffer = new byte[10];

        for (int i = 0; i < 256; i++)
        {
            var n      = TT.PRNG.Next(Int32.MinValue, Int32.MaxValue);
            var x      = new X690.Integer(n);
            var length = x.Write(buffer, 0);
            TT.Peek(x, buffer, length);
            var y = (X690.Read(buffer, 0, length)) as X690.Integer;
            Assert.Equal(n, x.Value);
            Assert.Equal(x.ValueBits, y.ValueBits);
            Assert.Equal(n, y.Value);
            Assert.Equal(x.Header.MessageLength, length);
        }
    }
Example #9
0
 public void T07_Integer_Stream_IO()
 {
     for (int i = 0; i < 256; i++)
     {
         var n = TT.PRNG.Next(Int32.MinValue, Int32.MaxValue);
         using (var stream = new MemoryStream()) {
             var x = new X690.Integer(n);
             x.Write(stream);
             TT.Peek(x, stream);
             stream.Position = 0;
             var y = (X690.Read(stream)) as X690.Integer;
             Assert.Equal(n, x.Value);
             Assert.Equal(x.ValueBits, y.ValueBits);
             Assert.Equal(n, y.Value);
         }
     }
 }
Example #10
0
    public void T12_Text_BER_Bufered_IO()
    {
        var buffer = new byte[10];

        foreach (var i in new string[] { "", "WOOF!" })
        {
            var x = new X690.Text(i)
            {
                IsDefiniteLength = false
            };
            Assert.Equal(-1, x.Header.MessageLength);
            var length = x.Write(buffer, 0);
            TT.Peek(x, buffer, length);
            var y = (X690.Read(buffer, 0, 16)) as X690.Text;
            Assert.Equal(i, x.Value);
            Assert.Equal(i, y.Value);
            Assert.False(y.Header.IsDefiniteLength);
            Assert.Equal(-1, y.Header.MessageLength);
        }
    }
Example #11
0
 public void T11_Text_BER_Stream_IO()
 {
     foreach (var i in new string[] { "WOOF!", "" })
     {
         using (var stream = new MemoryStream()) {
             var x = new X690.Text(i)
             {
                 IsDefiniteLength = false
             };
             Assert.Equal(-1, x.Header.MessageLength);
             x.Write(stream);
             TT.Peek(x, stream);
             stream.Position = 0;
             var y = (X690.Read(stream)) as X690.Text;
             Assert.Equal(i, x.Value);
             Assert.Equal(i, y.Value);
             Assert.False(y.Header.IsDefiniteLength);
             Assert.Equal(-1, y.Header.MessageLength);
             Assert.Equal(x, y);
         }
     }
 }
Example #12
0
    public void T16_Sequence_Nested_BER_Buffered_IO()
    {
        var buffer = new byte[64];
        var x      = new X690.Sequence();
        var s      = new X690.Sequence();
        var leaves = new X690.Node[] {
            new X690.Null(),
            new X690.Boolean(false),
            new X690.Boolean(true),
            new X690.Integer(-1),
            new X690.Integer(0),
            new X690.Integer(1),
            new X690.Text("WOOF!")
            {
                IsDefiniteLength = false
            },
            new X690.Text("GRR.."),
            new X690.Text("WOOF!")
            {
                IsDefiniteLength = false
            },
            new X690.Sequence()
        };

        foreach (var leaf in leaves)
        {
            s.Nodes.Add(leaf);
        }
        x.Nodes.Add(s);
        var length = x.Write(buffer, 0);

        TT.Peek(x, buffer, length);
        var y = X690.Read(buffer, 0, length);

        Assert.Equal(x, y);
    }