diff options
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r-- | crypto/src/asn1/DerBitString.cs | 36 | ||||
-rw-r--r-- | crypto/src/asn1/DerGeneralizedTime.cs | 6 | ||||
-rw-r--r-- | crypto/src/asn1/DerObjectIdentifier.cs | 2 | ||||
-rw-r--r-- | crypto/src/asn1/anssi/ANSSINamedCurves.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/sec/SECNamedCurves.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/x509/GeneralName.cs | 5 | ||||
-rw-r--r-- | crypto/src/asn1/x509/X509Name.cs | 16 | ||||
-rw-r--r-- | crypto/src/asn1/x9/X962NamedCurves.cs | 4 |
9 files changed, 37 insertions, 44 deletions
diff --git a/crypto/src/asn1/DerBitString.cs b/crypto/src/asn1/DerBitString.cs index ad7a7e349..fa37e6c0c 100644 --- a/crypto/src/asn1/DerBitString.cs +++ b/crypto/src/asn1/DerBitString.cs @@ -95,29 +95,29 @@ namespace Org.BouncyCastle.Asn1 Debug.Assert(0 < bytes && bytes <= 4); - byte[] result = new byte[bytes]; + byte[] data = new byte[bytes]; --bytes; for (int i = 0; i < bytes; i++) { - result[i] = (byte)namedBits; + data[i] = (byte)namedBits; namedBits >>= 8; } Debug.Assert((namedBits & 0xFF) != 0); - result[bytes] = (byte)namedBits; + data[bytes] = (byte)namedBits; - int pad = 0; - while ((namedBits & (1 << pad)) == 0) + int padBits = 0; + while ((namedBits & (1 << padBits)) == 0) { - ++pad; + ++padBits; } - Debug.Assert(pad < 8); + Debug.Assert(padBits < 8); - this.mData = result; - this.mPadBits = pad; + this.mData = data; + this.mPadBits = padBits; } public DerBitString( @@ -187,20 +187,18 @@ namespace Org.BouncyCastle.Asn1 { int last = mData[mData.Length - 1]; int mask = (1 << mPadBits) - 1; + int unusedBits = last & mask; - if ((last & mask) != 0) + if (unusedBits != 0) { - byte[] result = Arrays.Prepend(mData, (byte)mPadBits); + byte[] contents = Arrays.Prepend(mData, (byte)mPadBits); /* - * X.690-0207 11.2.1: Each unused bit in the final octet of the encoding of a bit string value shall be set to zero. - * - * NOTE: 'pad' is constrained to be 0 if 'bytes' are empty, in which case this is a no-op. - */ - last ^= (last & mask); - result[result.Length - 1] &= (byte)last; - - derOut.WriteEncoded(Asn1Tags.BitString, result); + * X.690-0207 11.2.1: Each unused bit in the final octet of the encoding of a bit string value shall be set to zero. + */ + contents[contents.Length - 1] = (byte)(last ^ unusedBits); + + derOut.WriteEncoded(Asn1Tags.BitString, contents); return; } } diff --git a/crypto/src/asn1/DerGeneralizedTime.cs b/crypto/src/asn1/DerGeneralizedTime.cs index 17c42e7cf..79b008768 100644 --- a/crypto/src/asn1/DerGeneralizedTime.cs +++ b/crypto/src/asn1/DerGeneralizedTime.cs @@ -204,7 +204,7 @@ namespace Org.BouncyCastle.Asn1 string d = time; bool makeUniversal = false; - if (d.EndsWith("Z")) + if (Platform.EndsWith(d, "Z")) { if (HasFractionalSeconds) { @@ -223,7 +223,7 @@ namespace Org.BouncyCastle.Asn1 if (HasFractionalSeconds) { - int fCount = d.IndexOf("GMT") - 1 - d.IndexOf('.'); + int fCount = Platform.IndexOf(d, "GMT") - 1 - d.IndexOf('.'); formatStr = @"yyyyMMddHHmmss." + FString(fCount) + @"'GMT'zzz"; } else @@ -267,7 +267,7 @@ namespace Org.BouncyCastle.Asn1 * NOTE: DateTime.Kind and DateTimeStyles.AssumeUniversal not available in .NET 1.1 */ DateTimeStyles style = DateTimeStyles.None; - if (format.EndsWith("Z")) + if (Platform.EndsWith(format, "Z")) { try { diff --git a/crypto/src/asn1/DerObjectIdentifier.cs b/crypto/src/asn1/DerObjectIdentifier.cs index f9f6a79d6..563c637e5 100644 --- a/crypto/src/asn1/DerObjectIdentifier.cs +++ b/crypto/src/asn1/DerObjectIdentifier.cs @@ -83,7 +83,7 @@ namespace Org.BouncyCastle.Asn1 public virtual bool On(DerObjectIdentifier stem) { string id = Id, stemId = stem.Id; - return id.Length > stemId.Length && id[stemId.Length] == '.' && id.StartsWith(stemId); + return id.Length > stemId.Length && id[stemId.Length] == '.' && Platform.StartsWith(id, stemId); } internal DerObjectIdentifier(byte[] bytes) diff --git a/crypto/src/asn1/anssi/ANSSINamedCurves.cs b/crypto/src/asn1/anssi/ANSSINamedCurves.cs index c7f9545f2..d0c90ebf1 100644 --- a/crypto/src/asn1/anssi/ANSSINamedCurves.cs +++ b/crypto/src/asn1/anssi/ANSSINamedCurves.cs @@ -60,7 +60,7 @@ namespace Org.BouncyCastle.Asn1.Anssi DerObjectIdentifier oid, X9ECParametersHolder holder) { - objIds.Add(Platform.ToLowerInvariant(name), oid); + objIds.Add(Platform.ToUpperInvariant(name), oid); names.Add(oid, name); curves.Add(oid, holder); } @@ -99,7 +99,7 @@ namespace Org.BouncyCastle.Asn1.Anssi public static DerObjectIdentifier GetOid( string name) { - return (DerObjectIdentifier)objIds[Platform.ToLowerInvariant(name)]; + return (DerObjectIdentifier)objIds[Platform.ToUpperInvariant(name)]; } /** diff --git a/crypto/src/asn1/sec/SECNamedCurves.cs b/crypto/src/asn1/sec/SECNamedCurves.cs index ca71a4e66..b753ac5d1 100644 --- a/crypto/src/asn1/sec/SECNamedCurves.cs +++ b/crypto/src/asn1/sec/SECNamedCurves.cs @@ -1088,7 +1088,7 @@ namespace Org.BouncyCastle.Asn1.Sec DerObjectIdentifier oid, X9ECParametersHolder holder) { - objIds.Add(Platform.ToLowerInvariant(name), oid); + objIds.Add(Platform.ToUpperInvariant(name), oid); names.Add(oid, name); curves.Add(oid, holder); } @@ -1160,7 +1160,7 @@ namespace Org.BouncyCastle.Asn1.Sec public static DerObjectIdentifier GetOid( string name) { - return (DerObjectIdentifier)objIds[Platform.ToLowerInvariant(name)]; + return (DerObjectIdentifier)objIds[Platform.ToUpperInvariant(name)]; } /** diff --git a/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs b/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs index ba3eda620..9a82db319 100644 --- a/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs +++ b/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs @@ -387,7 +387,7 @@ namespace Org.BouncyCastle.Asn1.TeleTrust DerObjectIdentifier oid, X9ECParametersHolder holder) { - objIds.Add(Platform.ToLowerInvariant(name), oid); + objIds.Add(Platform.ToUpperInvariant(name), oid); names.Add(oid, name); curves.Add(oid, holder); } @@ -439,7 +439,7 @@ namespace Org.BouncyCastle.Asn1.TeleTrust public static DerObjectIdentifier GetOid( string name) { - return (DerObjectIdentifier)objIds[Platform.ToLowerInvariant(name)]; + return (DerObjectIdentifier)objIds[Platform.ToUpperInvariant(name)]; } /** diff --git a/crypto/src/asn1/x509/GeneralName.cs b/crypto/src/asn1/x509/GeneralName.cs index 710ddc922..16096623c 100644 --- a/crypto/src/asn1/x509/GeneralName.cs +++ b/crypto/src/asn1/x509/GeneralName.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Text; +using Org.BouncyCastle.Utilities; using NetUtils = Org.BouncyCastle.Utilities.Net; namespace Org.BouncyCastle.Asn1.X509 @@ -356,11 +357,11 @@ namespace Org.BouncyCastle.Asn1.X509 private int[] parseIPv6(string ip) { - if (ip.StartsWith("::")) + if (Platform.StartsWith(ip, "::")) { ip = ip.Substring(1); } - else if (ip.EndsWith("::")) + else if (Platform.EndsWith(ip, "::")) { ip = ip.Substring(0, ip.Length - 1); } diff --git a/crypto/src/asn1/x509/X509Name.cs b/crypto/src/asn1/x509/X509Name.cs index fb404a3ec..01a7ec04a 100644 --- a/crypto/src/asn1/x509/X509Name.cs +++ b/crypto/src/asn1/x509/X509Name.cs @@ -399,7 +399,7 @@ namespace Org.BouncyCastle.Asn1.X509 if (derValue is IAsn1String && !(derValue is DerUniversalString)) { string v = ((IAsn1String)derValue).GetString(); - if (v.StartsWith("#")) + if (Platform.StartsWith(v, "#")) { v = "\\" + v; } @@ -499,12 +499,6 @@ namespace Org.BouncyCastle.Asn1.X509 } } -// private static bool IsEncoded( -// string s) -// { -// return s.StartsWith("#"); -// } - /** * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or * some such, converting it into an ordered set of name attributes. @@ -581,7 +575,7 @@ namespace Org.BouncyCastle.Asn1.X509 string name, IDictionary lookUp) { - if (Platform.ToUpperInvariant(name).StartsWith("OID.")) + if (Platform.StartsWith(Platform.ToUpperInvariant(name), "OID.")) { return new DerObjectIdentifier(name.Substring(4)); } @@ -724,7 +718,7 @@ namespace Org.BouncyCastle.Asn1.X509 { string val = (string)values[i]; - if (val.StartsWith("\\#")) + if (Platform.StartsWith(val, "\\#")) { val = val.Substring(1); } @@ -911,7 +905,7 @@ namespace Org.BouncyCastle.Asn1.X509 { string v = Platform.ToLowerInvariant(s).Trim(); - if (v.StartsWith("#")) + if (Platform.StartsWith(v, "#")) { Asn1Object obj = decodeObject(v); @@ -987,7 +981,7 @@ namespace Org.BouncyCastle.Asn1.X509 int end = buf.Length; - if (val.StartsWith("\\#")) + if (Platform.StartsWith(val, "\\#")) { index += 2; } diff --git a/crypto/src/asn1/x9/X962NamedCurves.cs b/crypto/src/asn1/x9/X962NamedCurves.cs index 6fa4e7c4b..14f7f818a 100644 --- a/crypto/src/asn1/x9/X962NamedCurves.cs +++ b/crypto/src/asn1/x9/X962NamedCurves.cs @@ -666,7 +666,7 @@ namespace Org.BouncyCastle.Asn1.X9 DerObjectIdentifier oid, X9ECParametersHolder holder) { - objIds.Add(Platform.ToLowerInvariant(name), oid); + objIds.Add(Platform.ToUpperInvariant(name), oid); names.Add(oid, name); curves.Add(oid, holder); } @@ -727,7 +727,7 @@ namespace Org.BouncyCastle.Asn1.X9 public static DerObjectIdentifier GetOid( string name) { - return (DerObjectIdentifier)objIds[Platform.ToLowerInvariant(name)]; + return (DerObjectIdentifier)objIds[Platform.ToUpperInvariant(name)]; } /** |