예제 #1
0
        public void Read_WithDistinguishedName_ReturnsGeneralName()
        {
            var bytes = new BcGeneralName(BcGeneralName.DirectoryName, new X509Name("CN=test")).GetDerEncoded();

            var generalName = GeneralName.Read(bytes);

            Assert.NotNull(generalName);
            Assert.Equal("CN=test", generalName.DirectoryName.Name);
        }
예제 #2
0
        public void Read_WithUnsupportedChoice_Throws()
        {
            var bytes = new BcGeneralName(BcGeneralName.RegisteredID, new DerObjectIdentifier("1.2.3")).GetDerEncoded();

            var exception = Assert.Throws <SignatureException>(
                () => GeneralName.Read(bytes));

            Assert.Equal("The ASN.1 data is unsupported.", exception.Message);
        }
예제 #3
0
        private static IReadOnlyList <GeneralName> ReadGeneralNames(DerSequenceReader reader)
        {
            var sequenceReader = reader.ReadSequence();
            var generalNames   = new List <GeneralName>(capacity: 1);

            var generalName = GeneralName.Read(sequenceReader);

            if (generalName != null)
            {
                generalNames.Add(generalName);
            }

            if (sequenceReader.HasData)
            {
                throw new SignatureException(Strings.InvalidAsn1);
            }

            return(generalNames.AsReadOnly());
        }
예제 #4
0
 public void Read_WithInvalidAsn1_Throws()
 {
     Assert.Throws <CryptographicException>(
         () => GeneralName.Read(new byte[] { 0x30, 0x07 }));
 }