Exemple #1
0
        public virtual void EncodeLength(int len)
        {
            if (len >= 0)
            {
                var bytesCount = Asn1Util.GetBytesCount(len);

                if (len > 0x7f)
                {
                    OutputStream.WriteByte((byte)(bytesCount | 0x80));
                }
                for (var i = (8 * bytesCount) - 8; i >= 0; i -= 8)
                {
                    var num3 = (byte)((len >> i) & 0xff);
                    OutputStream.WriteByte(num3);
                }
            }
            else if (len == Asn1Status.IndefiniteLength)
            {
                OutputStream.WriteByte(0x80);
            }
        }
Exemple #2
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);
            }
        }