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); }
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); }
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()); }
public void Read_WithInvalidAsn1_Throws() { Assert.Throws <CryptographicException>( () => GeneralName.Read(new byte[] { 0x30, 0x07 })); }