1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#--
#Copyright 2007 Nominet UK
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#++
module Dnsruby
class RR
class SSHFP < RR
ClassValue = nil #:nodoc: all
TypeValue = Types::SSHFP #:nodoc: all
attr_accessor :alg
attr_accessor :fptype
attr_accessor :fp
class Algorithms < CodeMapper
RSA = 1
DSS = 2
update()
end
class FpTypes < CodeMapper
SHA1 = 1
update()
end
def from_data(data) #:nodoc: all
alg, fptype, @fp = data
@alg = Algorithms.new(alg)
@fptype = FpTypes.new(fptype)
end
def from_hash(hash)
if hash[:alg]
@alg = Algorithms.new(hash[:alg])
end
if hash[:fptype]
@fptype = FpTypes.new(hash[:fptype])
end
if hash[:fp]
@fp = hash[:fp]
end
end
def from_string(input)
if (input.length > 0)
names = input.split(" ")
begin
@alg = Algorithms.new(names[0].to_i)
rescue ArgumentError
@alg = Algorithms.new(names[0])
end
begin
@fptype = FpTypes.new(names[1].to_i)
rescue ArgumentError
@fptype = FpTypes.new(names[1])
end
remaining = ""
for i in 2..(names.length + 1)
remaining += names[i].to_s
end
@fp = [remaining].pack("H*")
end
end
def rdata_to_string
ret = "#{@alg.code} #{@fptype.code} "
ret += @fp.unpack("H*")[0]
return ret
end
def encode_rdata(msg, canonical=false) #:nodoc: all
msg.put_pack("c", @alg.code)
msg.put_pack("c", @fptype.code)
msg.put_bytes(@fp)
end
def self.decode_rdata(msg) #:nodoc: all
alg, fptype = msg.get_unpack("cc")
fp = msg.get_bytes
return self.new([alg, fptype, fp])
end
end
end
end
|