| Index: net/dns/record_rdata.cc
|
| diff --git a/net/dns/record_rdata.cc b/net/dns/record_rdata.cc
|
| index 55967f91a9aef249a6973070280b2d20361afba3..06ab4a72a80ed90f85facfd786a06f671075a2ce 100644
|
| --- a/net/dns/record_rdata.cc
|
| +++ b/net/dns/record_rdata.cc
|
| @@ -215,4 +215,61 @@ bool TxtRecordRdata::IsEqual(const RecordRdata* other) const {
|
| return texts_ == txt_other->texts_;
|
| }
|
|
|
| +NsecRecordRdata::NsecRecordRdata() {
|
| +}
|
| +
|
| +NsecRecordRdata::~NsecRecordRdata() {
|
| +}
|
| +
|
| +// static
|
| +scoped_ptr<NsecRecordRdata> NsecRecordRdata::Create(
|
| + const base::StringPiece& data,
|
| + const DnsRecordParser& parser) {
|
| + scoped_ptr<NsecRecordRdata> rdata(new NsecRecordRdata);
|
| +
|
| + unsigned len_next_domain = parser.ReadName(data.data(), NULL);
|
| +
|
| + if (len_next_domain == 0 || data.length() < len_next_domain + 2)
|
| + return scoped_ptr<NsecRecordRdata>();
|
| +
|
| + unsigned window_num = data[len_next_domain];
|
| + unsigned len = data[len_next_domain+1];
|
| +
|
| + // The window number must be zero in mDns-secific nsec records. The bitmap
|
| + // length must be between 1 and 32, and since we may only have one window, the
|
| + // data length must be exactl equal to the domain length plus bitmap size.
|
| + if (window_num != 0 || len == 0 || len > 32 ||
|
| + data.length() != len_next_domain + 2 + len)
|
| + return scoped_ptr<NsecRecordRdata>();
|
| +
|
| + base::StringPiece bitmap_data = data.substr(len_next_domain + 2);
|
| +
|
| + rdata->bitmap_.insert(rdata->bitmap_.begin(),
|
| + bitmap_data.begin(),
|
| + bitmap_data.end());
|
| +
|
| + return rdata.Pass();
|
| +}
|
| +
|
| +uint16 NsecRecordRdata::Type() const {
|
| + return NsecRecordRdata::kType;
|
| +}
|
| +
|
| +bool NsecRecordRdata::IsEqual(const RecordRdata* other) const {
|
| + if (other->Type() != Type())
|
| + return false;
|
| + const NsecRecordRdata* nsec_other =
|
| + static_cast<const NsecRecordRdata*>(other);
|
| + return bitmap_ == nsec_other->bitmap_;
|
| +}
|
| +
|
| +bool NsecRecordRdata::GetBit(unsigned i) {
|
| + unsigned byte_num = i/8;
|
| + if (bitmap_.size() < byte_num + 1)
|
| + return false;
|
| +
|
| + unsigned bit_num = 7 - i % 8;
|
| + return (bitmap_[byte_num] & (1 << bit_num)) != 0;
|
| +}
|
| +
|
| } // namespace net
|
|
|