private AttributeCertificateInfo(Asn1Sequence seq) { if (seq.Count < 7 || seq.Count > 9) { throw new ArgumentException("Bad sequence size: " + seq.Count); } version = DerInteger.GetInstance(seq[0]); holder = Holder.GetInstance(seq[1]); issuer = AttCertIssuer.GetInstance(seq[2]); signature = AlgorithmIdentifier.GetInstance(seq[3]); serialNumber = DerInteger.GetInstance(seq[4]); attrCertValidityPeriod = AttCertValidityPeriod.GetInstance(seq[5]); attributes = Asn1Sequence.GetInstance(seq[6]); for (int i = 7; i < seq.Count; i++) { Asn1Encodable asn1Encodable = seq[i]; if (asn1Encodable is DerBitString) { issuerUniqueID = DerBitString.GetInstance(seq[i]); } else if (asn1Encodable is Asn1Sequence || asn1Encodable is X509Extensions) { extensions = X509Extensions.GetInstance(seq[i]); } } }
public void CheckAttributeCertificate( int id, byte[] cert) { Asn1Sequence seq = (Asn1Sequence)Asn1Object.FromByteArray(cert); string dump = Asn1Dump.DumpAsString(seq); AttributeCertificate obj = AttributeCertificate.GetInstance(seq); AttributeCertificateInfo acInfo = obj.ACInfo; // Version if (!(acInfo.Version.Equals(new DerInteger(1))) && (!(acInfo.Version.Equals(new DerInteger(2))))) { Fail("failed AC Version test for id " + id); } // Holder Holder h = acInfo.Holder; if (h == null) { Fail("failed AC Holder test, it's null, for id " + id); } // Issuer AttCertIssuer aci = acInfo.Issuer; if (aci == null) { Fail("failed AC Issuer test, it's null, for id " + id); } // Signature AlgorithmIdentifier sig = acInfo.Signature; if (sig == null) { Fail("failed AC Signature test for id " + id); } // Serial DerInteger serial = acInfo.SerialNumber; // Validity AttCertValidityPeriod validity = acInfo.AttrCertValidityPeriod; if (validity == null) { Fail("failed AC AttCertValidityPeriod test for id " + id); } // Attributes Asn1Sequence attribSeq = acInfo.Attributes; AttributeX509[] att = new AttributeX509[attribSeq.Count]; for (int i = 0; i < attribSeq.Count; i++) { att[i] = AttributeX509.GetInstance(attribSeq[i]); } // IssuerUniqueId // TODO, how to best test? // X509 Extensions X509Extensions ext = acInfo.Extensions; if (ext != null) { foreach (DerObjectIdentifier oid in ext.ExtensionOids) { X509Extension extVal = ext.GetExtension(oid); } } }