Module: Dnsruby::SerialTime
- Defined in:
- lib/dnsruby/serial_time.rb
Overview
RRSIG times are serial numbers, not absolute Unix timestamps (RFC 4034 section 3.1.5). Resolve each field into the era nearest the current time before comparing it with ordinary, absolute cache deadlines.
Constant Summary collapse
- MASK =
:nodoc: all
(1 << 32) - 1
- HALF =
1 << 31
Class Method Summary collapse
Class Method Details
.absolute(value, reference) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/dnsruby/serial_time.rb', line 11 def self.absolute(value, reference) distance = (value.to_i - reference.to_i) & MASK # RFC 1982 deliberately leaves this ordering undefined. return nil if distance == HALF distance -= MASK + 1 if distance > HALF reference.to_i + distance end |
.valid?(inception, expiration, now = Time.now.to_i) ⇒ Boolean
19 20 21 22 23 |
# File 'lib/dnsruby/serial_time.rb', line 19 def self.valid?(inception, expiration, now = Time.now.to_i) starts = absolute(inception, now) ends = absolute(expiration, now) starts && ends && starts <= now && now <= ends end |