Exemple #1
0
        public static void ReadEnumeratedBytes_Throws(PublicEncodingRules ruleSet, string inputHex)
        {
            byte[]    inputData = inputHex.HexToByteArray();
            AsnReader reader    = new AsnReader(inputData, (AsnEncodingRules)ruleSet);

            Assert.Throws <CryptographicException>(() => reader.ReadEnumeratedBytes());
        }
Exemple #2
0
        public static void ReadEnumeratedBytes(PublicEncodingRules ruleSet)
        {
            const string Payload = "0102030405060708090A0B0C0D0E0F10";

            // ENUMERATED (payload) followed by INTEGER (0)
            byte[]    data   = ("0A10" + Payload + "020100").HexToByteArray();
            AsnReader reader = new AsnReader(data, (AsnEncodingRules)ruleSet);

            ReadOnlyMemory <byte> contents = reader.ReadEnumeratedBytes();

            Assert.Equal(0x10, contents.Length);
            Assert.Equal(Payload, contents.ByteArrayToHex());
        }
Exemple #3
0
        public static void ExpectedTag_IgnoresConstructed(
            AsnEncodingRules ruleSet,
            string inputHex,
            TagClass tagClass,
            int tagValue)
        {
            Asn1Tag primitiveTag   = new Asn1Tag(tagClass, tagValue, false);
            Asn1Tag constructedTag = new Asn1Tag(tagClass, tagValue, true);

            byte[] inputData = inputHex.HexToByteArray();

            AsnReader   reader = new AsnReader(inputData, ruleSet);
            ShortBacked val1   = reader.ReadEnumeratedValue <ShortBacked>(constructedTag);

            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);
            ShortBacked val2 = reader.ReadEnumeratedValue <ShortBacked>(primitiveTag);

            Assert.False(reader.HasData);

            Assert.Equal(val1, val2);

            reader = new AsnReader(inputData, ruleSet);
            ShortBacked val3 = (ShortBacked)reader.ReadEnumeratedValue(typeof(ShortBacked), constructedTag);

            Assert.False(reader.HasData);

            Assert.Equal(val1, val3);

            reader = new AsnReader(inputData, ruleSet);
            ShortBacked val4 = (ShortBacked)reader.ReadEnumeratedValue(typeof(ShortBacked), primitiveTag);

            Assert.False(reader.HasData);

            Assert.Equal(val1, val4);

            reader = new AsnReader(inputData, ruleSet);
            ReadOnlyMemory <byte> bytes1 = reader.ReadEnumeratedBytes(constructedTag);

            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);
            ReadOnlyMemory <byte> bytes2 = reader.ReadEnumeratedBytes(primitiveTag);

            Assert.False(reader.HasData);

            Assert.Equal(bytes1.ByteArrayToHex(), bytes2.ByteArrayToHex());
            Assert.Equal("FF", bytes1.ByteArrayToHex());
        }