コード例 #1
0
ファイル: ReadEnumerated.cs プロジェクト: pgovind/runtime
        public static void TagMustBeCorrect_Custom(PublicEncodingRules ruleSet)
        {
            byte[]    inputData = { 0x87, 2, 0, 0x80 };
            AsnReader reader    = new AsnReader(inputData, (AsnEncodingRules)ruleSet);

            AssertExtensions.Throws <ArgumentException>(
                "expectedTag",
                () => reader.ReadEnumeratedValue <ShortBacked>(Asn1Tag.Null));

            Assert.True(reader.HasData, "HasData after bad universal tag");

            Assert.Throws <CryptographicException>(() => reader.ReadEnumeratedValue <ShortBacked>());

            Assert.True(reader.HasData, "HasData after default tag");

            Assert.Throws <CryptographicException>(
                () => reader.ReadEnumeratedValue <ShortBacked>(new Asn1Tag(TagClass.Application, 0)));

            Assert.True(reader.HasData, "HasData after wrong custom class");

            Assert.Throws <CryptographicException>(
                () => reader.ReadEnumeratedValue <ShortBacked>(new Asn1Tag(TagClass.ContextSpecific, 1)));

            Assert.True(reader.HasData, "HasData after wrong custom tag value");

            ShortBacked value = reader.ReadEnumeratedValue <ShortBacked>(new Asn1Tag(TagClass.ContextSpecific, 7));

            Assert.Equal((ShortBacked)0x80, value);
            Assert.False(reader.HasData, "HasData after reading value");
        }
コード例 #2
0
ファイル: ReadEnumerated.cs プロジェクト: pgovind/runtime
 public static void GetExpectedValue_ShortBacked(
     PublicEncodingRules ruleSet,
     ShortBacked expectedValue,
     string inputHex)
 {
     GetExpectedValue(ruleSet, expectedValue, inputHex);
 }
コード例 #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());
        }
コード例 #4
0
ファイル: ReadEnumerated.cs プロジェクト: pgovind/runtime
        public static void ExpectedTag_IgnoresConstructed(
            PublicEncodingRules ruleSet,
            string inputHex,
            PublicTagClass tagClass,
            int tagValue)
        {
            byte[]      inputData = inputHex.HexToByteArray();
            AsnReader   reader    = new AsnReader(inputData, (AsnEncodingRules)ruleSet);
            ShortBacked val1      = reader.ReadEnumeratedValue <ShortBacked>(new Asn1Tag((TagClass)tagClass, tagValue, true));

            Assert.False(reader.HasData);
            reader = new AsnReader(inputData, (AsnEncodingRules)ruleSet);
            ShortBacked val2 = reader.ReadEnumeratedValue <ShortBacked>(new Asn1Tag((TagClass)tagClass, tagValue, false));

            Assert.False(reader.HasData);

            Assert.Equal(val1, val2);
        }
コード例 #5
0
ファイル: ReadEnumerated.cs プロジェクト: pgovind/runtime
        public static void TagMustBeCorrect_Universal(PublicEncodingRules ruleSet)
        {
            byte[]    inputData = { 0x0A, 1, 0x7E };
            AsnReader reader    = new AsnReader(inputData, (AsnEncodingRules)ruleSet);

            AssertExtensions.Throws <ArgumentException>(
                "expectedTag",
                () => reader.ReadEnumeratedValue <ShortBacked>(Asn1Tag.Null));

            Assert.True(reader.HasData, "HasData after bad universal tag");

            Assert.Throws <CryptographicException>(
                () => reader.ReadEnumeratedValue <ShortBacked>(new Asn1Tag(TagClass.ContextSpecific, 0)));

            Assert.True(reader.HasData, "HasData after wrong tag");

            ShortBacked value = reader.ReadEnumeratedValue <ShortBacked>();

            Assert.Equal((ShortBacked)0x7E, value);
            Assert.False(reader.HasData, "HasData after read");
        }