diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-11-12 22:57:06 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-11-12 22:57:06 +0700 |
commit | 809e86bbf8ed478e7aa7b9de8a3bfc3014289bd5 (patch) | |
tree | 9287ae725992c5972bed155ec4f4773fdace7b22 /crypto/src/pkix | |
parent | Refactoring of "unused bits" changes (diff) | |
download | BouncyCastle.NET-ed25519-809e86bbf8ed478e7aa7b9de8a3bfc3014289bd5.tar.xz |
Review of culture-independent String comparison methods
Diffstat (limited to 'crypto/src/pkix')
-rw-r--r-- | crypto/src/pkix/PkixCertPath.cs | 6 | ||||
-rw-r--r-- | crypto/src/pkix/PkixCertPathValidatorUtilities.cs | 2 | ||||
-rw-r--r-- | crypto/src/pkix/PkixNameConstraintValidator.cs | 87 |
3 files changed, 48 insertions, 47 deletions
diff --git a/crypto/src/pkix/PkixCertPath.cs b/crypto/src/pkix/PkixCertPath.cs index d03709167..3c428f6fb 100644 --- a/crypto/src/pkix/PkixCertPath.cs +++ b/crypto/src/pkix/PkixCertPath.cs @@ -357,7 +357,7 @@ namespace Org.BouncyCastle.Pkix public virtual byte[] GetEncoded( string encoding) { - if (Platform.CompareIgnoreCase(encoding, "PkiPath") == 0) + if (Platform.EqualsIgnoreCase(encoding, "PkiPath")) { Asn1EncodableVector v = new Asn1EncodableVector(); @@ -368,7 +368,7 @@ namespace Org.BouncyCastle.Pkix return ToDerEncoded(new DerSequence(v)); } - else if (Platform.CompareIgnoreCase(encoding, "PKCS7") == 0) + else if (Platform.EqualsIgnoreCase(encoding, "PKCS7")) { Asn1.Pkcs.ContentInfo encInfo = new Asn1.Pkcs.ContentInfo( PkcsObjectIdentifiers.Data, null); @@ -389,7 +389,7 @@ namespace Org.BouncyCastle.Pkix return ToDerEncoded(new Asn1.Pkcs.ContentInfo(PkcsObjectIdentifiers.SignedData, sd)); } - else if (Platform.CompareIgnoreCase(encoding, "PEM") == 0) + else if (Platform.EqualsIgnoreCase(encoding, "PEM")) { MemoryStream bOut = new MemoryStream(); PemWriter pWrt = new PemWriter(new StreamWriter(bOut)); diff --git a/crypto/src/pkix/PkixCertPathValidatorUtilities.cs b/crypto/src/pkix/PkixCertPathValidatorUtilities.cs index acea77856..a2704a746 100644 --- a/crypto/src/pkix/PkixCertPathValidatorUtilities.cs +++ b/crypto/src/pkix/PkixCertPathValidatorUtilities.cs @@ -230,7 +230,7 @@ namespace Org.BouncyCastle.Pkix { try { - if (location.StartsWith("ldap://")) + if (Platform.StartsWith(location, "ldap://")) { // ldap://directory.d-trust.net/CN=D-TRUST // Qualified CA 2003 1:PN,O=D-Trust GmbH,C=DE diff --git a/crypto/src/pkix/PkixNameConstraintValidator.cs b/crypto/src/pkix/PkixNameConstraintValidator.cs index cf944beae..f4ae73925 100644 --- a/crypto/src/pkix/PkixNameConstraintValidator.cs +++ b/crypto/src/pkix/PkixNameConstraintValidator.cs @@ -662,7 +662,7 @@ namespace Org.BouncyCastle.Pkix private bool WithinDomain(String testDomain, String domain) { String tempDomain = domain; - if (tempDomain.StartsWith(".")) + if (Platform.StartsWith(tempDomain, ".")) { tempDomain = tempDomain.Substring(1); } @@ -685,7 +685,7 @@ namespace Org.BouncyCastle.Pkix return false; } } - else if (!(Platform.CompareIgnoreCase(testDomainParts[i + d], domainParts[i]) == 0)) + else if (!Platform.EqualsIgnoreCase(testDomainParts[i + d], domainParts[i])) { return false; } @@ -737,7 +737,7 @@ namespace Org.BouncyCastle.Pkix String str = ((String)it.Current); // is sub domain or the same - if (WithinDomain(dns, str) || (Platform.CompareIgnoreCase(dns, str) == 0)) + if (WithinDomain(dns, str) || Platform.EqualsIgnoreCase(dns, str)) { throw new PkixNameConstraintValidatorException( "DNS is from an excluded subtree."); @@ -763,7 +763,7 @@ namespace Org.BouncyCastle.Pkix // both are a particular mailbox if (email2.IndexOf('@') != -1) { - if (Platform.CompareIgnoreCase(email1, email2) == 0) + if (Platform.EqualsIgnoreCase(email1, email2)) { union.Add(email1); } @@ -774,7 +774,7 @@ namespace Org.BouncyCastle.Pkix } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { if (WithinDomain(_sub, email2)) { @@ -789,7 +789,7 @@ namespace Org.BouncyCastle.Pkix // email2 specifies a particular host else { - if (Platform.CompareIgnoreCase(_sub, email2) == 0) + if (Platform.EqualsIgnoreCase(_sub, email2)) { union.Add(email2); } @@ -801,7 +801,7 @@ namespace Org.BouncyCastle.Pkix } } // email1 specifies a domain - else if (email1.StartsWith(".")) + else if (Platform.StartsWith(email1, ".")) { if (email2.IndexOf('@') != -1) { @@ -817,9 +817,9 @@ namespace Org.BouncyCastle.Pkix } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { - if (WithinDomain(email1, email2) || Platform.CompareIgnoreCase(email1, email2) == 0) + if (WithinDomain(email1, email2) || Platform.EqualsIgnoreCase(email1, email2)) { union.Add(email2); } @@ -852,7 +852,7 @@ namespace Org.BouncyCastle.Pkix if (email2.IndexOf('@') != -1) { String _sub = email2.Substring(email1.IndexOf('@') + 1); - if (Platform.CompareIgnoreCase(_sub, email1) == 0) + if (Platform.EqualsIgnoreCase(_sub, email1)) { union.Add(email1); } @@ -863,7 +863,7 @@ namespace Org.BouncyCastle.Pkix } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { if (WithinDomain(email1, email2)) { @@ -878,7 +878,7 @@ namespace Org.BouncyCastle.Pkix // email2 specifies a particular host else { - if (Platform.CompareIgnoreCase(email1, email2) == 0) + if (Platform.EqualsIgnoreCase(email1, email2)) { union.Add(email1); } @@ -900,7 +900,7 @@ namespace Org.BouncyCastle.Pkix // both are a particular mailbox if (email2.IndexOf('@') != -1) { - if (Platform.CompareIgnoreCase(email1, email2) == 0) + if (Platform.EqualsIgnoreCase(email1, email2)) { union.Add(email1); } @@ -911,7 +911,7 @@ namespace Org.BouncyCastle.Pkix } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { if (WithinDomain(_sub, email2)) { @@ -926,7 +926,7 @@ namespace Org.BouncyCastle.Pkix // email2 specifies a particular host else { - if (Platform.CompareIgnoreCase(_sub, email2) == 0) + if (Platform.EqualsIgnoreCase(_sub, email2)) { union.Add(email2); } @@ -939,7 +939,7 @@ namespace Org.BouncyCastle.Pkix } } // email1 specifies a domain - else if (email1.StartsWith(".")) + else if (Platform.StartsWith(email1, ".")) { if (email2.IndexOf('@') != -1) { @@ -955,9 +955,9 @@ namespace Org.BouncyCastle.Pkix } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { - if (WithinDomain(email1, email2) || Platform.CompareIgnoreCase(email1, email2) == 0) + if (WithinDomain(email1, email2) || Platform.EqualsIgnoreCase(email1, email2)) { union.Add(email2); } @@ -990,7 +990,7 @@ namespace Org.BouncyCastle.Pkix if (email2.IndexOf('@') != -1) { String _sub = email2.Substring(email1.IndexOf('@') + 1); - if (Platform.CompareIgnoreCase(_sub, email1) == 0) + if (Platform.EqualsIgnoreCase(_sub, email1)) { union.Add(email1); } @@ -1001,7 +1001,7 @@ namespace Org.BouncyCastle.Pkix } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { if (WithinDomain(email1, email2)) { @@ -1016,7 +1016,7 @@ namespace Org.BouncyCastle.Pkix // email2 specifies a particular host else { - if (Platform.CompareIgnoreCase(email1, email2) == 0) + if (Platform.EqualsIgnoreCase(email1, email2)) { union.Add(email1); } @@ -1122,13 +1122,13 @@ namespace Org.BouncyCastle.Pkix // both are a particular mailbox if (email2.IndexOf('@') != -1) { - if (Platform.CompareIgnoreCase(email1, email2) == 0) + if (Platform.EqualsIgnoreCase(email1, email2)) { intersect.Add(email1); } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { if (WithinDomain(_sub, email2)) { @@ -1138,14 +1138,14 @@ namespace Org.BouncyCastle.Pkix // email2 specifies a particular host else { - if (Platform.CompareIgnoreCase(_sub, email2) == 0) + if (Platform.EqualsIgnoreCase(_sub, email2)) { intersect.Add(email1); } } } // email specifies a domain - else if (email1.StartsWith(".")) + else if (Platform.StartsWith(email1, ".")) { if (email2.IndexOf('@') != -1) { @@ -1156,9 +1156,9 @@ namespace Org.BouncyCastle.Pkix } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { - if (WithinDomain(email1, email2) || (Platform.CompareIgnoreCase(email1, email2) == 0)) + if (WithinDomain(email1, email2) || Platform.EqualsIgnoreCase(email1, email2)) { intersect.Add(email1); } @@ -1181,13 +1181,13 @@ namespace Org.BouncyCastle.Pkix if (email2.IndexOf('@') != -1) { String _sub = email2.Substring(email2.IndexOf('@') + 1); - if (Platform.CompareIgnoreCase(_sub, email1) == 0) + if (Platform.EqualsIgnoreCase(_sub, email1)) { intersect.Add(email2); } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { if (WithinDomain(email1, email2)) { @@ -1197,7 +1197,7 @@ namespace Org.BouncyCastle.Pkix // email2 specifies a particular host else { - if (Platform.CompareIgnoreCase(email1, email2) == 0) + if (Platform.EqualsIgnoreCase(email1, email2)) { intersect.Add(email1); } @@ -1291,13 +1291,13 @@ namespace Org.BouncyCastle.Pkix // both are a particular mailbox if (email2.IndexOf('@') != -1) { - if (Platform.CompareIgnoreCase(email1, email2) == 0) + if (Platform.EqualsIgnoreCase(email1, email2)) { intersect.Add(email1); } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { if (WithinDomain(_sub, email2)) { @@ -1307,14 +1307,14 @@ namespace Org.BouncyCastle.Pkix // email2 specifies a particular host else { - if (Platform.CompareIgnoreCase(_sub, email2) == 0) + if (Platform.EqualsIgnoreCase(_sub, email2)) { intersect.Add(email1); } } } // email specifies a domain - else if (email1.StartsWith(".")) + else if (Platform.StartsWith(email1, ".")) { if (email2.IndexOf('@') != -1) { @@ -1325,9 +1325,9 @@ namespace Org.BouncyCastle.Pkix } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { - if (WithinDomain(email1, email2) || (Platform.CompareIgnoreCase(email1, email2) == 0)) + if (WithinDomain(email1, email2) || Platform.EqualsIgnoreCase(email1, email2)) { intersect.Add(email1); } @@ -1350,13 +1350,13 @@ namespace Org.BouncyCastle.Pkix if (email2.IndexOf('@') != -1) { String _sub = email2.Substring(email2.IndexOf('@') + 1); - if (Platform.CompareIgnoreCase(_sub, email1) == 0) + if (Platform.EqualsIgnoreCase(_sub, email1)) { intersect.Add(email2); } } // email2 specifies a domain - else if (email2.StartsWith(".")) + else if (Platform.StartsWith(email2, ".")) { if (WithinDomain(email1, email2)) { @@ -1366,7 +1366,7 @@ namespace Org.BouncyCastle.Pkix // email2 specifies a particular host else { - if (Platform.CompareIgnoreCase(email1, email2) == 0) + if (Platform.EqualsIgnoreCase(email1, email2)) { intersect.Add(email1); } @@ -1405,9 +1405,9 @@ namespace Org.BouncyCastle.Pkix { String host = ExtractHostFromURL(uri); // a host - if (!constraint.StartsWith(".")) + if (!Platform.StartsWith(constraint, ".")) { - if (Platform.CompareIgnoreCase(host, constraint) == 0) + if (Platform.EqualsIgnoreCase(host, constraint)) { return true; } @@ -1428,9 +1428,10 @@ namespace Org.BouncyCastle.Pkix // remove ':' after protocol, e.g. http: String sub = url.Substring(url.IndexOf(':') + 1); // extract host from Common Internet Scheme Syntax, e.g. http:// - if (sub.IndexOf("//") != -1) + int idxOfSlashes = Platform.IndexOf(sub, "//"); + if (idxOfSlashes != -1) { - sub = sub.Substring(sub.IndexOf("//") + 2); + sub = sub.Substring(idxOfSlashes + 2); } // first remove port, e.g. http://test.com:21 if (sub.LastIndexOf(':') != -1) |