1c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Use of this source code is governed by a BSD-style license that can be
3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// found in the LICENSE file.
4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifndef NET_BASE_DNS_UTIL_H_
6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define NET_BASE_DNS_UTIL_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
9c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include <string>
10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
113345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#include "base/basictypes.h"
123345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottnamespace net {
14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// DNSDomainFromDot - convert a domain string to DNS format. From DJB's
16c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// public domain DNS library.
17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//
18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//   dotted: a string in dotted form: "www.google.com"
19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//   out: a result in DNS form: "\x03www\x06google\x03com\x00"
20c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottbool DNSDomainFromDot(const std::string& dotted, std::string* out);
21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
22dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen// DNSDomainToString coverts a domain in DNS format to a dotted string.
23dc0f95d653279beabeb9817299e2902918ba123eKristian Monsenstd::string DNSDomainToString(const std::string& domain);
24dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Returns true iff the given character is in the set of valid DNS label
26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// characters as given in RFC 3490, 4.1, 3(a)
27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottbool IsSTD3ASCIIValidCharacter(char c);
28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Returns the hostname by trimming the ending dot, if one exists.
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstd::string TrimEndingDot(const std::string& host);
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
323345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// DNS resource record types. See
333345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// http://www.iana.org/assignments/dns-parameters
3472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// WARNING: if you're adding any new values here you may need to add them to
3572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// dnsrr_resolver.cc:DnsRRIsParsedByWindows.
363345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
373345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint16 kDNS_CNAME = 5;
383345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint16 kDNS_TXT = 16;
393345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint16 kDNS_CERT = 37;
403345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint16 kDNS_DS = 43;
413345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint16 kDNS_RRSIG = 46;
423345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint16 kDNS_DNSKEY = 48;
433345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint16 kDNS_ANY = 0xff;
443f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsenstatic const uint16 kDNS_CAA = 13172;  // temporary, not IANA
45731df977c0511bca2206b5f333555b1205ff1f43Iain Merrickstatic const uint16 kDNS_TESTING = 0xfffe;  // in private use area.
463345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
473345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
483345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint8 kDNSSEC_RSA_SHA1 = 5;
493345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint8 kDNSSEC_RSA_SHA1_NSEC3 = 7;
503345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint8 kDNSSEC_RSA_SHA256 = 8;
513345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
523345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// RFC 4509
533345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint8 kDNSSEC_SHA1 = 1;
543345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstatic const uint8 kDNSSEC_SHA256 = 2;
553345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
56c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}  // namespace net
57c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
58c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif  // NET_BASE_DNS_UTIL_H_
59