# File lib/Dnsruby/resource/NSEC.rb, line 105 def self.decode_types(bytes) types = [] #RFC4034 section 4.1.2 #The RR type space is split into 256 window blocks, each representing #the low-order 8 bits of the 16-bit RR type space. Each block that #has at least one active RR type is encoded using a single octet #window number (from 0 to 255), a single octet bitmap length (from 1 #to 32) indicating the number of octets used for the window block's #bitmap, and up to 32 octets (256 bits) of bitmap. #Blocks are present in the NSEC RR RDATA in increasing numerical #order. # Type Bit Maps Field = ( Window Block # | Bitmap Length | Bitmap )+ # where "|" denotes concatenation. pos = 0 while (pos < bytes.length) #So, read the first two octets if (bytes.length-pos < 2) raise DecodeError.new("NSEC : Expected window number and bitmap length octets") end window_number = bytes[pos] bitmap_length = bytes[pos+1] if (window_number.class == String) # Ruby 1.9 window_number = window_number.getbyte(0) bitmap_length = bitmap_length.getbyte(0) end pos += 2 bitmap = bytes[pos,bitmap_length] pos += bitmap_length #Each bitmap encodes the low-order 8 bits of RR types within the #window block, in network bit order. The first bit is bit 0. For #window block 0, bit 1 corresponds to RR type 1 (A), bit 2 corresponds #to RR type 2 (NS), and so forth. For window block 1, bit 1 #corresponds to RR type 257, and bit 2 to RR type 258. If a bit is #set, it indicates that an RRset of that type is present for the NSEC #RR's owner name. If a bit is clear, it indicates that no RRset of #that type is present for the NSEC RR's owner name. index = 0 bitmap.each_byte do |char| if char.to_i != 0 # decode these RR types 0..8.times do |i| if (((1 << (7-i)) & char) == (1 << (7-i))) type = Types.new((256 * window_number) + (8 * index) + i) #Bits representing pseudo-types MUST be clear, as they do not appear #in zone data. If encountered, they MUST be ignored upon being read. if (!([Types::OPT, Types::TSIG].include?(type))) types.push(type) end end end end index += 1 end end return types end