Exemplo n.º 1
0
        public virtual void EncodeUnivString(int[] data, bool explicitTagging, Asn1Tag tag)
        {
            if (explicitTagging)
            {
                EncodeTag(tag);
            }
            if (data == null)
            {
                EncodeLength(0);
            }
            else
            {
                EncodeLength(data.Length * 4);
                var length = data.Length;

                for (var i = 0; i < length; ++i)
                {
                    var number = data[i];
                    OutputStream.WriteByte((byte)(Asn1Util.UrShift(number, 0x18) & 0xff));
                    OutputStream.WriteByte((byte)(Asn1Util.UrShift(number, 0x10) & 0xff));
                    OutputStream.WriteByte((byte)(Asn1Util.UrShift(number, 8) & 0xff));
                    OutputStream.WriteByte((byte)(number & 0xff));
                }
            }
        }
Exemplo n.º 2
0
        public virtual void EncodeIdentifier(long ident)
        {
            var number          = 0x7fL;
            var identBytesCount = Asn1RunTime.GetIdentBytesCount(ident);

            number = number << (7 * identBytesCount);

            if (identBytesCount > 0)
            {
                while (identBytesCount > 0)
                {
                    number = Asn1Util.UrShift(number, 7);
                    identBytesCount--;

                    var num3 = Asn1Util.UrShift(ident & number, identBytesCount * 7);

                    if (identBytesCount != 0)
                    {
                        num3 |= 0x80L;
                    }

                    OutputStream.WriteByte((byte)num3);
                }
            }
            else
            {
                OutputStream.WriteByte(0);
            }
        }
Exemplo n.º 3
0
        private static int TrailingZerosCnt(long w)
        {
            var num = Asn1RunTime.IntTrailingZerosCnt((int)w);

            if (num >= RealBase16)
            {
                return(Asn1RunTime.IntTrailingZerosCnt((int)Asn1Util.UrShift(w, RealBase16)) + RealBase16);
            }

            return(num);
        }
Exemplo n.º 4
0
        public override void EncodeUnivString(int[] value, bool explicitTagging, Asn1Tag tag)
        {
            if ((value == null) || (value.Length <= 250))
            {
                base.EncodeUnivString(value, explicitTagging, tag);
            }
            else
            {
                if (explicitTagging)
                {
                    EncodeTagAndIndefLen(Asn1UniversalString.Tag.Class, 0x20, Asn1UniversalString.Tag.IdCode);
                }
                else
                {
                    OutputStream.WriteByte(0x80);
                }

                for (var i = 0; i < value.Length; i += 250)
                {
                    var num2 = value.Length - i;

                    if (num2 > 250)
                    {
                        num2 = 250;
                    }

                    EncodeTagAndLength(Asn1OctetString.Tag, num2 * 4);

                    for (int j = 0; j < num2; j++)
                    {
                        var number = value[j + i];

                        OutputStream.WriteByte((byte)(Asn1Util.UrShift(number, 0x18) & 0xff));
                        OutputStream.WriteByte((byte)(Asn1Util.UrShift(number, 0x10) & 0xff));
                        OutputStream.WriteByte((byte)(Asn1Util.UrShift(number, 8) & 0xff));
                        OutputStream.WriteByte((byte)(number & 0xff));
                    }
                }

                EncodeEoc();
            }
        }
Exemplo n.º 5
0
        public override void Encode(Asn1BerOutputStream outs, bool explicitTagging)
        {
            if (explicitTagging)
            {
                outs.EncodeTag(Tag);
            }

            if (Value == 0.0)
            {
                outs.EncodeLength(0);
            }
            else if (Value == double.NegativeInfinity)
            {
                outs.EncodeIntValue(MinusInfinity, true);
            }
            else if (Value == double.PositiveInfinity)
            {
                outs.EncodeIntValue(PlusInfinity, true);
            }
            else
            {
                var len  = 1;
                var num2 = BitConverter.DoubleToInt64Bits(Value);
                var num3 = ((num2 >> RealIso6093Mask) == 0L) ? 1 : -1;
                var num4 = ((int)((num2 >> 0x34) & 0x7ffL)) - 0x433;
                var w    = (num4 == 0) ? ((num2 & 0xfffffffffffffL) << 1) : ((num2 & 0xfffffffffffffL) | 0x10000000000000L);

                if (w != 0L)
                {
                    var bits = TrailingZerosCnt(w);
                    w     = Asn1Util.UrShift(w, bits);
                    num4 += bits;
                    len  += Asn1Util.GetUlongBytesCount(w);
                }
                else
                {
                    len++;
                }

                var num7 = RealBinary;

                if (num3 == -1)
                {
                    num7 |= PlusInfinity;
                }

                var bytesCount = Asn1Util.GetBytesCount(num4);
                len += bytesCount;

                switch (bytesCount)
                {
                case RealExplen2:
                    break;

                case RealExplen3:
                    num7 |= 1;
                    break;

                case RealExplenLong:
                    num7 |= 2;
                    break;

                default:
                    num7 |= 3;
                    len++;
                    break;
                }

                outs.EncodeLength(len);
                outs.WriteByte((byte)num7);

                if ((num7 & 3) == 3)
                {
                    outs.EncodeIntValue(bytesCount, false);
                }

                outs.EncodeIntValue(num4, false);
                outs.EncodeIntValue(w, false);
            }
        }
Exemplo n.º 6
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (double.IsNegativeInfinity(Value))
            {
                len = buffer.EncodeIntValue(MinusInfinity);
            }
            else if (double.IsPositiveInfinity(Value))
            {
                len = buffer.EncodeIntValue(PlusInfinity);
            }

            else if (Value != 0.0)
            {
                var num2 = BitConverter.DoubleToInt64Bits(Value);
                var num3 = ((num2 >> RealIso6093Mask) == 0L) ? 1 : -1;
                var num4 = ((int)((num2 >> 0x34) & 0x7ffL)) - 0x433;
                var w    = (num4 == 0) ? ((num2 & 0xfffffffffffffL) << 1) : ((num2 & 0xfffffffffffffL) | 0x10000000000000L);

                if (w != 0L)
                {
                    var bits = TrailingZerosCnt(w);
                    w     = Asn1Util.UrShift(w, bits);
                    num4 += bits;
                }

                len += buffer.EncodeIntValue(w);

                var num7 = buffer.EncodeIntValue(num4);
                len += num7;

                var num8 = RealBinary;

                if (num3 == -1)
                {
                    num8 |= PlusInfinity;
                }

                switch (num7)
                {
                case RealExplen2:
                    break;

                case RealExplen3:
                    num8 |= 1;
                    break;

                case RealExplenLong:
                    num8 |= 2;
                    break;

                default:
                    num8 |= 3;
                    len  += buffer.EncodeIntValue(num7);
                    break;
                }

                buffer.Copy((byte)num8);
                len++;
            }

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return(len);
        }