// Token: 0x06002FDA RID: 12250 RVA: 0x000B7630 File Offset: 0x000B5830 private static bool ValidateStd3AndAscii(string unicode, bool bUseStd3, bool bCheckAscii) { if (unicode.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } int num = -1; for (int i = 0; i < unicode.Length; i++) { if (unicode[i] <= '\u001f') { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequence", new object[] { i }), "unicode"); } if (bCheckAscii && unicode[i] >= '\u007f') { return(false); } if (IdnMapping.IsDot(unicode[i])) { if (i == num + 1) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } if (i - num > 64) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "Unicode"); } if (bUseStd3 && i > 0) { IdnMapping.ValidateStd3(unicode[i - 1], true); } num = i; } else if (bUseStd3) { IdnMapping.ValidateStd3(unicode[i], i == num + 1); } } if (num == -1 && unicode.Length > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } if (unicode.Length > 255 - (IdnMapping.IsDot(unicode[unicode.Length - 1]) ? 0 : 1)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", new object[] { 255 - (IdnMapping.IsDot(unicode[unicode.Length - 1]) ? 0 : 1) }), "unicode"); } if (bUseStd3 && !IdnMapping.IsDot(unicode[unicode.Length - 1])) { IdnMapping.ValidateStd3(unicode[unicode.Length - 1], true); } return(true); }
/// <summary>Encodes the specified number of characters in a substring of domain name labels that include Unicode characters outside the US-ASCII character range. The substring is converted to a string of displayable Unicode characters in the US-ASCII character range and is formatted according to the IDNA standard. </summary> /// <param name="unicode">The string to convert, which consists of one or more domain name labels delimited with label separators.</param> /// <param name="index">A zero-based offset into <paramref name="unicode" /> that specifies the start of the substring.</param> /// <param name="count">The number of characters to convert in the substring that starts at the position specified by <paramref name="index" /> in the <paramref name="unicode" /> string. </param> /// <returns>The equivalent of the substring specified by the <paramref name="unicode" />, <paramref name="index" />, and <paramref name="count" /> parameters, consisting of displayable Unicode characters in the US-ASCII character range (U+0020 to U+007E) and formatted according to the IDNA standard.</returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="unicode" /> is <see langword="null" />.</exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="index" /> or <paramref name="count" /> is less than zero.-or- /// <paramref name="index" /> is greater than the length of <paramref name="unicode" />.-or- /// <paramref name="index" /> is greater than the length of <paramref name="unicode" /> minus <paramref name="count" />.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="unicode" /> is invalid based on the <see cref="P:System.Globalization.IdnMapping.AllowUnassigned" /> and <see cref="P:System.Globalization.IdnMapping.UseStd3AsciiRules" /> properties, and the IDNA standard.</exception> // Token: 0x06002FD0 RID: 12240 RVA: 0x000B7130 File Offset: 0x000B5330 public string GetAscii(string unicode, int index, int count) { if (unicode == null) { throw new ArgumentNullException("unicode"); } if (index < 0 || count < 0) { throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (index > unicode.Length) { throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (index > unicode.Length - count) { throw new ArgumentOutOfRangeException("unicode", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); } unicode = unicode.Substring(index, count); if (Environment.IsWindows8OrAbove) { return(this.GetAsciiUsingOS(unicode)); } if (IdnMapping.ValidateStd3AndAscii(unicode, this.UseStd3AsciiRules, true)) { return(unicode); } if (unicode[unicode.Length - 1] <= '\u001f') { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequence", new object[] { unicode.Length - 1 }), "unicode"); } bool flag = unicode.Length > 0 && IdnMapping.IsDot(unicode[unicode.Length - 1]); unicode = unicode.Normalize(this.m_bAllowUnassigned ? ((NormalizationForm)13) : ((NormalizationForm)269)); if (!flag && unicode.Length > 0 && IdnMapping.IsDot(unicode[unicode.Length - 1])) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } if (this.UseStd3AsciiRules) { IdnMapping.ValidateStd3AndAscii(unicode, true, false); } return(IdnMapping.punycode_encode(unicode)); }
private static string punycode_decode(string ascii) { if (ascii.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii"); } int length1 = ascii.Length; int num1 = (int)byte.MaxValue; string str1 = ascii; int index1 = str1.Length - 1; int num2 = IdnMapping.IsDot(str1[index1]) ? 0 : 1; int num3 = num1 - num2; if (length1 > num3) { string key = "Argument_IdnBadNameSize"; object[] objArray = new object[1]; int index2 = 0; int num4 = (int)byte.MaxValue; string str2 = ascii; int index3 = str2.Length - 1; int num5 = IdnMapping.IsDot(str2[index3]) ? 0 : 1; // ISSUE: variable of a boxed type __Boxed <int> local = (ValueType)(num4 - num5); objArray[index2] = (object)local; throw new ArgumentException(Environment.GetResourceString(key, objArray), "ascii"); } StringBuilder stringBuilder1 = new StringBuilder(ascii.Length); int num6 = 0; int startIndex = 0; int index4 = 0; while (num6 < ascii.Length) { num6 = ascii.IndexOf('.', startIndex); if (num6 < 0 || num6 > ascii.Length) { num6 = ascii.Length; } if (num6 == startIndex) { if (num6 != ascii.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii"); } break; } if (num6 - startIndex > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii"); } if (ascii.Length < "xn--".Length + startIndex || !ascii.Substring(startIndex, "xn--".Length).Equals("xn--", StringComparison.OrdinalIgnoreCase)) { stringBuilder1.Append(ascii.Substring(startIndex, num6 - startIndex)); } else { startIndex += "xn--".Length; int num4 = ascii.LastIndexOf('-', num6 - 1); if (num4 == num6 - 1) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } int num5; if (num4 <= startIndex) { num5 = 0; } else { num5 = num4 - startIndex; for (int index2 = startIndex; index2 < startIndex + num5; ++index2) { if ((int)ascii[index2] > (int)sbyte.MaxValue) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } stringBuilder1.Append((int)ascii[index2] < 65 || (int)ascii[index2] > 90 ? ascii[index2] : (char)((int)ascii[index2] - 65 + 97)); } } int num7 = startIndex + (num5 > 0 ? num5 + 1 : 0); int num8 = 128; int num9 = 72; int num10 = 0; int num11 = 0; label_49: while (num7 < num6) { int num12 = num10; int num13 = 1; int num14 = 36; while (num7 < num6) { int num15 = IdnMapping.decode_digit(ascii[num7++]); if (num15 > (134217727 - num10) / num13) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } num10 += num15 * num13; int num16 = num14 <= num9 ? 1 : (num14 >= num9 + 26 ? 26 : num14 - num9); if (num15 >= num16) { if (num13 > 134217727 / (36 - num16)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } num13 *= 36 - num16; num14 += 36; } else { num9 = IdnMapping.adapt(num10 - num12, stringBuilder1.Length - index4 - num11 + 1, num12 == 0); if (num10 / (stringBuilder1.Length - index4 - num11 + 1) > 134217727 - num8) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } num8 += num10 / (stringBuilder1.Length - index4 - num11 + 1); int num17 = num10 % (stringBuilder1.Length - index4 - num11 + 1); if (num8 < 0 || num8 > 1114111 || num8 >= 55296 && num8 <= 57343) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } string str2 = char.ConvertFromUtf32(num8); int index2; if (num11 > 0) { int num18 = num17; index2 = index4; while (num18 > 0) { if (index2 >= stringBuilder1.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } if (char.IsSurrogate(stringBuilder1[index2])) { ++index2; } --num18; ++index2; } } else { index2 = index4 + num17; } stringBuilder1.Insert(index2, str2); if (IdnMapping.IsSupplementary(num8)) { ++num11; } num10 = num17 + 1; goto label_49; } } throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } bool flag = false; BidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder1.ToString(), index4); switch (bidiCategory) { case BidiCategory.RightToLeft: case BidiCategory.RightToLeftArabic: flag = true; break; } for (int index2 = index4; index2 < stringBuilder1.Length; ++index2) { if (!char.IsLowSurrogate(stringBuilder1.ToString(), index2)) { bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder1.ToString(), index2); if (flag && bidiCategory == BidiCategory.LeftToRight || !flag && (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii"); } } } if (flag && bidiCategory != BidiCategory.RightToLeft && bidiCategory != BidiCategory.RightToLeftArabic) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii"); } } if (num6 - startIndex > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii"); } if (num6 != ascii.Length) { stringBuilder1.Append('.'); } startIndex = num6 + 1; index4 = stringBuilder1.Length; } int length2 = stringBuilder1.Length; int num19 = (int)byte.MaxValue; StringBuilder stringBuilder2 = stringBuilder1; int index5 = stringBuilder2.Length - 1; int num20 = IdnMapping.IsDot(stringBuilder2[index5]) ? 0 : 1; int num21 = num19 - num20; if (length2 > num21) { string key = "Argument_IdnBadNameSize"; object[] objArray = new object[1]; int index2 = 0; int num4 = (int)byte.MaxValue; StringBuilder stringBuilder3 = stringBuilder1; int index3 = stringBuilder3.Length - 1; int num5 = IdnMapping.IsDot(stringBuilder3[index3]) ? 0 : 1; // ISSUE: variable of a boxed type __Boxed <int> local = (ValueType)(num4 - num5); objArray[index2] = (object)local; throw new ArgumentException(Environment.GetResourceString(key, objArray), "ascii"); } return(stringBuilder1.ToString()); }
private static string punycode_encode(string unicode) { if (unicode.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } StringBuilder stringBuilder = new StringBuilder(unicode.Length); int num1 = 0; int num2 = 0; int startIndex = 0; while (num1 < unicode.Length) { num1 = unicode.IndexOfAny(IdnMapping.M_Dots, num2); if (num1 < 0) { num1 = unicode.Length; } if (num1 == num2) { if (num1 != unicode.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } break; } stringBuilder.Append("xn--"); bool flag = false; switch (CharUnicodeInfo.GetBidiCategory(unicode, num2)) { case BidiCategory.RightToLeft: case BidiCategory.RightToLeftArabic: flag = true; int index1 = num1 - 1; if (char.IsLowSurrogate(unicode, index1)) { --index1; } switch (CharUnicodeInfo.GetBidiCategory(unicode, index1)) { case BidiCategory.RightToLeft: case BidiCategory.RightToLeftArabic: break; default: throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } } int num3 = 0; for (int index2 = num2; index2 < num1; ++index2) { BidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(unicode, index2); if (flag && bidiCategory == BidiCategory.LeftToRight) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } if (!flag && (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } if (IdnMapping.basic((uint)unicode[index2])) { stringBuilder.Append(IdnMapping.encode_basic(unicode[index2])); ++num3; } else if (char.IsSurrogatePair(unicode, index2)) { ++index2; } } int num4 = num3; if (num4 == num1 - num2) { stringBuilder.Remove(startIndex, "xn--".Length); } else { if (unicode.Length - num2 >= "xn--".Length && unicode.Substring(num2, "xn--".Length).Equals("xn--", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "unicode"); } int num5 = 0; if (num4 > 0) { stringBuilder.Append('-'); } int num6 = 128; int num7 = 0; int num8 = 72; while (num3 < num1 - num2) { int cTest = 134217727; int index2 = num2; while (index2 < num1) { int utf32 = char.ConvertToUtf32(unicode, index2); if (utf32 >= num6 && utf32 < cTest) { cTest = utf32; } index2 += IdnMapping.IsSupplementary(utf32) ? 2 : 1; } int delta = num7 + (cTest - num6) * (num3 - num5 + 1); int num9 = cTest; int index3 = num2; while (index3 < num1) { int utf32 = char.ConvertToUtf32(unicode, index3); if (utf32 < num9) { ++delta; } if (utf32 == num9) { int d = delta; int num10 = 36; while (true) { int num11 = num10 <= num8 ? 1 : (num10 >= num8 + 26 ? 26 : num10 - num8); if (d >= num11) { stringBuilder.Append(IdnMapping.encode_digit(num11 + (d - num11) % (36 - num11))); d = (d - num11) / (36 - num11); num10 += 36; } else { break; } } stringBuilder.Append(IdnMapping.encode_digit(d)); num8 = IdnMapping.adapt(delta, num3 - num5 + 1, num3 == num4); delta = 0; ++num3; if (IdnMapping.IsSupplementary(cTest)) { ++num3; ++num5; } } index3 += IdnMapping.IsSupplementary(utf32) ? 2 : 1; } num7 = delta + 1; num6 = num9 + 1; } } if (stringBuilder.Length - startIndex > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } if (num1 != unicode.Length) { stringBuilder.Append('.'); } num2 = num1 + 1; startIndex = stringBuilder.Length; } int length = stringBuilder.Length; int num12 = (int)byte.MaxValue; string str1 = unicode; int index4 = str1.Length - 1; int num13 = IdnMapping.IsDot(str1[index4]) ? 0 : 1; int num14 = num12 - num13; if (length > num14) { string key = "Argument_IdnBadNameSize"; object[] objArray = new object[1]; int index1 = 0; int num3 = (int)byte.MaxValue; string str2 = unicode; int index2 = str2.Length - 1; int num4 = IdnMapping.IsDot(str2[index2]) ? 0 : 1; // ISSUE: variable of a boxed type __Boxed <int> local = (ValueType)(num3 - num4); objArray[index1] = (object)local; throw new ArgumentException(Environment.GetResourceString(key, objArray), "unicode"); } return(stringBuilder.ToString()); }
private static bool ValidateStd3AndAscii(string unicode, bool bUseStd3, bool bCheckAscii) { if (unicode.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } int num1 = -1; for (int index = 0; index < unicode.Length; ++index) { if ((int)unicode[index] <= 31) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequence", (object)index), "unicode"); } if (bCheckAscii && (int)unicode[index] >= (int)sbyte.MaxValue) { return(false); } if (IdnMapping.IsDot(unicode[index])) { if (index == num1 + 1) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } if (index - num1 > 64) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "Unicode"); } if (bUseStd3 && index > 0) { IdnMapping.ValidateStd3(unicode[index - 1], true); } num1 = index; } else if (bUseStd3) { IdnMapping.ValidateStd3(unicode[index], index == num1 + 1); } } if (num1 == -1 && unicode.Length > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } int length = unicode.Length; int num2 = (int)byte.MaxValue; string str1 = unicode; int index1 = str1.Length - 1; int num3 = IdnMapping.IsDot(str1[index1]) ? 0 : 1; int num4 = num2 - num3; if (length > num4) { string key = "Argument_IdnBadNameSize"; object[] objArray = new object[1]; int index2 = 0; int num5 = (int)byte.MaxValue; string str2 = unicode; int index3 = str2.Length - 1; int num6 = IdnMapping.IsDot(str2[index3]) ? 0 : 1; // ISSUE: variable of a boxed type __Boxed <int> local = (ValueType)(num5 - num6); objArray[index2] = (object)local; throw new ArgumentException(Environment.GetResourceString(key, objArray), "unicode"); } if (bUseStd3) { string str2 = unicode; int index2 = str2.Length - 1; if (!IdnMapping.IsDot(str2[index2])) { string str3 = unicode; int index3 = str3.Length - 1; IdnMapping.ValidateStd3(str3[index3], true); } } return(true); }
/// <summary>编码包含 US-ASCII 字符范围以外的 Unicode 字符的域名称标签子字符串的指定字符数。子串转换为在 US-ASCII 字符范围内可显示的“ Unicode ”字符串并根据 IDNA 标准格式化。</summary> /// <returns>由 <paramref name="unicode" />、<paramref name="index" /> 和 <paramref name="count" /> 参数指定的子字符串的等效项,包括 US-ASCII 字符范围(U+0020 至 U+007E)内的可显示 Unicode 字符并根据 IDNA 标准格式化。</returns> /// <param name="unicode">要转换的字符串,它包含一个或多个由标签分隔符分隔的域名标签。</param> /// <param name="index"> /// <paramref name="unicode" /> 的从零开始的偏移量,用于指定子字符串的起始位置。</param> /// <param name="count">要在 <paramref name="unicode" /> 字符串中的 <paramref name="index" /> 指定的位置开始的子字符串中转换的字符数。</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="unicode" /> 为 null。</exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="index" /> 或 <paramref name="count" /> 小于零。- 或 -<paramref name="index" /> 大于 <paramref name="unicode" /> 的长度。- 或 -<paramref name="index" /> 大于 <paramref name="unicode" /> 的长度减去 <paramref name="count" />。</exception> /// <exception cref="T:System.ArgumentException">根据 <see cref="P:System.Globalization.IdnMapping.AllowUnassigned" /> 和 <see cref="P:System.Globalization.IdnMapping.UseStd3AsciiRules" /> 属性以及 IDNA 标准,<paramref name="unicode" /> 是无效的。</exception> public string GetAscii(string unicode, int index, int count) { if (unicode == null) { throw new ArgumentNullException("unicode"); } if (index < 0 || count < 0) { throw new ArgumentOutOfRangeException(index < 0 ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (index > unicode.Length) { throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (index > unicode.Length - count) { throw new ArgumentOutOfRangeException("unicode", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); } unicode = unicode.Substring(index, count); if (Environment.IsWindows8OrAbove) { return(this.GetAsciiUsingOS(unicode)); } if (IdnMapping.ValidateStd3AndAscii(unicode, this.UseStd3AsciiRules, true)) { return(unicode); } string str1 = unicode; int index1 = str1.Length - 1; if ((int)str1[index1] <= 31) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequence", (object)(unicode.Length - 1)), "unicode"); } int num; if (unicode.Length > 0) { string str2 = unicode; int index2 = str2.Length - 1; num = IdnMapping.IsDot(str2[index2]) ? 1 : 0; } else { num = 0; } unicode = unicode.Normalize(this.m_bAllowUnassigned ? (NormalizationForm)13 : (NormalizationForm)269); if (num == 0 && unicode.Length > 0) { string str2 = unicode; int index2 = str2.Length - 1; if (IdnMapping.IsDot(str2[index2])) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } } if (this.UseStd3AsciiRules) { IdnMapping.ValidateStd3AndAscii(unicode, true, false); } return(IdnMapping.punycode_encode(unicode)); }
// Token: 0x06002FE3 RID: 12259 RVA: 0x000B7D34 File Offset: 0x000B5F34 private static string punycode_decode(string ascii) { if (ascii.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii"); } if (ascii.Length > 255 - (IdnMapping.IsDot(ascii[ascii.Length - 1]) ? 0 : 1)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", new object[] { 255 - (IdnMapping.IsDot(ascii[ascii.Length - 1]) ? 0 : 1) }), "ascii"); } StringBuilder stringBuilder = new StringBuilder(ascii.Length); int i = 0; int num = 0; int num2 = 0; while (i < ascii.Length) { i = ascii.IndexOf('.', num); if (i < 0 || i > ascii.Length) { i = ascii.Length; } if (i == num) { if (i != ascii.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii"); } break; } else { if (i - num > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii"); } if (ascii.Length < "xn--".Length + num || !ascii.Substring(num, "xn--".Length).Equals("xn--", StringComparison.OrdinalIgnoreCase)) { stringBuilder.Append(ascii.Substring(num, i - num)); } else { num += "xn--".Length; int num3 = ascii.LastIndexOf('-', i - 1); if (num3 == i - 1) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } int num4; if (num3 <= num) { num4 = 0; } else { num4 = num3 - num; for (int j = num; j < num + num4; j++) { if (ascii[j] > '\u007f') { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } stringBuilder.Append((ascii[j] >= 'A' && ascii[j] <= 'Z') ? (ascii[j] - 'A' + 'a') : ascii[j]); } } int k = num + ((num4 > 0) ? (num4 + 1) : 0); int num5 = 128; int num6 = 72; int num7 = 0; int num8 = 0; IL_40D: while (k < i) { int num9 = num7; int num10 = 1; int num11 = 36; while (k < i) { int num12 = IdnMapping.decode_digit(ascii[k++]); if (num12 > (134217727 - num7) / num10) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } num7 += num12 * num10; int num13 = (num11 <= num6) ? 1 : ((num11 >= num6 + 26) ? 26 : (num11 - num6)); if (num12 >= num13) { if (num10 > 134217727 / (36 - num13)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } num10 *= 36 - num13; num11 += 36; } else { num6 = IdnMapping.adapt(num7 - num9, stringBuilder.Length - num2 - num8 + 1, num9 == 0); if (num7 / (stringBuilder.Length - num2 - num8 + 1) > 134217727 - num5) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } num5 += num7 / (stringBuilder.Length - num2 - num8 + 1); num7 %= stringBuilder.Length - num2 - num8 + 1; if (num5 < 0 || num5 > 1114111 || (num5 >= 55296 && num5 <= 57343)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } string value = char.ConvertFromUtf32(num5); int num14; if (num8 > 0) { int l = num7; num14 = num2; while (l > 0) { if (num14 >= stringBuilder.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } if (char.IsSurrogate(stringBuilder[num14])) { num14++; } l--; num14++; } } else { num14 = num2 + num7; } stringBuilder.Insert(num14, value); if (IdnMapping.IsSupplementary(num5)) { num8++; } num7++; goto IL_40D; } } throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); } bool flag = false; BidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder.ToString(), num2); if (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic) { flag = true; } for (int m = num2; m < stringBuilder.Length; m++) { if (!char.IsLowSurrogate(stringBuilder.ToString(), m)) { bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder.ToString(), m); if ((flag && bidiCategory == BidiCategory.LeftToRight) || (!flag && (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic))) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii"); } } } if (flag && bidiCategory != BidiCategory.RightToLeft && bidiCategory != BidiCategory.RightToLeftArabic) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii"); } } if (i - num > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii"); } if (i != ascii.Length) { stringBuilder.Append('.'); } num = i + 1; num2 = stringBuilder.Length; } } if (stringBuilder.Length > 255 - (IdnMapping.IsDot(stringBuilder[stringBuilder.Length - 1]) ? 0 : 1)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", new object[] { 255 - (IdnMapping.IsDot(stringBuilder[stringBuilder.Length - 1]) ? 0 : 1) }), "ascii"); } return(stringBuilder.ToString()); }
// Token: 0x06002FE2 RID: 12258 RVA: 0x000B7924 File Offset: 0x000B5B24 private static string punycode_encode(string unicode) { if (unicode.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } StringBuilder stringBuilder = new StringBuilder(unicode.Length); int i = 0; int num = 0; int num2 = 0; while (i < unicode.Length) { i = unicode.IndexOfAny(IdnMapping.M_Dots, num); if (i < 0) { i = unicode.Length; } if (i == num) { if (i != unicode.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } break; } else { stringBuilder.Append("xn--"); bool flag = false; BidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(unicode, num); if (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic) { flag = true; int num3 = i - 1; if (char.IsLowSurrogate(unicode, num3)) { num3--; } bidiCategory = CharUnicodeInfo.GetBidiCategory(unicode, num3); if (bidiCategory != BidiCategory.RightToLeft && bidiCategory != BidiCategory.RightToLeftArabic) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } } int j = 0; for (int k = num; k < i; k++) { BidiCategory bidiCategory2 = CharUnicodeInfo.GetBidiCategory(unicode, k); if (flag && bidiCategory2 == BidiCategory.LeftToRight) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } if (!flag && (bidiCategory2 == BidiCategory.RightToLeft || bidiCategory2 == BidiCategory.RightToLeftArabic)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } if (IdnMapping.basic((uint)unicode[k])) { stringBuilder.Append(IdnMapping.encode_basic(unicode[k])); j++; } else if (char.IsSurrogatePair(unicode, k)) { k++; } } int num4 = j; if (num4 == i - num) { stringBuilder.Remove(num2, "xn--".Length); } else { if (unicode.Length - num >= "xn--".Length && unicode.Substring(num, "xn--".Length).Equals("xn--", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "unicode"); } int num5 = 0; if (num4 > 0) { stringBuilder.Append('-'); } int num6 = 128; int num7 = 0; int num8 = 72; while (j < i - num) { int num9 = 134217727; int num10; for (int l = num; l < i; l += (IdnMapping.IsSupplementary(num10) ? 2 : 1)) { num10 = char.ConvertToUtf32(unicode, l); if (num10 >= num6 && num10 < num9) { num9 = num10; } } num7 += (num9 - num6) * (j - num5 + 1); num6 = num9; for (int l = num; l < i; l += (IdnMapping.IsSupplementary(num10) ? 2 : 1)) { num10 = char.ConvertToUtf32(unicode, l); if (num10 < num6) { num7++; } if (num10 == num6) { int num11 = num7; int num12 = 36; for (;;) { int num13 = (num12 <= num8) ? 1 : ((num12 >= num8 + 26) ? 26 : (num12 - num8)); if (num11 < num13) { break; } stringBuilder.Append(IdnMapping.encode_digit(num13 + (num11 - num13) % (36 - num13))); num11 = (num11 - num13) / (36 - num13); num12 += 36; } stringBuilder.Append(IdnMapping.encode_digit(num11)); num8 = IdnMapping.adapt(num7, j - num5 + 1, j == num4); num7 = 0; j++; if (IdnMapping.IsSupplementary(num9)) { j++; num5++; } } } num7++; num6++; } } if (stringBuilder.Length - num2 > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } if (i != unicode.Length) { stringBuilder.Append('.'); } num = i + 1; num2 = stringBuilder.Length; } } if (stringBuilder.Length > 255 - (IdnMapping.IsDot(unicode[unicode.Length - 1]) ? 0 : 1)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", new object[] { 255 - (IdnMapping.IsDot(unicode[unicode.Length - 1]) ? 0 : 1) }), "unicode"); } return(stringBuilder.ToString()); }