public async Task <IReadOnlyList <DnsZone> > ListZonesAsync() { var zones = await _cloudflareDnsClient.ListAllZonesAsync(); // Zone API は Punycode されていない値を返すのでエンコードが必要 return(zones.Select(x => new DnsZone { Id = x.Id, Name = Punycode.Encode(x.Name) }).ToArray()); }
public static String CanonicalDomain(String str) { if (str != null) { // See: S4.1.2.3 & S5.2.3: ignore leading . str = str.Trim().TrimStart('.'); if (NonAscii.IsMatch(str)) { str = Punycode.Encode(str); } return(str.ToLowerInvariant()); } return(str); }
private bool IsForPublicSuffix(Apache.Http.Cookie.Cookie cookie) { string domain = cookie.GetDomain(); if (domain.StartsWith(".")) { domain = Sharpen.Runtime.Substring(domain, 1); } domain = Punycode.ToUnicode(domain); // An exception rule takes priority over any other matching rule. if (this.exceptions != null) { if (this.exceptions.Contains(domain)) { return(false); } } if (this.suffixes == null) { return(false); } do { if (this.suffixes.Contains(domain)) { return(true); } // patterns if (domain.StartsWith("*.")) { domain = Sharpen.Runtime.Substring(domain, 2); } int nextdot = domain.IndexOf('.'); if (nextdot == -1) { break; } domain = "*" + Sharpen.Runtime.Substring(domain, nextdot); }while (domain.Length > 0); return(false); }
// // toUnicode operation; should only apply to a single label // private static String ToUnicodeInternal(String label, int flag) { bool[] caseFlags = null; StringBuffer dest; // step 1 // find out if all the codepoints in input are ASCII bool isASCII = IsAllASCII(label); if (!isASCII) { // step 2 // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here try { UCharacterIterator iter = UCharacterIterator.getInstance(label); dest = NamePrep.prepare(iter, flag); } catch (Exception) { // toUnicode never fails; if any step fails, return the input string return(label); } } else { dest = new StringBuffer(label); } // step 3 // verify ACE Prefix if (StartsWithACEPrefix(dest)) { // step 4 // Remove the ACE Prefix String temp = dest.Substring(ACE_PREFIX_LENGTH, dest.Length() - ACE_PREFIX_LENGTH); try { // step 5 // Decode using punycode StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null); // step 6 // Apply toASCII String toASCIIOut = ToASCII(decodeOut.ToString(), flag); // step 7 // verify if (toASCIIOut.EqualsIgnoreCase(dest.ToString())) { // step 8 // return output of step 5 return(decodeOut.ToString()); } } catch (Exception) { // no-op } } // just return the input return(label); }
// // toASCII operation; should only apply to a single label // private static String ToASCIIInternal(String label, int flag) { // step 1 // Check if the string contains code points outside the ASCII range 0..0x7c. bool isASCII = IsAllASCII(label); StringBuffer dest; // step 2 // perform the nameprep operation; flag ALLOW_UNASSIGNED is used here if (!isASCII) { UCharacterIterator iter = UCharacterIterator.getInstance(label); try { dest = NamePrep.prepare(iter, flag); } catch (java.text.ParseException e) { throw new IllegalArgumentException(e); } } else { dest = new StringBuffer(label); } // step 8, move forward to check the smallest number of the code points // the length must be inside 1..63 if (dest.Length() == 0) { throw new IllegalArgumentException("Empty label is not a legal name"); } // step 3 // Verify the absence of non-LDH ASCII code points // 0..0x2c, 0x2e..0x2f, 0x3a..0x40, 0x5b..0x60, 0x7b..0x7f // Verify the absence of leading and trailing hyphen bool useSTD3ASCIIRules = ((flag & USE_STD3_ASCII_RULES) != 0); if (useSTD3ASCIIRules) { for (int i = 0; i < dest.Length(); i++) { int c = dest.CharAt(i); if (IsNonLDHAsciiCodePoint(c)) { throw new IllegalArgumentException("Contains non-LDH ASCII characters"); } } if (dest.CharAt(0) == '-' || dest.CharAt(dest.Length() - 1) == '-') { throw new IllegalArgumentException("Has leading or trailing hyphen"); } } if (!isASCII) { // step 4 // If all code points are inside 0..0x7f, skip to step 8 if (!IsAllASCII(dest.ToString())) { // step 5 // verify the sequence does not begin with ACE prefix if (!StartsWithACEPrefix(dest)) { // step 6 // encode the sequence with punycode try { dest = Punycode.encode(dest, null); } catch (java.text.ParseException e) { throw new IllegalArgumentException(e); } dest = ToASCIILower(dest); // step 7 // prepend the ACE prefix dest.Insert(0, ACE_PREFIX); } else { throw new IllegalArgumentException("The input starts with the ACE Prefix"); } } } // step 8 // the length must be inside 1..63 if (dest.Length() > MAX_LABEL_LENGTH) { throw new IllegalArgumentException("The label in the input is too long"); } return(dest.ToString()); }
/// <summary> /// Try to guess WHOIS server for specified query object. /// </summary> /// <param name="obj">A query object.</param> /// <returns>The <see cref="QueryParser"/> object of self.</returns> public QueryParser GuessServer(string obj) { if (string.IsNullOrWhiteSpace(obj)) { throw new ArgumentException("Empty query."); } OriginalQuery = obj; Query = Punycode.ToAscii(obj.Trim().TrimEnd(new char[] { '.' })); Server = null; ServerQuery = string.Empty; ServerEncoding = Encoding.ASCII; ServerHint = ServerHints.NONE; // IPv6 address if (Query.Contains(':')) { // RPSL hierarchical objects if (Query.StartsWith("as", StringComparison.InvariantCultureIgnoreCase)) { return(FindAS(stdlib.strtoul(obj.Substring(2), 10))); } return(ParseIPv6(Query)); } // email if (Query.Contains('@')) { throw new NoServerException(); } // TLD domains -> try find, but don't throw error yet if (!Query.Contains('.')) { /* if it is a TLD or a new gTLD then ask IANA */ var low = Query.ToLowerInvariant(); var tld = Assignments.TLD.FirstOrDefault(a => a.Item1 == low); if (tld != null || Assignments.GTLD.Any(a => a == Query)) { Server = "whois.iana.org"; ServerHint |= ServerHints.IANA; return(this); } } // no dot and no hyphen means it's a NSI NIC handle or ASN (?) if (!(Query.Contains('.') || Query.Contains('-'))) { if (GuessServer_Regex_AS.IsMatch(Query)) { return(FindAS(stdlib.strtoul(Query.Substring(2), 10))); } if (Query[0] == '!') /* NSI NIC handle */ { Server = "whois.networksolutions.com"; return(this); } throw new NoServerException(); } // ASN32 if (Query.StartsWith("as", StringComparison.InvariantCultureIgnoreCase) && Query.Length >= 3 && TryParseASN32(Query.Substring(2), out uint asn32)) { return(FindAS32(asn32)); } // IPv4 if (TryParseIPv4(Query, out uint ip)) { return(FindIPv4(ip)); } // TLD if (IsTLD(Query)) { return(this); } // new gTLD, e.g. they have whois.nic.[TLD] var gtld_result = FindByNewTLD(Query); if (gtld_result != null) { Server = gtld_result; ServerHint |= ServerHints.GTLD; return(this); } // no dot but hyphen -> NIC if (!Query.Contains('.')) { var low = Query.ToLowerInvariant(); var nicPrefix = Assignments.NicHandlePrefixes .Where(a => low.StartsWith(a.Key)) .FirstOrDefault(); if (nicPrefix.Key != null) { Server = nicPrefix.Value; return(this); } var nicSuffix = Assignments.NicHandleSuffixes .Where(a => low.EndsWith(a.Key)) .FirstOrDefault(); if (nicSuffix.Key != null) { Server = nicSuffix.Value; return(this); } Server = "whois.arin.net"; return(this); } // done throw new NoServerException(); }
public void AsciiSeparators(string description, string decoded, string encoded) => Assert.Equal(encoded, Punycode.ToAscii(decoded));
public void UnicodeStrings(string description, string decoded, string encoded) { Assert.Equal(encoded, Punycode.ToUnicode(encoded)); Assert.Equal(decoded, Punycode.ToUnicode(decoded)); }
public void UnicodeDomains(string description, string decoded, string encoded) => Assert.Equal(decoded, Punycode.ToUnicode(encoded));
public void Encode(string description, string decoded, string encoded) => Assert.Equal(encoded, Punycode.Encode(decoded));
void DecodeFailsOnOverflow() => Assert.Throws <ArgumentOutOfRangeException>(() => Punycode.Decode("\x81"));
void DecodeFailsOnIllegalInput() => Assert.Throws <ArgumentOutOfRangeException>(() => Punycode.Decode("\x81-"));