@@ -330,7 +330,7 @@ impl OMNameResolver {
330
330
}
331
331
332
332
/// Builds a new [`OMNameResolver`] which will not validate the time limits on DNSSEC proofs
333
- /// (at least until [`Self::new_best_block`] is called).
333
+ /// (for builds without the "std" feature and until [`Self::new_best_block`] is called).
334
334
///
335
335
/// If possible, you should prefer [`Self::new`] so that providing stale proofs is not
336
336
/// possible, however in no-std environments where there is some trust in the resolver used and
@@ -339,7 +339,7 @@ impl OMNameResolver {
339
339
/// Note that not calling [`Self::new_best_block`] will result in requests not timing out and
340
340
/// unresolved requests leaking memory. You must instead call
341
341
/// [`Self::expire_pending_resolution`] as unresolved requests expire.
342
- pub fn new_without_expiry_validation ( ) -> Self {
342
+ pub fn new_without_no_std_expiry_validation ( ) -> Self {
343
343
Self {
344
344
pending_resolves : Mutex :: new ( new_hash_map ( ) ) ,
345
345
latest_block_time : AtomicUsize :: new ( 0 ) ,
@@ -478,16 +478,24 @@ impl OMNameResolver {
478
478
let validated_rrs =
479
479
parsed_rrs. as_ref ( ) . and_then ( |rrs| verify_rr_stream ( rrs) . map_err ( |_| & ( ) ) ) ;
480
480
if let Ok ( validated_rrs) = validated_rrs {
481
- let block_time = self . latest_block_time . load ( Ordering :: Acquire ) as u64 ;
482
- if block_time != 0 {
481
+ #[ allow( unused_assignments, unused_mut) ]
482
+ let mut time = self . latest_block_time . load ( Ordering :: Acquire ) as u64 ;
483
+ #[ cfg( feature = "std" ) ]
484
+ {
485
+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
486
+ let now = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) ;
487
+ time = now. expect ( "Time must be > 1970" ) . as_secs ( ) ;
488
+ }
489
+ if time != 0 {
483
490
// Block times may be up to two hours in the future and some time into the past
484
491
// (we assume no more than two hours, though the actual limits are rather
485
492
// complicated).
486
493
// Thus, we have to let the proof times be rather fuzzy.
487
- if validated_rrs. valid_from > block_time + 60 * 2 {
494
+ let max_time_offset = if cfg ! ( feature = "std" ) { 0 } else { 60 * 2 } ;
495
+ if validated_rrs. valid_from > time + max_time_offset {
488
496
return None ;
489
497
}
490
- if validated_rrs. expires < block_time - 60 * 2 {
498
+ if validated_rrs. expires < time - max_time_offset {
491
499
return None ;
492
500
}
493
501
}
0 commit comments