Inheritance: Asn1Encodable, IAsn1Choice
		public override void PerformTest()
		{
			RequestedCertificate.Choice type = RequestedCertificate.Choice.AttributeCertificate;
			X509CertificateStructure cert = X509CertificateStructure.GetInstance(
				Asn1Object.FromByteArray(certBytes));

			byte[] certOctets = new byte[20];
			RequestedCertificate requested = new RequestedCertificate(type, certOctets);

			checkConstruction(requested, type, certOctets, null);

			requested = new RequestedCertificate(cert);

			checkConstruction(requested, RequestedCertificate.Choice.Certificate, null, cert);

			requested = RequestedCertificate.GetInstance(null);

			if (requested != null)
			{
				Fail("null GetInstance() failed.");
			}

			try
			{
				RequestedCertificate.GetInstance(new object());

				Fail("GetInstance() failed to detect bad object.");
			}
			catch (ArgumentException)
			{
				// expected
			}
		}
Example #2
0
 public static RequestedCertificate GetInstance(Asn1TaggedObject obj, bool isExplicit)
 {
     if (!isExplicit)
     {
         throw new ArgumentException("choice item must be explicitly tagged");
     }
     return(RequestedCertificate.GetInstance(obj.GetObject()));
 }
		private void checkValues(
			RequestedCertificate		requested,
			RequestedCertificate.Choice	type,
			byte[]						certOctets,
			X509CertificateStructure	cert)
		{
			checkMandatoryField("certType", (int) type, (int) requested.Type);

			if (requested.Type == RequestedCertificate.Choice.Certificate)
			{
				checkMandatoryField("certificate", cert.GetEncoded(), requested.GetCertificateBytes());
			}
			else
			{
				checkMandatoryField("certificateOctets", certOctets, requested.GetCertificateBytes());
			}
		}
		private void checkConstruction(
			RequestedCertificate		requested,
			RequestedCertificate.Choice	type,
			byte[]						certOctets,
			X509CertificateStructure	cert)
		{
			checkValues(requested, type, certOctets, cert);

			requested = RequestedCertificate.GetInstance(requested);

			checkValues(requested, type, certOctets, cert);

			Asn1InputStream aIn = new Asn1InputStream(requested.ToAsn1Object().GetEncoded());

			object obj = aIn.ReadObject();

			requested = RequestedCertificate.GetInstance(obj);

			checkValues(requested, type, certOctets, cert);
		}