Esempio n. 1
0
        public static void VerifyReadNamedBitList_KeyUsage_OneByte(AsnEncodingRules ruleSet)
        {
            //     KeyUsage ::= BIT STRING {
            //       digitalSignature   (0),
            //       nonRepudiation     (1),
            //       keyEncipherment    (2),
            //       dataEncipherment   (3),
            //       keyAgreement       (4),
            //       keyCertSign        (5),
            //       cRLSign            (6),
            //       encipherOnly       (7),
            //       decipherOnly       (8) }

            X509KeyUsageExtension kuExt = new X509KeyUsageExtension(
                X509KeyUsageFlags.KeyCertSign | X509KeyUsageFlags.CrlSign,
                critical: false);

            BitArray expected = new BitArray(7);

            expected.Set(6, true);
            expected.Set(5, true);

            AsnReader reader = new AsnReader(kuExt.RawData, ruleSet);
            BitArray  actual = reader.ReadNamedBitList();

            Assert.Equal(expected.Cast <bool>(), actual.Cast <bool>());
        }
Esempio n. 2
0
        public static void ReadNamedBitList_BitArray_7993Bits(AsnEncodingRules ruleSet)
        {
            string inputHex;

            if (ruleSet == AsnEncodingRules.CER)
            {
                inputHex = "A580038203E8" + new string('0', 2000) + "03020780" + "0000";
            }
            else
            {
                inputHex = "858203E907" + new string('0', 1998) + "80";
            }

            byte[]    inputData = inputHex.HexToByteArray();
            AsnReader reader    = new AsnReader(inputData, ruleSet);
            BitArray  actual    = reader.ReadNamedBitList(new Asn1Tag(TagClass.ContextSpecific, 5));

            Assert.False(reader.HasData);

            BitArray expected = new BitArray(7993);

            expected.Set(7992, true);

            Assert.Equal(expected.Cast <bool>(), actual.Cast <bool>());
        }
Esempio n. 3
0
        public static void ReadNamedBitList_BitArray_Empty(AsnEncodingRules ruleSet)
        {
            byte[]    inputData = "030100".HexToByteArray();
            AsnReader reader    = new AsnReader(inputData, ruleSet);

            BitArray bits = reader.ReadNamedBitList();

            Assert.Equal(0, bits.Length);
            Assert.False(reader.HasData);
        }
Esempio n. 4
0
        public static void VerifyReadNamedBitList_KeyUsage_TwoByte(AsnEncodingRules ruleSet)
        {
            X509KeyUsageExtension kuExt = new X509KeyUsageExtension(
                X509KeyUsageFlags.KeyAgreement | X509KeyUsageFlags.DecipherOnly,
                critical: false);

            BitArray expected = new BitArray(9);

            expected.Set(4, true);
            expected.Set(8, true);

            AsnReader reader = new AsnReader(kuExt.RawData, ruleSet);
            BitArray  actual = reader.ReadNamedBitList();

            Assert.Equal(expected.Cast <bool>(), actual.Cast <bool>());
        }
Esempio n. 5
0
        public static void ReadNamedBitList_BitArray_EveryPattern(AsnEncodingRules ruleSet)
        {
            const string InputHex =
                // Tag
                "DF836B" +
                // Length
                "820101" +
                // Unused bit count
                "00" +
                // Reversed bits for byte patterns 0x00-0x1F
                "008040C020A060E0109050D030B070F0088848C828A868E8189858D838B878F8" +
                // Reversed bits for byte patterns 0x20-0x3F
                "048444C424A464E4149454D434B474F40C8C4CCC2CAC6CEC1C9C5CDC3CBC7CFC" +
                // Reversed bits for byte patterns 0x40-0x5F
                "028242C222A262E2129252D232B272F20A8A4ACA2AAA6AEA1A9A5ADA3ABA7AFA" +
                // Reversed bits for byte patterns 0x60-0x7F
                "068646C626A666E6169656D636B676F60E8E4ECE2EAE6EEE1E9E5EDE3EBE7EFE" +
                // Reversed bits for byte patterns 0x80-0x9F
                "018141C121A161E1119151D131B171F1098949C929A969E9199959D939B979F9" +
                // Reversed bits for byte patterns 0xA0-0xBF
                "058545C525A565E5159555D535B575F50D8D4DCD2DAD6DED1D9D5DDD3DBD7DFD" +
                // Reversed bits for byte patterns 0xC0-0xDF
                "038343C323A363E3139353D333B373F30B8B4BCB2BAB6BEB1B9B5BDB3BBB7BFB" +
                // Reversed bits for byte patterns 0xE0-0xFF
                "078747C727A767E7179757D737B777F70F8F4FCF2FAF6FEF1F9F5FDF3FBF7FFF";

            byte[]    inputData = InputHex.HexToByteArray();
            AsnReader reader    = new AsnReader(inputData, ruleSet);

            byte[] allTheBytes = new byte[256];

            for (int i = 0; i < allTheBytes.Length; i++)
            {
                allTheBytes[i] = (byte)i;
            }

            BitArray bits = reader.ReadNamedBitList(new Asn1Tag(TagClass.Private, 491));

            Assert.Equal(allTheBytes.Length * 8, bits.Length);
            Assert.False(reader.HasData);

            byte[] actual = new byte[allTheBytes.Length];
            bits.CopyTo(actual, 0);

            Assert.Equal(actual, actual);
        }
Esempio n. 6
0
        public static void ReadNamedBitList_BitArray_7992Bits(AsnEncodingRules ruleSet)
        {
            string inputHex = "848203E80008" + new string('0', 1994) + "02";

            byte[] inputData = inputHex.HexToByteArray();

            BitArray expected = new BitArray(7992);

            expected.Set(4, true);
            expected.Set(7990, true);

            AsnReader reader = new AsnReader(inputData, ruleSet);
            BitArray  actual = reader.ReadNamedBitList(new Asn1Tag(TagClass.ContextSpecific, 4));

            Assert.False(reader.HasData);

            Assert.Equal(expected.Cast <bool>(), actual.Cast <bool>());
        }
Esempio n. 7
0
        public static void ReadNamedBitList_BitArray(AsnEncodingRules ruleSet)
        {
            byte[] inputData = "440406400100".HexToByteArray();
            bool[] expected  = new bool[18];
            expected[1] = expected[15] = true;

            AsnReader reader = new AsnReader(inputData, ruleSet);

            BitArray bits = reader.ReadNamedBitList(new Asn1Tag(TagClass.Application, 4));

            Assert.Equal(expected.Length, bits.Length);
            Assert.False(reader.HasData);

            bool[] actual = new bool[expected.Length];
            bits.CopyTo(actual, 0);

            Assert.Equal(expected, actual);
        }