示例#1
0
        public void TestReadingWritingZeroInLength()
        {
            MemoryStream            bOut   = new MemoryStream();
            BerOctetStringGenerator octGen = new BerOctetStringGenerator(bOut);

            Stream outStream = octGen.GetOctetOutputStream();

            outStream.Write(new byte[] { 1, 2, 3, 4 }, 0, 4);
            outStream.Write(new byte[512], 0, 512);              // forces a zero to appear in length

            outStream.Close();

            Asn1StreamParser aIn = new Asn1StreamParser(bOut.ToArray());

            BerOctetStringParser s = (BerOctetStringParser)aIn.ReadObject();

            Stream inStream = s.GetOctetStream();
            int    count    = 0;

            while (inStream.ReadByte() >= 0)
            {
                count++;
            }

            Assert.AreEqual(516, count);
        }
示例#2
0
        public void TestReadingWritingNested()
        {
            MemoryStream            bOut   = new MemoryStream();
            BerSequenceGenerator    sGen   = new BerSequenceGenerator(bOut);
            BerOctetStringGenerator octGen = new BerOctetStringGenerator(sGen.GetRawOutputStream());

            Stream outStream = octGen.GetOctetOutputStream();

            BerSequenceGenerator inSGen = new BerSequenceGenerator(outStream);

            BerOctetStringGenerator inOctGen = new BerOctetStringGenerator(inSGen.GetRawOutputStream());

            Stream inOut = inOctGen.GetOctetOutputStream();

            inOut.Write(new byte[] { 1, 2, 3, 4 }, 0, 4);
            inOut.Write(new byte[10], 0, 10);

            inOut.Close();

            inSGen.Close();

            outStream.Close();

            sGen.Close();

            Asn1StreamParser aIn = new Asn1StreamParser(bOut.ToArray());

            BerSequenceParser sq = (BerSequenceParser)aIn.ReadObject();

            BerOctetStringParser s = (BerOctetStringParser)sq.ReadObject();

            Asn1StreamParser aIn2 = new Asn1StreamParser(s.GetOctetStream());

            BerSequenceParser sq2 = (BerSequenceParser)aIn2.ReadObject();

            BerOctetStringParser inS = (BerOctetStringParser)sq2.ReadObject();

            Stream inStream = inS.GetOctetStream();
            int    count    = 0;

            while (inStream.ReadByte() >= 0)
            {
                count++;
            }

            Assert.AreEqual(14, count);
        }