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/security | |
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/security')
-rw-r--r-- | crypto/src/security/CipherUtilities.cs | 6 | ||||
-rw-r--r-- | crypto/src/security/GeneratorUtilities.cs | 2 | ||||
-rw-r--r-- | crypto/src/security/MacUtilities.cs | 6 | ||||
-rw-r--r-- | crypto/src/security/PbeUtilities.cs | 32 | ||||
-rw-r--r-- | crypto/src/security/SecureRandom.cs | 2 | ||||
-rw-r--r-- | crypto/src/security/SignerUtilities.cs | 6 |
6 files changed, 27 insertions, 27 deletions
diff --git a/crypto/src/security/CipherUtilities.cs b/crypto/src/security/CipherUtilities.cs index cdb711f69..9ad4228ac 100644 --- a/crypto/src/security/CipherUtilities.cs +++ b/crypto/src/security/CipherUtilities.cs @@ -278,9 +278,9 @@ namespace Org.BouncyCastle.Security - if (algorithm.StartsWith("PBE")) + if (Platform.StartsWith(algorithm, "PBE")) { - if (algorithm.EndsWith("-CBC")) + if (Platform.EndsWith(algorithm, "-CBC")) { if (algorithm == "PBEWITHSHA1ANDDES-CBC") { @@ -305,7 +305,7 @@ namespace Org.BouncyCastle.Security new CbcBlockCipher(new RC2Engine())); } } - else if (algorithm.EndsWith("-BC") || algorithm.EndsWith("-OPENSSL")) + else if (Platform.EndsWith(algorithm, "-BC") || Platform.EndsWith(algorithm, "-OPENSSL")) { if (Strings.IsOneOf(algorithm, "PBEWITHSHAAND128BITAES-CBC-BC", diff --git a/crypto/src/security/GeneratorUtilities.cs b/crypto/src/security/GeneratorUtilities.cs index 45fbc9425..7562a76be 100644 --- a/crypto/src/security/GeneratorUtilities.cs +++ b/crypto/src/security/GeneratorUtilities.cs @@ -299,7 +299,7 @@ namespace Org.BouncyCastle.Security return new DsaKeyPairGenerator(); // "EC", "ECDH", "ECDHC", "ECDSA", "ECGOST3410", "ECMQV" - if (canonicalName.StartsWith("EC")) + if (Platform.StartsWith(canonicalName, "EC")) return new ECKeyPairGenerator(canonicalName); if (canonicalName == "ELGAMAL") diff --git a/crypto/src/security/MacUtilities.cs b/crypto/src/security/MacUtilities.cs index 41cf5e9e2..fab9b1d41 100644 --- a/crypto/src/security/MacUtilities.cs +++ b/crypto/src/security/MacUtilities.cs @@ -114,15 +114,15 @@ namespace Org.BouncyCastle.Security mechanism = upper; } - if (mechanism.StartsWith("PBEWITH")) + if (Platform.StartsWith(mechanism, "PBEWITH")) { mechanism = mechanism.Substring("PBEWITH".Length); } - if (CultureInfo.InvariantCulture.CompareInfo.IsPrefix(mechanism, "HMAC", CompareOptions.Ordinal)) + if (Platform.StartsWith(mechanism, "HMAC")) { string digestName; - if (mechanism.StartsWith("HMAC-") || mechanism.StartsWith("HMAC/")) + if (Platform.StartsWith(mechanism, "HMAC-") || Platform.StartsWith(mechanism, "HMAC/")) { digestName = mechanism.Substring(5); } diff --git a/crypto/src/security/PbeUtilities.cs b/crypto/src/security/PbeUtilities.cs index 0cb235ae6..33f31e5b4 100644 --- a/crypto/src/security/PbeUtilities.cs +++ b/crypto/src/security/PbeUtilities.cs @@ -444,7 +444,7 @@ namespace Org.BouncyCastle.Security } } } - else if (mechanism.StartsWith("PBEwithSHA-1")) + else if (Platform.StartsWith(mechanism, "PBEwithSHA-1")) { PbeParametersGenerator generator = MakePbeGenerator( (string) algorithmType[mechanism], new Sha1Digest(), keyBytes, salt, iterationCount); @@ -494,7 +494,7 @@ namespace Org.BouncyCastle.Security parameters = generator.GenerateDerivedParameters("RC2", 64, 64); } } - else if (mechanism.StartsWith("PBEwithSHA-256")) + else if (Platform.StartsWith(mechanism, "PBEwithSHA-256")) { PbeParametersGenerator generator = MakePbeGenerator( (string) algorithmType[mechanism], new Sha256Digest(), keyBytes, salt, iterationCount); @@ -512,7 +512,7 @@ namespace Org.BouncyCastle.Security parameters = generator.GenerateDerivedParameters("AES", 256, 128); } } - else if (mechanism.StartsWith("PBEwithMD5")) + else if (Platform.StartsWith(mechanism, "PBEwithMD5")) { PbeParametersGenerator generator = MakePbeGenerator( (string)algorithmType[mechanism], new MD5Digest(), keyBytes, salt, iterationCount); @@ -538,7 +538,7 @@ namespace Org.BouncyCastle.Security parameters = generator.GenerateDerivedParameters("AES", 256, 128); } } - else if (mechanism.StartsWith("PBEwithMD2")) + else if (Platform.StartsWith(mechanism, "PBEwithMD2")) { PbeParametersGenerator generator = MakePbeGenerator( (string)algorithmType[mechanism], new MD2Digest(), keyBytes, salt, iterationCount); @@ -551,7 +551,7 @@ namespace Org.BouncyCastle.Security parameters = generator.GenerateDerivedParameters("RC2", 64, 64); } } - else if (mechanism.StartsWith("PBEwithHmac")) + else if (Platform.StartsWith(mechanism, "PBEwithHmac")) { string digestName = mechanism.Substring("PBEwithHmac".Length); IDigest digest = DigestUtilities.GetDigest(digestName); @@ -594,39 +594,39 @@ namespace Org.BouncyCastle.Security { string mechanism = (string)algorithms[Platform.ToUpperInvariant(algorithm)]; - if (mechanism.StartsWith("PBEwithHmac")) + if (Platform.StartsWith(mechanism, "PBEwithHmac")) { string digestName = mechanism.Substring("PBEwithHmac".Length); return MacUtilities.GetMac("HMAC/" + digestName); } - if (mechanism.StartsWith("PBEwithMD2") - || mechanism.StartsWith("PBEwithMD5") - || mechanism.StartsWith("PBEwithSHA-1") - || mechanism.StartsWith("PBEwithSHA-256")) + if (Platform.StartsWith(mechanism, "PBEwithMD2") + || Platform.StartsWith(mechanism, "PBEwithMD5") + || Platform.StartsWith(mechanism, "PBEwithSHA-1") + || Platform.StartsWith(mechanism, "PBEwithSHA-256")) { - if (mechanism.EndsWith("AES-CBC-BC") || mechanism.EndsWith("AES-CBC-OPENSSL")) + if (Platform.EndsWith(mechanism, "AES-CBC-BC") || Platform.EndsWith(mechanism, "AES-CBC-OPENSSL")) { return CipherUtilities.GetCipher("AES/CBC"); } - if (mechanism.EndsWith("DES-CBC")) + if (Platform.EndsWith(mechanism, "DES-CBC")) { return CipherUtilities.GetCipher("DES/CBC"); } - if (mechanism.EndsWith("DESEDE-CBC")) + if (Platform.EndsWith(mechanism, "DESEDE-CBC")) { return CipherUtilities.GetCipher("DESEDE/CBC"); } - if (mechanism.EndsWith("RC2-CBC")) + if (Platform.EndsWith(mechanism, "RC2-CBC")) { return CipherUtilities.GetCipher("RC2/CBC"); } - if (mechanism.EndsWith("RC4")) + if (Platform.EndsWith(mechanism, "RC4")) { return CipherUtilities.GetCipher("RC4"); } @@ -643,7 +643,7 @@ namespace Org.BouncyCastle.Security private static ICipherParameters FixDesParity(string mechanism, ICipherParameters parameters) { - if (!mechanism.EndsWith("DES-CBC") & !mechanism.EndsWith("DESEDE-CBC")) + if (!Platform.EndsWith(mechanism, "DES-CBC") && !Platform.EndsWith(mechanism, "DESEDE-CBC")) { return parameters; } diff --git a/crypto/src/security/SecureRandom.cs b/crypto/src/security/SecureRandom.cs index 5bad57a14..4894a93e6 100644 --- a/crypto/src/security/SecureRandom.cs +++ b/crypto/src/security/SecureRandom.cs @@ -91,7 +91,7 @@ namespace Org.BouncyCastle.Security public static SecureRandom GetInstance(string algorithm, bool autoSeed) { string upper = Platform.ToUpperInvariant(algorithm); - if (upper.EndsWith("PRNG")) + if (Platform.EndsWith(upper, "PRNG")) { string digestName = upper.Substring(0, upper.Length - "PRNG".Length); DigestRandomGenerator prng = CreatePrng(digestName, autoSeed); diff --git a/crypto/src/security/SignerUtilities.cs b/crypto/src/security/SignerUtilities.cs index bd1515147..9a4915b46 100644 --- a/crypto/src/security/SignerUtilities.cs +++ b/crypto/src/security/SignerUtilities.cs @@ -312,7 +312,7 @@ namespace Org.BouncyCastle.Security return GetPssX509Parameters("SHA-1"); } - if (mechanism.EndsWith("withRSAandMGF1")) + if (Platform.EndsWith(mechanism, "withRSAandMGF1")) { string digestName = mechanism.Substring(0, mechanism.Length - "withRSAandMGF1".Length); return GetPssX509Parameters(digestName); @@ -534,10 +534,10 @@ namespace Org.BouncyCastle.Security return new Iso9796d2Signer(new RsaBlindedEngine(), new RipeMD160Digest(), true); } - if (mechanism.EndsWith("/X9.31")) + if (Platform.EndsWith(mechanism, "/X9.31")) { string x931 = mechanism.Substring(0, mechanism.Length - "/X9.31".Length); - int withPos = x931.IndexOf("WITH"); + int withPos = Platform.IndexOf(x931, "WITH"); if (withPos > 0) { int endPos = withPos + "WITH".Length; |