Пример #1
0
        public KeyInfoX509Data(X509Certificate cert, IEnumerable <X509Certificate> additional, X509IncludeOption includeOption)
        {
            if (cert == null)
            {
                throw new ArgumentNullException("cert");
            }

            X509Certificate         certificate = Utils.CloneCertificate(cert);
            IList <X509Certificate> chain       = null;

            switch (includeOption)
            {
            case X509IncludeOption.ExcludeRoot:
                // Build the certificate chain
                chain = Utils.BuildCertificateChain(cert, additional);

                // Can't honor the option if we only have a partial chain.

                /*if ((chain.ChainStatus.Length > 0) &&
                 *  ((chain.ChainStatus[0].Status & X509ChainStatusFlags.PartialChain) == X509ChainStatusFlags.PartialChain))
                 * {
                 *  throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Partial_Chain);
                 * }*/

                for (int index = 0; index < (Utils.IsSelfSigned(chain) ? 1 : chain.Count - 1); index++)
                {
                    AddCertificate(chain[index]);
                }
                break;

            case X509IncludeOption.EndCertOnly:
                AddCertificate(certificate);
                break;

            case X509IncludeOption.WholeChain:
                // Build the certificate chain
                chain = Utils.BuildCertificateChain(cert, additional);

                // Can't honor the option if we only have a partial chain.

                /*if ((chain.ChainStatus.Length > 0) &&
                 *  ((chain.ChainStatus[0].Status & X509ChainStatusFlags.PartialChain) == X509ChainStatusFlags.PartialChain))
                 * {
                 *  throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Partial_Chain);
                 * }*/

                foreach (var element in chain)
                {
                    AddCertificate(element);
                }
                break;
            }
        }