public override string GetSubjectName(bool legacyV1Mode)
 {
     ThrowIfContextInvalid();
     if (legacyV1Mode)
     {
         return(_cert.SubjectName);
     }
     else
     {
         return(MX.X501.ToString(_cert.GetSubjectName(), true, ", ", true));
     }
 }
Esempio n. 2
0
        public string GetNameInfo(X509NameType nameType, bool forIssuer)
        {
            switch (nameType)
            {
            case X509NameType.SimpleName:
                if (_cert == null)
                {
                    throw new CryptographicException(empty_error);
                }
                // return CN= or, if missing, the first part of the DN
                ASN1 sn = forIssuer ? _cert.GetIssuerName() : _cert.GetSubjectName();
                ASN1 dn = Find(commonName, sn);
                if (dn != null)
                {
                    return(GetValueAsString(dn));
                }
                if (sn.Count == 0)
                {
                    return(String.Empty);
                }
                ASN1 last_entry = sn [sn.Count - 1];
                if (last_entry.Count == 0)
                {
                    return(String.Empty);
                }
                return(GetValueAsString(last_entry [0]));

            case X509NameType.EmailName:
                // return the E= part of the DN (if present)
                ASN1 e = Find(email, forIssuer ? _cert.GetIssuerName() : _cert.GetSubjectName());
                if (e != null)
                {
                    return(GetValueAsString(e));
                }
                return(String.Empty);

            case X509NameType.UpnName:
                // FIXME - must find/create test case
                return(String.Empty);

            case X509NameType.DnsName:
                // return the CN= part of the DN (if present)
                ASN1 cn = Find(commonName, forIssuer ? _cert.GetIssuerName() : _cert.GetSubjectName());
                if (cn != null)
                {
                    return(GetValueAsString(cn));
                }
                return(String.Empty);

            case X509NameType.DnsFromAlternativeName:
                // FIXME - must find/create test case
                return(String.Empty);

            case X509NameType.UrlName:
                // FIXME - must find/create test case
                return(String.Empty);

            default:
                throw new ArgumentException("nameType");
            }
        }