コード例 #1
0
        static public ASN1 FromInt32(Int32 value)
        {
            byte[] integer = BitConverterLE.GetBytes(value);
            Array.Reverse(integer);
            int x = 0;

            while ((x < integer.Length) && (integer [x] == 0x00))
            {
                x++;
            }
            ASN1 asn1 = new ASN1(0x02);

            switch (x)
            {
            case 0:
                asn1.Value = integer;
                break;

            case 4:
                asn1.Value = new byte [1];
                break;

            default:
                byte[] smallerInt = new byte [4 - x];
                Buffer.BlockCopy(integer, x, smallerInt, 0, smallerInt.Length);
                asn1.Value = smallerInt;
                break;
            }
            return(asn1);
        }
コード例 #2
0
ファイル: ASN1Convert.cs プロジェクト: Hengle/JellyTerain
        public static ASN1 FromInt32(int value)
        {
            byte[] bytes = BitConverterLE.GetBytes(value);
            Array.Reverse(bytes);
            int i;

            for (i = 0; i < bytes.Length && bytes[i] == 0; i++)
            {
            }
            ASN1 aSN = new ASN1(2);

            switch (i)
            {
            case 0:
                aSN.Value = bytes;
                break;

            case 4:
                aSN.Value = new byte[1];
                break;

            default:
            {
                byte[] array = new byte[4 - i];
                Buffer.BlockCopy(bytes, i, array, 0, array.Length);
                aSN.Value = array;
                break;
            }
            }
            return(aSN);
        }
コード例 #3
0
        public static ASN1 FromInt32(int value)
        {
            byte[] bytes = BitConverterLE.GetBytes(value);
            Array.Reverse(bytes);
            int num = 0;

            while (num < bytes.Length && bytes[num] == 0)
            {
                num++;
            }
            ASN1 asn  = new ASN1(2);
            int  num2 = num;

            if (num2 != 0)
            {
                if (num2 != 4)
                {
                    byte[] array = new byte[4 - num];
                    Buffer.BlockCopy(bytes, num, array, 0, array.Length);
                    asn.Value = array;
                }
                else
                {
                    asn.Value = new byte[1];
                }
            }
            else
            {
                asn.Value = bytes;
            }
            return(asn);
        }
コード例 #4
0
        public static ASN1 FromInt32(int value)
        {
            byte[] bytes = BitConverterLE.GetBytes(value);
            Array.Reverse((Array)bytes);
            int srcOffset = 0;

            while (srcOffset < bytes.Length && bytes[srcOffset] == (byte)0)
            {
                ++srcOffset;
            }
            ASN1 asN1 = new ASN1((byte)2);

            switch (srcOffset)
            {
            case 0:
                asN1.Value = bytes;
                break;

            case 4:
                asN1.Value = new byte[1];
                break;

            default:
                byte[] numArray = new byte[4 - srcOffset];
                Buffer.BlockCopy((Array)bytes, srcOffset, (Array)numArray, 0, numArray.Length);
                asN1.Value = numArray;
                break;
            }
            return(asN1);
        }