public X509CertificatePair ReadCertPair(
			Stream inStream)
		{
			if (inStream == null)
				throw new ArgumentNullException("inStream");
			if (!inStream.CanRead)
				throw new ArgumentException("inStream must be read-able", "inStream");

			if (currentStream == null)
			{
				currentStream = inStream;
			}
			else if (currentStream != inStream) // reset if input stream has changed
			{
				currentStream = inStream;
			}

			try
			{
				PushbackStream pis = new PushbackStream(inStream);
				int tag = pis.ReadByte();

				if (tag < 0)
					return null;

				pis.Unread(tag);

				return ReadDerCrossCertificatePair(pis);
			}
			catch (Exception e)
			{
				throw new CertificateException(e.ToString());
			}
		}
		/**
		 * Generates a certificate object and initializes it with the data
		 * read from the input stream inStream.
		 */
		public IX509AttributeCertificate ReadAttrCert(
			Stream inStream)
		{
			if (inStream == null)
				throw new ArgumentNullException("inStream");
			if (!inStream.CanRead)
				throw new ArgumentException("inStream must be read-able", "inStream");

			if (currentStream == null)
			{
				currentStream = inStream;
				sData = null;
				sDataObjectCount = 0;
			}
			else if (currentStream != inStream) // reset if input stream has changed
			{
				currentStream = inStream;
				sData = null;
				sDataObjectCount = 0;
			}

			try
			{
				if (sData != null)
				{
					if (sDataObjectCount != sData.Count)
					{
						return GetCertificate();
					}

					sData = null;
					sDataObjectCount = 0;
					return null;
				}

				PushbackStream pis = new PushbackStream(inStream);
				int tag = pis.ReadByte();

				if (tag < 0)
					return null;

				pis.Unread(tag);

				if (tag != 0x30)  // assume ascii PEM encoded.
				{
					return ReadPemCertificate(pis);
				}

				return ReadDerCertificate(new Asn1InputStream(pis));
			}
			catch (Exception e)
			{
				throw new CertificateException(e.ToString());
			}
		}
Exemplo n.º 3
0
		/**
		 * Generates a certificate revocation list (CRL) object and initializes
		 * it with the data read from the input stream inStream.
		 */
		public X509Crl ReadCrl(
			Stream inStream)
		{
			if (inStream == null)
				throw new ArgumentNullException("inStream");
			if (!inStream.CanRead)
				throw new ArgumentException("inStream must be read-able", "inStream");

			if (currentCrlStream == null)
			{
				currentCrlStream = inStream;
				sCrlData = null;
				sCrlDataObjectCount = 0;
			}
			else if (currentCrlStream != inStream) // reset if input stream has changed
			{
				currentCrlStream = inStream;
				sCrlData = null;
				sCrlDataObjectCount = 0;
			}

			try
			{
				if (sCrlData != null)
				{
					if (sCrlDataObjectCount != sCrlData.Count)
					{
						return GetCrl();
					}

					sCrlData = null;
					sCrlDataObjectCount = 0;
					return null;
				}

				PushbackStream pis = new PushbackStream(inStream);
				int tag = pis.ReadByte();

				if (tag < 0)
					return null;

				pis.Unread(tag);

				if (tag != 0x30)	// assume ascii PEM encoded.
				{
					return ReadPemCrl(pis);
				}

				Asn1InputStream asn1 = lazyAsn1
					?	new LazyAsn1InputStream(pis)
					:	new Asn1InputStream(pis);

				return ReadDerCrl(asn1);
			}
			catch (CrlException e)
			{
				throw e;
			}
			catch (Exception e)
			{
				throw new CrlException(e.ToString());
			}
		}