diff options
Diffstat (limited to 'src/mscorlib/src/System/Text/ISO2022Encoding.cs')
-rw-r--r-- | src/mscorlib/src/System/Text/ISO2022Encoding.cs | 74 |
1 files changed, 31 insertions, 43 deletions
diff --git a/src/mscorlib/src/System/Text/ISO2022Encoding.cs b/src/mscorlib/src/System/Text/ISO2022Encoding.cs index fe57e7cc57..fca579fe56 100644 --- a/src/mscorlib/src/System/Text/ISO2022Encoding.cs +++ b/src/mscorlib/src/System/Text/ISO2022Encoding.cs @@ -28,6 +28,7 @@ namespace System.Text { using System.Globalization; + using System.Diagnostics; using System.Diagnostics.Contracts; using System.Text; using System.Runtime.InteropServices; @@ -53,7 +54,6 @@ namespace System.Text // We have to load the 936 code page tables, so impersonate 936 as our base // This pretends to be other code pages as far as memory sections are concerned. - [System.Security.SecurityCritical] // auto-generated internal ISO2022Encoding(int codePage) : base(codePage, tableBaseCodePages[codePage % 10]) { this.m_bUseMlangTypeForSerialization = true; @@ -61,11 +61,10 @@ namespace System.Text // Constructor called by serialization. // Note: We use the base GetObjectData however - [System.Security.SecurityCritical] // auto-generated internal ISO2022Encoding(SerializationInfo info, StreamingContext context) : base(info, context) { // Actually this can't ever get called, CodePageEncoding is our proxy - Contract.Assert(false, "Didn't expect to make it to DBCSCodePageEncoding serialization constructor"); + Debug.Assert(false, "Didn't expect to make it to DBCSCodePageEncoding serialization constructor"); throw new ArgumentException(Environment.GetResourceString("Arg_ExecutionEngineException")); } @@ -102,7 +101,6 @@ namespace System.Text ModeNOOP = -3 } - [System.Security.SecurityCritical] // auto-generated protected unsafe override String GetMemorySectionName() { int iUseCodePage = this.bFlagDataTable ? dataTableCodePage : CodePage; @@ -123,7 +121,7 @@ namespace System.Text strFormat = "CodePage_{0}_{1}_{2}_{3}_{4}_HZ"; break; default: - Contract.Assert(false, "[ISO2022Encoding.GetMemorySectionName] Don't expect to get here for code page " + this.CodePage); + Debug.Assert(false, "[ISO2022Encoding.GetMemorySectionName] Don't expect to get here for code page " + this.CodePage); strFormat = "CodePage_{0}_{1}_{2}_{3}_{4}"; break; } @@ -263,28 +261,26 @@ namespace System.Text } // GetByteCount - [System.Security.SecurityCritical] // auto-generated internal override unsafe int GetByteCount(char* chars, int count, EncoderNLS baseEncoder) { // Just need to ASSERT, this is called by something else internal that checked parameters already - Contract.Assert(count >= 0, "[ISO2022Encoding.GetByteCount]count is negative"); - Contract.Assert(chars != null, "[ISO2022Encoding.GetByteCount]chars is null"); + Debug.Assert(count >= 0, "[ISO2022Encoding.GetByteCount]count is negative"); + Debug.Assert(chars != null, "[ISO2022Encoding.GetByteCount]chars is null"); // Just call GetBytes with null byte* to get count return GetBytes(chars, count, null, 0, baseEncoder); } - [System.Security.SecurityCritical] // auto-generated internal override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, EncoderNLS baseEncoder) { // Just need to ASSERT, this is called by something else internal that checked parameters already - Contract.Assert(chars != null, "[ISO2022Encoding.GetBytes]chars is null"); - Contract.Assert(byteCount >= 0, "[ISO2022Encoding.GetBytes]byteCount is negative"); - Contract.Assert(charCount >= 0, "[ISO2022Encoding.GetBytes]charCount is negative"); + Debug.Assert(chars != null, "[ISO2022Encoding.GetBytes]chars is null"); + Debug.Assert(byteCount >= 0, "[ISO2022Encoding.GetBytes]byteCount is negative"); + Debug.Assert(charCount >= 0, "[ISO2022Encoding.GetBytes]charCount is negative"); // Assert because we shouldn't be able to have a null encoder. - Contract.Assert(encoderFallback != null, "[ISO2022Encoding.GetBytes]Attempting to use null encoder fallback"); + Debug.Assert(encoderFallback != null, "[ISO2022Encoding.GetBytes]Attempting to use null encoder fallback"); // Fix our encoder ISO2022Encoder encoder = (ISO2022Encoder)baseEncoder; @@ -316,25 +312,23 @@ namespace System.Text } // This is internal and called by something else, - [System.Security.SecurityCritical] // auto-generated internal override unsafe int GetCharCount(byte* bytes, int count, DecoderNLS baseDecoder) { // Just assert, we're called internally so these should be safe, checked already - Contract.Assert(bytes != null, "[ISO2022Encoding.GetCharCount]bytes is null"); - Contract.Assert(count >= 0, "[ISO2022Encoding.GetCharCount]byteCount is negative"); + Debug.Assert(bytes != null, "[ISO2022Encoding.GetCharCount]bytes is null"); + Debug.Assert(count >= 0, "[ISO2022Encoding.GetCharCount]byteCount is negative"); // Just call getChars with null char* to get count return GetChars(bytes, count, null, 0, baseDecoder); } - [System.Security.SecurityCritical] // auto-generated internal override unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount, DecoderNLS baseDecoder) { // Just need to ASSERT, this is called by something else internal that checked parameters already - Contract.Assert(bytes != null, "[ISO2022Encoding.GetChars]bytes is null"); - Contract.Assert(byteCount >= 0, "[ISO2022Encoding.GetChars]byteCount is negative"); - Contract.Assert(charCount >= 0, "[ISO2022Encoding.GetChars]charCount is negative"); + Debug.Assert(bytes != null, "[ISO2022Encoding.GetChars]bytes is null"); + Debug.Assert(byteCount >= 0, "[ISO2022Encoding.GetChars]byteCount is negative"); + Debug.Assert(charCount >= 0, "[ISO2022Encoding.GetChars]charCount is negative"); // Fix our decoder ISO2022Decoder decoder = (ISO2022Decoder)baseDecoder; @@ -358,7 +352,7 @@ namespace System.Text iCount = GetCharsCP52936( bytes, byteCount, chars, charCount, decoder); break; default: - Contract.Assert(false, "[ISO2022Encoding.GetChars] had unexpected code page"); + Debug.Assert(false, "[ISO2022Encoding.GetChars] had unexpected code page"); break; } @@ -399,7 +393,6 @@ namespace System.Text // undefined, so we maintain that behavior when decoding. We will never generate characters using // that technique, but the decoder will process them. // - [System.Security.SecurityCritical] // auto-generated private unsafe int GetBytesCP5022xJP(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { @@ -422,7 +415,7 @@ namespace System.Text // We may have a left over character from last time, try and process it. if (charLeftOver > 0) { - Contract.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP5022xJP]leftover character should be high surrogate"); + Debug.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP5022xJP]leftover character should be high surrogate"); // It has to be a high surrogate, which we don't support, so it has to be a fallback buffer.Fallback(charLeftOver); @@ -483,7 +476,7 @@ namespace System.Text else { // 50221 does halfwidth katakana by escape sequence - Contract.Assert(CodePage == 50221, "[ISO2022Encoding.GetBytesCP5022xJP]Expected Code Page 50221"); + Debug.Assert(CodePage == 50221, "[ISO2022Encoding.GetBytesCP5022xJP]Expected Code Page 50221"); // Add our escape sequence if (!buffer.AddByte(ESCAPE, unchecked((byte)'('), unchecked((byte)'I'))) @@ -642,7 +635,6 @@ namespace System.Text // Also Mlang always assumed KR mode, even if the designator wasn't found yet, so we do that as // well. So basically we just ignore <ESC>$)C when decoding. // - [System.Security.SecurityCritical] // auto-generated private unsafe int GetBytesCP50225KR(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { @@ -665,7 +657,7 @@ namespace System.Text // We may have a l left over character from last time, try and process it. if (charLeftOver > 0) { - Contract.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP50225KR]leftover character should be high surrogate"); + Debug.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP50225KR]leftover character should be high surrogate"); // It has to be a high surrogate, which we don't support, so it has to be a fallback buffer.Fallback(charLeftOver); @@ -765,7 +757,7 @@ namespace System.Text if (!encoder.MustFlush || encoder.charLeftOver != (char)0) { // We should be not flushing or converting - Contract.Assert(!encoder.MustFlush || !encoder.m_throwOnOverflow, + Debug.Assert(!encoder.MustFlush || !encoder.m_throwOnOverflow, "[ISO2022Encoding.GetBytesCP50225KR]Expected no left over data or not flushing or not converting"); encoder.shiftInOutMode = shiftOutMode; } @@ -793,7 +785,6 @@ namespace System.Text // // This encoding is designed for transmission by e-mail and news. No bytes should have high bit set. // (all bytes <= 0x7f) - [System.Security.SecurityCritical] // auto-generated private unsafe int GetBytesCP52936(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { @@ -813,7 +804,7 @@ namespace System.Text // We may have a left over character from last time, try and process it. if (charLeftOver > 0) { - Contract.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP52936]leftover character should be high surrogate"); + Debug.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP52936]leftover character should be high surrogate"); // It has to be a high surrogate, which we don't support, so it has to be a fallback buffer.Fallback(charLeftOver); @@ -928,7 +919,6 @@ namespace System.Text return buffer.Count; } - [System.Security.SecurityCritical] // auto-generated private unsafe int GetCharsCP5022xJP(byte* bytes, int byteCount, char* chars, int charCount, ISO2022Decoder decoder) { @@ -1139,7 +1129,7 @@ namespace System.Text if (!decoder.MustFlush || escapeCount != 0) { // Either not flushing or had state (from convert) - Contract.Assert(!decoder.MustFlush || !decoder.m_throwOnOverflow, + Debug.Assert(!decoder.MustFlush || !decoder.m_throwOnOverflow, "[ISO2022Encoding.GetCharsCP5022xJP]Expected no state or not converting or not flushing"); decoder.currentMode = currentMode; @@ -1233,7 +1223,7 @@ namespace System.Text private byte DecrementEscapeBytes(ref byte[] bytes, ref int count) { - Contract.Assert(count > 0, "[ISO2022Encoding.DecrementEscapeBytes]count > 0"); + Debug.Assert(count > 0, "[ISO2022Encoding.DecrementEscapeBytes]count > 0"); // Decrement our count count--; @@ -1256,7 +1246,6 @@ namespace System.Text // Note that in DBCS mode mlang passed through ' ', '\t' and '\n' as SBCS characters // probably to allow mailer formatting without too much extra work. - [System.Security.SecurityCritical] // auto-generated private unsafe int GetCharsCP50225KR(byte* bytes, int byteCount, char* chars, int charCount, ISO2022Decoder decoder) { @@ -1441,7 +1430,7 @@ namespace System.Text if (!decoder.MustFlush || escapeCount != 0) { // Either not flushing or had state (from convert) - Contract.Assert(!decoder.MustFlush || !decoder.m_throwOnOverflow, + Debug.Assert(!decoder.MustFlush || !decoder.m_throwOnOverflow, "[ISO2022Encoding.GetCharsCP50225KR]Expected no state or not converting or not flushing"); decoder.currentMode = currentMode; @@ -1496,12 +1485,11 @@ namespace System.Text // // This encoding is designed for transmission by e-mail and news. No bytes should have high bit set. // (all bytes <= 0x7f) - [System.Security.SecurityCritical] // auto-generated private unsafe int GetCharsCP52936(byte* bytes, int byteCount, char* chars, int charCount, ISO2022Decoder decoder) { - Contract.Assert(byteCount >=0, "[ISO2022Encoding.GetCharsCP52936]count >=0"); - Contract.Assert(bytes!=null, "[ISO2022Encoding.GetCharsCP52936]bytes!=null"); + Debug.Assert(byteCount >=0, "[ISO2022Encoding.GetCharsCP52936]count >=0"); + Debug.Assert(bytes!=null, "[ISO2022Encoding.GetCharsCP52936]bytes!=null"); // Get our info. Encoding.EncodingCharBuffer buffer = new Encoding.EncodingCharBuffer( @@ -1612,7 +1600,7 @@ namespace System.Text if (currentMode != ISO2022Modes.ModeASCII) { // Should be ModeHZ - Contract.Assert(currentMode == ISO2022Modes.ModeHZ, "[ISO2022Encoding.GetCharsCP52936]Expected ModeHZ"); + Debug.Assert(currentMode == ISO2022Modes.ModeHZ, "[ISO2022Encoding.GetCharsCP52936]Expected ModeHZ"); char cm; // Everett allowed characters < 0x20 to be passed as if they were ASCII @@ -1737,7 +1725,7 @@ namespace System.Text else { // Either not flushing or had state (from convert) - Contract.Assert(!decoder.MustFlush || !decoder.m_throwOnOverflow, + Debug.Assert(!decoder.MustFlush || !decoder.m_throwOnOverflow, "[ISO2022Encoding.GetCharsCP52936]Expected no state or not converting or not flushing"); decoder.currentMode = currentMode; @@ -1754,7 +1742,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1801,7 +1789,7 @@ namespace System.Text byteCount += extraStart + extraEnd; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -1809,7 +1797,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1839,7 +1827,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } |