Class: Dnsruby::KeyCache
- Inherits:
-
Object
- Object
- Dnsruby::KeyCache
- Defined in:
- lib/dnsruby/key_cache.rb
Overview
:nodoc: all
Instance Method Summary collapse
- #add(k) ⇒ Object
- #add_key_with_expiration(k, expiration) ⇒ Object
- #add_rrset(k) ⇒ Object
- #each ⇒ Object
- #find_key_for(name) ⇒ Object
-
#initialize(keys = nil) ⇒ KeyCache
constructor
Cache includes expiration time for keys Cache removes expired records.
- #keys ⇒ Object
-
#keys_and_expirations ⇒ Object
return @keys.keys.
- #priv_add_key(k, exp) ⇒ Object
- #remove_expired_keys ⇒ Object
Constructor Details
Instance Method Details
#add(k) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dnsruby/key_cache.rb', line 29 def add(k) if (k == nil) return false elsif (k.instance_of?RRSet) add_rrset(k) elsif (k.kind_of?KeyCache) kaes = k.keys_and_expirations kaes.keys.each { |keykey| # priv_add_key(keykey, kaes[keykey]) priv_add_key(keykey[1], keykey[0]) } else raise ArgumentError.new("Expected an RRSet or KeyCache! Got #{k.class}") end return true end |
#add_key_with_expiration(k, expiration) ⇒ Object
26 27 28 |
# File 'lib/dnsruby/key_cache.rb', line 26 def add_key_with_expiration(k, expiration) priv_add_key(k, expiration) end |
#add_rrset(k) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dnsruby/key_cache.rb', line 46 def add_rrset(k) # Get expiration from the RRSIG # There can be several RRSIGs here, one for each key which has signed the RRSet # We want to choose the one with the most secure signing algorithm, key length, # and the longest expiration time - not easy! # for now, we simply accept all signed keys k.sigs.each { |sig| if (sig.type_covered = Types.DNSKEY) if (sig.inception <= Time.now.to_i) # Check sig.expiration, sig.algorithm if (sig.expiration > Time.now.to_i) # add the keys to the store k.rrs.each {|rr| priv_add_key(rr, sig.expiration)} end end end } end |
#each ⇒ Object
74 75 76 77 78 |
# File 'lib/dnsruby/key_cache.rb', line 74 def each # Only offer currently-valid keys here remove_expired_keys @keys.values.each {|v| yield v[1]} end |
#find_key_for(name) ⇒ Object
96 97 98 99 |
# File 'lib/dnsruby/key_cache.rb', line 96 def find_key_for(name) each {|key| return key if key.name == name} return false end |
#keys ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/dnsruby/key_cache.rb', line 79 def keys # Only offer currently-valid keys here remove_expired_keys ks = [] @keys.values.each {|a| ks.push(a[1])} return ks # return @keys.keys end |
#keys_and_expirations ⇒ Object
return @keys.keys
87 88 89 90 |
# File 'lib/dnsruby/key_cache.rb', line 87 def keys_and_expirations remove_expired_keys return keys.values end |
#priv_add_key(k, exp) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/dnsruby/key_cache.rb', line 65 def priv_add_key(k, exp) # Check that the key does not already exist with a longer expiration! if (@keys[k] == nil) @keys[k.key_tag] = [exp,k] elsif ((@keys[k])[0] < exp) @keys[k.key_tag] = [exp,k] end end |
#remove_expired_keys ⇒ Object
91 92 93 94 95 |
# File 'lib/dnsruby/key_cache.rb', line 91 def remove_expired_keys @keys.delete_if {|k,v| v[0] < Time.now.to_i } end |