Class: Dnsruby::RR::HIP
- Inherits:
-
Dnsruby::RR
- Object
- Dnsruby::RR
- Dnsruby::RR::HIP
- Defined in:
- lib/dnsruby/resource/HIP.rb
Constant Summary collapse
Constants inherited from Dnsruby::RR
Instance Attribute Summary collapse
-
#hit_length ⇒ Object
An 8-bit length for the HIT field.
-
#pk_algorithm ⇒ Object
The PK algorithm used : 0 - no key present 1 - DSA key present 2 - RSA key present.
-
#pk_length ⇒ Object
An 8-bit length for the Public Key field.
-
#rsvs ⇒ Object
An array of Rendezvous Servers.
Attributes inherited from Dnsruby::RR
#klass, #name, #rdata, #ttl, #type
Class Method Summary collapse
-
.decode_rdata(msg) ⇒ Object
:nodoc: all.
Instance Method Summary collapse
-
#encode_rdata(msg, canonical = false) ⇒ Object
:nodoc: all.
-
#from_data(data) ⇒ Object
:nodoc: all.
- #from_hash(hash) ⇒ Object
- #from_string(input) ⇒ Object
- #hit_from_string(hit_text) ⇒ Object
-
#hit_string ⇒ Object
HIT field - stored in binary : client methods should handle base16(hex) encoding.
- #public_key_from_string(key_text) ⇒ Object
-
#public_key_string ⇒ Object
Public Key field - presentation format is base64 - public_key methods reused from IPSECKEY.
-
#rdata_to_string ⇒ Object
:nodoc: all.
Methods inherited from Dnsruby::RR
#<=>, #==, #clone, create, #eql?, find_class, get_class, get_num, #hash, implemented_rrs, #init_defaults, new_from_data, new_from_hash, new_from_string, #rdlength, #sameRRset, #to_s
Instance Attribute Details
#hit_length ⇒ Object
An 8-bit length for the HIT field
25 26 27 |
# File 'lib/dnsruby/resource/HIP.rb', line 25 def hit_length @hit_length end |
#pk_algorithm ⇒ Object
The PK algorithm used :
0 - no key present
1 - DSA key present
2 - RSA key present
30 31 32 |
# File 'lib/dnsruby/resource/HIP.rb', line 30 def pk_algorithm @pk_algorithm end |
#pk_length ⇒ Object
An 8-bit length for the Public Key field
32 33 34 |
# File 'lib/dnsruby/resource/HIP.rb', line 32 def pk_length @pk_length end |
#rsvs ⇒ Object
An array of Rendezvous Servers
35 36 37 |
# File 'lib/dnsruby/resource/HIP.rb', line 35 def rsvs @rsvs end |
Class Method Details
.decode_rdata(msg) ⇒ Object
:nodoc: all
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/dnsruby/resource/HIP.rb', line 123 def self.decode_rdata(msg) #:nodoc: all hit_length, pk_algorithm, pk_length = msg.get_unpack('ccC') hit = msg.get_bytes(hit_length) public_key = msg.get_bytes(pk_length) rsvs = [] # Load in the RSV names, if there are any while (msg.has_remaining?) name = msg.get_name rsvs.push(name) end return self.new( [hit_length, pk_algorithm, pk_length, hit, public_key, rsvs]) end |
Instance Method Details
#encode_rdata(msg, canonical = false) ⇒ Object
:nodoc: all\
113 114 115 116 117 118 119 120 121 |
# File 'lib/dnsruby/resource/HIP.rb', line 113 def encode_rdata(msg, canonical=false) #:nodoc: all\ msg.put_pack('ccC', @hit_length, @pk_algorithm, @pk_length) msg.put_bytes(@hit) msg.put_bytes(@public_key) @rsvs.each {|rsv| # RSVs MUST NOT be compressed msg.put_name(rsv, true) } end |
#from_data(data) ⇒ Object
:nodoc: all
37 38 39 40 41 42 43 44 45 |
# File 'lib/dnsruby/resource/HIP.rb', line 37 def from_data(data) #:nodoc: all @rsvs=[] @hit_length = data[0] @pk_algorithm = data[1] @pk_length = data[2] @hit = data[3] @public_key = data[4] @rsvs = data[5] end |
#from_hash(hash) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dnsruby/resource/HIP.rb', line 47 def from_hash(hash) @rsvs=[] @hit_length = hash[:hit_length] @pk_algorithm = hash[:pk_algorithm] @pk_length = hash[:pk_length] @hit = hash[:hit] @public_key = hash[:public_key] if (hash[:rsvs]) hash[:rsvs].each {|rsv| @rsvs.push(Name.create(rsv)) } end end |
#from_string(input) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/dnsruby/resource/HIP.rb', line 84 def from_string(input) @rsvs=[] if (input.length > 0) split = input.split(" ") @pk_algorithm = split[0].to_i @hit = hit_from_string(split[1]) @hit_length = @hit.length @public_key = public_key_from_string(split[2]) @pk_length = @public_key.length # Now load in any RSVs there may be count = 3 while (split[count]) @rsvs.push(Name.create(split[count])) count += 1 end end end |
#hit_from_string(hit_text) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/dnsruby/resource/HIP.rb', line 66 def hit_from_string(hit_text) # Decode the hex value hit_text.gsub!(/\n/, "") hit_text.gsub!(/ /, "") return hit_text.unpack("H*")[0] end |
#hit_string ⇒ Object
HIT field - stored in binary : client methods should handle base16(hex) encoding
62 63 64 65 |
# File 'lib/dnsruby/resource/HIP.rb', line 62 def hit_string # Return hex value [@hit.to_s].pack("H*").gsub("\n", "") end |
#public_key_from_string(key_text) ⇒ Object
78 79 80 81 82 |
# File 'lib/dnsruby/resource/HIP.rb', line 78 def public_key_from_string(key_text) key_text.gsub!(/\n/, "") key_text.gsub!(/ /, "") return key_text.unpack("m*")[0] end |
#public_key_string ⇒ Object
Public Key field - presentation format is base64 - public_key methods reused from IPSECKEY
74 75 76 |
# File 'lib/dnsruby/resource/HIP.rb', line 74 def public_key_string [@public_key.to_s].pack("m*").gsub("\n", "") end |
#rdata_to_string ⇒ Object
:nodoc: all
105 106 107 108 109 110 111 |
# File 'lib/dnsruby/resource/HIP.rb', line 105 def rdata_to_string #:nodoc: all ret = "#{@pk_algorithm} #{hit_string} #{public_key_string}" @rsvs.each {|rsv| ret += " #{rsv.to_s(true)}" } return ret end |