All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
validity-period.h
1 
21 #ifndef NDN_VALIDITY_PERIOD_H
22 #define NDN_VALIDITY_PERIOD_H
23 
24 #include <float.h>
25 #include <math.h>
26 #include <ndn-cpp/c/security/validity-period-types.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
36 static __inline void
37 ndn_ValidityPeriod_clear(struct ndn_ValidityPeriod *self)
38 {
39  self->notBefore = DBL_MAX;
40  self->notAfter = -DBL_MAX;
41 }
42 
47 static __inline void
48 ndn_ValidityPeriod_initialize(struct ndn_ValidityPeriod *self)
49 {
50  ndn_ValidityPeriod_clear(self);
51 }
52 
59 static __inline int
60 ndn_ValidityPeriod_hasPeriod(const struct ndn_ValidityPeriod *self)
61 {
62  return !(self->notBefore == DBL_MAX && self->notAfter == -DBL_MAX);
63 }
64 
75 static __inline void
76 ndn_ValidityPeriod_setPeriod
77  (struct ndn_ValidityPeriod *self, ndn_MillisecondsSince1970 notBefore,
78  ndn_MillisecondsSince1970 notAfter)
79 {
80  // Round up to the nearest second.
81  self->notBefore = round(ceil(round(notBefore) / 1000.0) * 1000.0);
82  // Round down to the nearest second.
83  self->notAfter = round(floor(round(notAfter) / 1000.0) * 1000.0);
84 }
85 
91 static __inline int
92 ndn_ValidityPeriod_equals
93  (const struct ndn_ValidityPeriod *self, const struct ndn_ValidityPeriod *other)
94 {
95  return self->notBefore == other->notBefore &&
96  self->notAfter == other->notAfter;
97 }
98 
106 static __inline int
107 ndn_ValidityPeriod_isValid
108  (const struct ndn_ValidityPeriod *self, ndn_MillisecondsSince1970 time)
109 {
110  return self->notBefore <= time && time <= self->notAfter;
111 }
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif
Copyright (C) 2016-2018 Regents of the University of California.
Definition: validity-period-types.h:34
ndn_MillisecondsSince1970 notAfter
-DBL_MAX for none.
Definition: validity-period-types.h:36
ndn_MillisecondsSince1970 notBefore
DBL_MAX for none.
Definition: validity-period-types.h:35