Chromium Code Reviews| Index: net/dns/record_rdata.cc |
| diff --git a/net/dns/record_rdata.cc b/net/dns/record_rdata.cc |
| index 55967f91a9aef249a6973070280b2d20361afba3..8cec2200ccfbacb72aa8a595f92c1d31cb67fa48 100644 |
| --- a/net/dns/record_rdata.cc |
| +++ b/net/dns/record_rdata.cc |
| @@ -215,4 +215,60 @@ 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); |
|
szym
2013/06/24 21:50:28
nit: |next_domain_len| would be better, |next_doma
Noam Samuel
2013/06/25 01:31:31
Done.
|
| + |
| + if (len_next_domain == 0 || data.length() < len_next_domain + 2) |
| + return scoped_ptr<NsecRecordRdata>(); |
| + |
|
szym
2013/06/24 21:50:28
StringPiece::operator[] returns char, so I'd sugge
Noam Samuel
2013/06/25 01:31:31
Done.
|
| + unsigned window_num = data[len_next_domain]; |
|
szym
2013/06/24 21:50:28
I suggest block_num or block_number
"window number
Noam Samuel
2013/06/25 01:31:31
Done.
|
| + unsigned len = data[len_next_domain+1]; |
|
szym
2013/06/24 21:50:28
bitmap_length
Noam Samuel
2013/06/25 01:31:31
Done.
|
| + |
| + // The window number must be zero in mDns-secific nsec records. The bitmap |
|
szym
2013/06/24 21:50:28
"specific"
"NSEC"
Noam Samuel
2013/06/25 01:31:31
Done.
|
| + // 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. |
|
szym
2013/06/24 21:50:28
"exactly"
Noam Samuel
2013/06/25 01:31:31
Done.
|
| + if (window_num != 0 || len == 0 || len > 32 || |
| + data.length() != len_next_domain + 2 + len) |
|
szym
2013/06/24 21:50:28
The last check would be easier to understand if yo
Noam Samuel
2013/06/25 01:31:31
Done.
|
| + return scoped_ptr<NsecRecordRdata>(); |
| + |
| + base::StringPiece bitmap_data = data.substr(len_next_domain + 2); |
| + |
| + rdata->bitmap_.insert(rdata->bitmap_.begin(), |
| + bitmap_data.begin(), |
|
gene
2013/06/24 19:47:16
indentation
Noam Samuel
2013/06/24 21:31:30
Done.
|
| + 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; |
|
gene
2013/06/24 19:47:16
move return to the next line
Noam Samuel
2013/06/24 21:31:30
Done.
|
| + const NsecRecordRdata* nsec_other = |
| + static_cast<const NsecRecordRdata*>(other); |
| + return bitmap_ == nsec_other->bitmap_; |
| +} |
| + |
| +bool NsecRecordRdata::bit(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 |