Exemple #1
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);
         }
     }
 }
Exemple #2
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);
        }
    }
Exemple #3
0
        protected virtual bool ValueOf(uint n)
        {
            int j = 0;

            switch ((UniversalType)(type.ToByte()))
            {
            case UniversalType.Boolean: val = (b[0] > 0); break;

            case UniversalType.Integer:
                val = new Integer(b); break;

            case UniversalType.BitString:
                byte   r  = b[0];
                BitSet bs = new BitSet(n * 8 - r);     // 8.6.2
                for (j = 0; j < bs.size; j++)
                {
                    bs.bits[j] = (b[4 * j] << 24) | (b[4 * j + 1] << 16) | (b[4 * j + 2] << 8) | b[4 * j + 3];
                }
                val = bs; break;

            case UniversalType.OctetString:
                val = new OctetString(b, 0, n); break;

            case UniversalType.Null:
                val = null;
                break;

            case UniversalType.ObjectIdentifier:
                ArrayList al = new ArrayList();
                int       p  = 0;
                while (p < n)
                {
                    al.Add(GetOIDEl(ref p));
                }
                uint[] oid;
                if (((uint)al[0]) == 43)
                {
                    oid    = new uint[al.Count + 1];
                    oid[0] = 1;
                    oid[1] = 3;
                    for (j = 1; j < al.Count; j++)
                    {
                        oid[j + 1] = (uint)al[j];
                    }
                }
                else     // can happen that oid is .0??
                {
                    //				throw(new Exception("OID must begin with .1.3"));
                    oid = new uint[al.Count];
                    for (j = 0; j < al.Count; j++)
                    {
                        oid[j] = (uint)al[j];
                    }
                }
                val = oid; break;

            case UniversalType.Real:
                val = new Real(b); break;

            case UniversalType.GeneralString:
                val = ASCIIEncoding.ASCII.GetString(b); break;

            case UniversalType.Enumerated:
                val = new Integer(b); break;

            default:
                val = type.ToString() + " unimplemented"; break;
            }
            return(true);
        }