]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Minor refactor of dst code
authorMatthijs Mekking <matthijs@isc.org>
Mon, 22 Sep 2025 14:58:22 +0000 (16:58 +0200)
committerMatthijs Mekking <matthijs@isc.org>
Wed, 1 Oct 2025 12:25:53 +0000 (12:25 +0000)
Convert the defines to enums. Initialize the tags more explicitly and
less ugly.

lib/dns/dst_api.c
lib/dns/dst_internal.h
lib/dns/dst_parse.c
lib/dns/include/dst/dst.h
lib/dns/keymgr.c
lib/dns/zone.c

index 88a488772c04ed6e3f106f931520880befe695c8..f5d8d94ba4bac10f4dd211433bf3c08c5c6a2949 100644 (file)
                goto cleanup;                \
        }
 
-#define NUMERIC_NTAGS (DST_MAX_NUMERIC + 1)
-static const char *numerictags[NUMERIC_NTAGS] = {
-       "Predecessor:", "Successor:",  "MaxTTL:",    "RollPeriod:",
-       "Lifetime:",    "DSPubCount:", "DSRemCount:"
+static const char *numerictags[DST_MAX_NUMERIC] = {
+       [DST_NUM_PREDECESSOR] = "Predecessor:",
+       [DST_NUM_SUCCESSOR] = "Successor:",
+       [DST_NUM_MAXTTL] = "MaxTTL:",
+       [DST_NUM_ROLLPERIOD] = "RollPeriod:",
+       [DST_NUM_LIFETIME] = "Lifetime:",
+       [DST_NUM_DSPUBCOUNT] = "DSPubCount:",
+       [DST_NUM_DSDELCOUNT] = "DSRemCount:",
 };
 
-#define BOOLEAN_NTAGS (DST_MAX_BOOLEAN + 1)
-static const char *booleantags[BOOLEAN_NTAGS] = { "KSK:", "ZSK:" };
-
-#define TIMING_NTAGS (DST_MAX_TIMES + 1)
-static const char *timingtags[TIMING_NTAGS] = {
-       "Generated:",    "Published:",    "Active:",       "Revoked:",
-       "Retired:",      "Removed:",
-
-       "DSPublish:",    "SyncPublish:",  "SyncDelete:",
-
-       "DNSKEYChange:", "ZRRSIGChange:", "KRRSIGChange:", "DSChange:",
+static const char *booleantags[DST_MAX_BOOLEAN] = {
+       [DST_BOOL_KSK] = "KSK:",
+       [DST_BOOL_ZSK] = "ZSK:",
+};
 
-       "DSRemoved:",    "ZRRSIGPublish", "ZRRSIGRemoved"
+static const char *timingtags[DST_MAX_TIMES] = {
+       [DST_TIME_CREATED] = "Generated:",
+       [DST_TIME_PUBLISH] = "Published:",
+       [DST_TIME_ACTIVATE] = "Active:",
+       [DST_TIME_REVOKE] = "Revoked:",
+       [DST_TIME_INACTIVE] = "Retired:",
+       [DST_TIME_DELETE] = "Removed:",
+       [DST_TIME_DSPUBLISH] = "DSPublish:",
+       [DST_TIME_SYNCPUBLISH] = "SyncPublish:",
+       [DST_TIME_SYNCDELETE] = "SyncDelete:",
+       [DST_TIME_DNSKEY] = "DNSKEYChange:",
+       [DST_TIME_ZRRSIG] = "ZRRSIGChange:",
+       [DST_TIME_KRRSIG] = "KRRSIGChange:",
+       [DST_TIME_DS] = "DSChange:",
+       [DST_TIME_DSDELETE] = "DSRemoved:",
+       [DST_TIME_SIGPUBLISH] = "ZRRSIGPublish:",
+       [DST_TIME_SIGDELETE] = "ZZRRSIGDelete:",
 };
 
-#define KEYSTATES_NTAGS (DST_MAX_KEYSTATES + 1)
-static const char *keystatestags[KEYSTATES_NTAGS] = {
-       "DNSKEYState:", "ZRRSIGState:", "KRRSIGState:", "DSState:", "GoalState:"
+static const char *keystatestags[DST_MAX_KEYSTATES] = {
+       [DST_KEY_DNSKEY] = "DNSKEYState:", [DST_KEY_ZRRSIG] = "ZRRSIGState:",
+       [DST_KEY_KRRSIG] = "KRRSIGState:", [DST_KEY_DS] = "DSState:",
+       [DST_KEY_GOAL] = "GoalState:",
 };
 
 #define KEYSTATES_NVALUES 4
@@ -987,7 +1001,7 @@ isc_result_t
 dst_key_getbool(const dst_key_t *key, int type, bool *valuep) {
        REQUIRE(VALID_KEY(key));
        REQUIRE(valuep != NULL);
-       REQUIRE(type <= DST_MAX_BOOLEAN);
+       REQUIRE(type < DST_MAX_BOOLEAN);
 
        isc_mutex_lock(&(((dst_key_t *)key)->mdlock));
        if (!key->boolset[type]) {
@@ -1003,7 +1017,7 @@ dst_key_getbool(const dst_key_t *key, int type, bool *valuep) {
 void
 dst_key_setbool(dst_key_t *key, int type, bool value) {
        REQUIRE(VALID_KEY(key));
-       REQUIRE(type <= DST_MAX_BOOLEAN);
+       REQUIRE(type < DST_MAX_BOOLEAN);
 
        isc_mutex_lock(&key->mdlock);
        key->modified = key->modified || !key->boolset[type] ||
@@ -1016,7 +1030,7 @@ dst_key_setbool(dst_key_t *key, int type, bool value) {
 void
 dst_key_unsetbool(dst_key_t *key, int type) {
        REQUIRE(VALID_KEY(key));
-       REQUIRE(type <= DST_MAX_BOOLEAN);
+       REQUIRE(type < DST_MAX_BOOLEAN);
 
        isc_mutex_lock(&key->mdlock);
        key->modified = key->modified || key->boolset[type];
@@ -1028,7 +1042,7 @@ isc_result_t
 dst_key_getnum(const dst_key_t *key, int type, uint32_t *valuep) {
        REQUIRE(VALID_KEY(key));
        REQUIRE(valuep != NULL);
-       REQUIRE(type <= DST_MAX_NUMERIC);
+       REQUIRE(type < DST_MAX_NUMERIC);
 
        isc_mutex_lock(&(((dst_key_t *)key)->mdlock));
        if (!key->numset[type]) {
@@ -1044,7 +1058,7 @@ dst_key_getnum(const dst_key_t *key, int type, uint32_t *valuep) {
 void
 dst_key_setnum(dst_key_t *key, int type, uint32_t value) {
        REQUIRE(VALID_KEY(key));
-       REQUIRE(type <= DST_MAX_NUMERIC);
+       REQUIRE(type < DST_MAX_NUMERIC);
 
        isc_mutex_lock(&key->mdlock);
        key->modified = key->modified || !key->numset[type] ||
@@ -1057,7 +1071,7 @@ dst_key_setnum(dst_key_t *key, int type, uint32_t value) {
 void
 dst_key_unsetnum(dst_key_t *key, int type) {
        REQUIRE(VALID_KEY(key));
-       REQUIRE(type <= DST_MAX_NUMERIC);
+       REQUIRE(type < DST_MAX_NUMERIC);
 
        isc_mutex_lock(&key->mdlock);
        key->modified = key->modified || key->numset[type];
@@ -1069,7 +1083,7 @@ isc_result_t
 dst_key_gettime(const dst_key_t *key, int type, isc_stdtime_t *timep) {
        REQUIRE(VALID_KEY(key));
        REQUIRE(timep != NULL);
-       REQUIRE(type <= DST_MAX_TIMES);
+       REQUIRE(type < DST_MAX_TIMES);
 
        isc_mutex_lock(&(((dst_key_t *)key)->mdlock));
        if (!key->timeset[type]) {
@@ -1084,7 +1098,7 @@ dst_key_gettime(const dst_key_t *key, int type, isc_stdtime_t *timep) {
 void
 dst_key_settime(dst_key_t *key, int type, isc_stdtime_t when) {
        REQUIRE(VALID_KEY(key));
-       REQUIRE(type <= DST_MAX_TIMES);
+       REQUIRE(type < DST_MAX_TIMES);
 
        isc_mutex_lock(&key->mdlock);
        key->modified = key->modified || !key->timeset[type] ||
@@ -1097,7 +1111,7 @@ dst_key_settime(dst_key_t *key, int type, isc_stdtime_t when) {
 void
 dst_key_unsettime(dst_key_t *key, int type) {
        REQUIRE(VALID_KEY(key));
-       REQUIRE(type <= DST_MAX_TIMES);
+       REQUIRE(type < DST_MAX_TIMES);
 
        isc_mutex_lock(&key->mdlock);
        key->modified = key->modified || key->timeset[type];
@@ -1109,7 +1123,7 @@ isc_result_t
 dst_key_getstate(const dst_key_t *key, int type, dst_key_state_t *statep) {
        REQUIRE(VALID_KEY(key));
        REQUIRE(statep != NULL);
-       REQUIRE(type <= DST_MAX_KEYSTATES);
+       REQUIRE(type < DST_MAX_KEYSTATES);
 
        isc_mutex_lock(&(((dst_key_t *)key)->mdlock));
        if (!key->keystateset[type]) {
@@ -1125,7 +1139,7 @@ dst_key_getstate(const dst_key_t *key, int type, dst_key_state_t *statep) {
 void
 dst_key_setstate(dst_key_t *key, int type, dst_key_state_t state) {
        REQUIRE(VALID_KEY(key));
-       REQUIRE(type <= DST_MAX_KEYSTATES);
+       REQUIRE(type < DST_MAX_KEYSTATES);
 
        isc_mutex_lock(&key->mdlock);
        key->modified = key->modified || !key->keystateset[type] ||
@@ -1138,7 +1152,7 @@ dst_key_setstate(dst_key_t *key, int type, dst_key_state_t state) {
 void
 dst_key_unsetstate(dst_key_t *key, int type) {
        REQUIRE(VALID_KEY(key));
-       REQUIRE(type <= DST_MAX_KEYSTATES);
+       REQUIRE(type < DST_MAX_KEYSTATES);
 
        isc_mutex_lock(&key->mdlock);
        key->modified = key->modified || key->keystateset[type];
@@ -1627,22 +1641,22 @@ find_metadata(const char *s, const char *tags[], int ntags) {
 
 static int
 find_numericdata(const char *s) {
-       return find_metadata(s, numerictags, NUMERIC_NTAGS);
+       return find_metadata(s, numerictags, DST_MAX_NUMERIC);
 }
 
 static int
 find_booleandata(const char *s) {
-       return find_metadata(s, booleantags, BOOLEAN_NTAGS);
+       return find_metadata(s, booleantags, DST_MAX_BOOLEAN);
 }
 
 static int
 find_timingdata(const char *s) {
-       return find_metadata(s, timingtags, TIMING_NTAGS);
+       return find_metadata(s, timingtags, DST_MAX_TIMES);
 }
 
 static int
 find_keystatedata(const char *s) {
-       return find_metadata(s, keystatestags, KEYSTATES_NTAGS);
+       return find_metadata(s, keystatestags, DST_MAX_KEYSTATES);
 }
 
 static isc_result_t
@@ -1734,7 +1748,7 @@ dst_key_read_state(const char *filename, isc_mem_t *mctx, dst_key_t **keyp) {
                /* Numeric metadata */
                tag = find_numericdata(DST_AS_STR(token));
                if (tag >= 0) {
-                       INSIST(tag < NUMERIC_NTAGS);
+                       INSIST(tag < DST_MAX_NUMERIC);
 
                        NEXTTOKEN(lex, opt | ISC_LEXOPT_NUMBER, &token);
                        if (token.type != isc_tokentype_number) {
@@ -1748,7 +1762,7 @@ dst_key_read_state(const char *filename, isc_mem_t *mctx, dst_key_t **keyp) {
                /* Boolean metadata */
                tag = find_booleandata(DST_AS_STR(token));
                if (tag >= 0) {
-                       INSIST(tag < BOOLEAN_NTAGS);
+                       INSIST(tag < DST_MAX_BOOLEAN);
 
                        NEXTTOKEN(lex, opt, &token);
                        if (token.type != isc_tokentype_string) {
@@ -1770,7 +1784,7 @@ dst_key_read_state(const char *filename, isc_mem_t *mctx, dst_key_t **keyp) {
                if (tag >= 0) {
                        uint32_t when;
 
-                       INSIST(tag < TIMING_NTAGS);
+                       INSIST(tag < DST_MAX_TIMES);
 
                        NEXTTOKEN(lex, opt, &token);
                        if (token.type != isc_tokentype_string) {
@@ -1791,7 +1805,7 @@ dst_key_read_state(const char *filename, isc_mem_t *mctx, dst_key_t **keyp) {
                if (tag >= 0) {
                        dst_key_state_t state;
 
-                       INSIST(tag < KEYSTATES_NTAGS);
+                       INSIST(tag < DST_MAX_KEYSTATES);
 
                        NEXTTOKEN(lex, opt, &token);
                        if (token.type != isc_tokentype_string) {
@@ -2310,7 +2324,7 @@ dst_key_is_unused(const dst_key_t *key) {
         * None of the key timing metadata, except Created, may be set.  Key
         * state times may be set only if their respective state is HIDDEN.
         */
-       for (int i = 0; i < DST_MAX_TIMES + 1; i++) {
+       for (int i = 0; i < DST_MAX_TIMES; i++) {
                state_type_set = false;
 
                switch (i) {
@@ -2631,7 +2645,7 @@ dst_key_copy_metadata(dst_key_t *to, dst_key_t *from) {
        REQUIRE(VALID_KEY(to));
        REQUIRE(VALID_KEY(from));
 
-       for (int i = 0; i < DST_MAX_TIMES + 1; i++) {
+       for (int i = 0; i < DST_MAX_TIMES; i++) {
                result = dst_key_gettime(from, i, &when);
                if (result == ISC_R_SUCCESS) {
                        dst_key_settime(to, i, when);
@@ -2640,7 +2654,7 @@ dst_key_copy_metadata(dst_key_t *to, dst_key_t *from) {
                }
        }
 
-       for (int i = 0; i < DST_MAX_NUMERIC + 1; i++) {
+       for (int i = 0; i < DST_MAX_NUMERIC; i++) {
                result = dst_key_getnum(from, i, &num);
                if (result == ISC_R_SUCCESS) {
                        dst_key_setnum(to, i, num);
@@ -2649,7 +2663,7 @@ dst_key_copy_metadata(dst_key_t *to, dst_key_t *from) {
                }
        }
 
-       for (int i = 0; i < DST_MAX_BOOLEAN + 1; i++) {
+       for (int i = 0; i < DST_MAX_BOOLEAN; i++) {
                result = dst_key_getbool(from, i, &yesno);
                if (result == ISC_R_SUCCESS) {
                        dst_key_setbool(to, i, yesno);
@@ -2658,7 +2672,7 @@ dst_key_copy_metadata(dst_key_t *to, dst_key_t *from) {
                }
        }
 
-       for (int i = 0; i < DST_MAX_KEYSTATES + 1; i++) {
+       for (int i = 0; i < DST_MAX_KEYSTATES; i++) {
                result = dst_key_getstate(from, i, &state);
                if (result == ISC_R_SUCCESS) {
                        dst_key_setstate(to, i, state);
index 21dc8cb06a89c35199ab0250f46d07267f3f229e..51f8cd5d26cefce815e3caa04f627ba001184bae 100644 (file)
@@ -100,21 +100,20 @@ struct dst_key {
                } pkeypair;
        } keydata; /*%< pointer to key in crypto pkg fmt */
 
-       isc_stdtime_t times[DST_MAX_TIMES + 1]; /*%< timing metadata */
-       bool timeset[DST_MAX_TIMES + 1];        /*%< data set? */
+       isc_stdtime_t times[DST_MAX_TIMES]; /*%< timing metadata */
+       bool timeset[DST_MAX_TIMES];        /*%< data set? */
 
-       uint32_t nums[DST_MAX_NUMERIC + 1]; /*%< numeric metadata
-                                            * */
-       bool numset[DST_MAX_NUMERIC + 1];   /*%< data set? */
+       uint32_t nums[DST_MAX_NUMERIC]; /*%< numeric metadata
+                                        * */
+       bool numset[DST_MAX_NUMERIC];   /*%< data set? */
 
-       bool bools[DST_MAX_BOOLEAN + 1];   /*%< boolean metadata
-                                           * */
-       bool boolset[DST_MAX_BOOLEAN + 1]; /*%< data set? */
+       bool bools[DST_MAX_BOOLEAN];   /*%< boolean metadata
+                                       * */
+       bool boolset[DST_MAX_BOOLEAN]; /*%< data set? */
 
-       dst_key_state_t keystates[DST_MAX_KEYSTATES + 1]; /*%< key states
-                                                          * */
-       bool keystateset[DST_MAX_KEYSTATES + 1];          /*%< data
-                                                          * set? */
+       dst_key_state_t keystates[DST_MAX_KEYSTATES]; /*%< key states
+                                                      * */
+       bool keystateset[DST_MAX_KEYSTATES];          /*%< data set? */
 
        bool kasp;     /*%< key has kasp state */
        bool inactive; /*%< private key not present as it is
index 479d23c603b65ec7f07126fa5693d9e7a3b621eb..9dc4f9cedd665b5efce92be23d0f398968d543aa 100644 (file)
 #define PRIVATE_KEY_STR "Private-key-format:"
 #define ALGORITHM_STR  "Algorithm:"
 
-#define TIMING_NTAGS (DST_MAX_TIMES + 1)
-static const char *timetags[TIMING_NTAGS] = {
-       "Created:", "Publish:",   "Activate:",    "Revoke:",     "Inactive:",
-       "Delete:",  "DSPublish:", "SyncPublish:", "SyncDelete:", NULL,
-       NULL,       NULL,         NULL,           NULL,          NULL
+static const char *timetags[DST_MAX_TIMES] = {
+       [DST_TIME_CREATED] = "Created:",
+       [DST_TIME_PUBLISH] = "Publish:",
+       [DST_TIME_ACTIVATE] = "Activate:",
+       [DST_TIME_REVOKE] = "Revoke:",
+       [DST_TIME_INACTIVE] = "Inactive:",
+       [DST_TIME_DELETE] = "Delete:",
+       [DST_TIME_DSPUBLISH] = "DSPublish:",
+       [DST_TIME_SYNCPUBLISH] = "SyncPublish:",
+       [DST_TIME_SYNCDELETE] = "SyncDelete:",
+       [DST_TIME_DNSKEY] = NULL,
+       [DST_TIME_ZRRSIG] = NULL,
+       [DST_TIME_KRRSIG] = NULL,
+       [DST_TIME_DS] = NULL,
+       [DST_TIME_DSDELETE] = NULL,
+       [DST_TIME_SIGPUBLISH] = NULL,
+       [DST_TIME_SIGDELETE] = NULL,
 };
 
-#define NUMERIC_NTAGS (DST_MAX_NUMERIC + 1)
-static const char *numerictags[NUMERIC_NTAGS] = {
-       "Predecessor:", "Successor:", "MaxTTL:", "RollPeriod:", NULL, NULL, NULL
+static const char *numerictags[DST_MAX_NUMERIC] = {
+       [DST_NUM_PREDECESSOR] = "Predecessor:",
+       [DST_NUM_SUCCESSOR] = "Successor:",
+       [DST_NUM_MAXTTL] = "MaxTTL:",
+       [DST_NUM_ROLLPERIOD] = "RollPeriod:",
+       [DST_NUM_LIFETIME] = NULL,
+       [DST_NUM_DSPUBCOUNT] = NULL,
+       [DST_NUM_DSDELCOUNT] = NULL,
 };
 
 struct parse_map {
@@ -151,12 +168,12 @@ find_metadata(const char *s, const char *tags[], int ntags) {
 
 static int
 find_timedata(const char *s) {
-       return find_metadata(s, timetags, TIMING_NTAGS);
+       return find_metadata(s, timetags, DST_MAX_TIMES);
 }
 
 static int
 find_numericdata(const char *s) {
-       return find_metadata(s, numerictags, NUMERIC_NTAGS);
+       return find_metadata(s, numerictags, DST_MAX_NUMERIC);
 }
 
 static int
@@ -491,7 +508,7 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex,
                /* Numeric metadata */
                tag = find_numericdata(DST_AS_STR(token));
                if (tag >= 0) {
-                       INSIST(tag < NUMERIC_NTAGS);
+                       INSIST(tag < DST_MAX_NUMERIC);
 
                        NEXTTOKEN(lex, opt | ISC_LEXOPT_NUMBER, &token);
                        if (token.type != isc_tokentype_number) {
@@ -506,7 +523,7 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex,
                /* Timing metadata */
                tag = find_timedata(DST_AS_STR(token));
                if (tag >= 0) {
-                       INSIST(tag < TIMING_NTAGS);
+                       INSIST(tag < DST_MAX_TIMES);
 
                        NEXTTOKEN(lex, opt, &token);
                        if (token.type != isc_tokentype_string) {
@@ -729,7 +746,7 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv,
 
        /* Add the metadata tags */
        if (major > 1 || (major == 1 && minor >= 3)) {
-               for (i = 0; i < NUMERIC_NTAGS; i++) {
+               for (i = 0; i < DST_MAX_NUMERIC; i++) {
                        result = dst_key_getnum(key, i, &value);
                        if (result != ISC_R_SUCCESS) {
                                continue;
@@ -738,7 +755,7 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv,
                                fprintf(fp, "%s %u\n", numerictags[i], value);
                        }
                }
-               for (i = 0; i < TIMING_NTAGS; i++) {
+               for (i = 0; i < DST_MAX_TIMES; i++) {
                        result = dst_key_gettime(key, i, &when);
                        if (result != ISC_R_SUCCESS) {
                                continue;
index ecd952e845c851a34f4d9d07ea1d2b3474809b2b..061369d50ca10055cd7c2656138ca2dbd9950f17 100644 (file)
@@ -138,46 +138,58 @@ typedef enum dst_algorithm {
 #define DST_TYPE_TEMPLATE 0x10000000
 
 /* Key timing metadata definitions */
-#define DST_TIME_CREATED     0
-#define DST_TIME_PUBLISH     1
-#define DST_TIME_ACTIVATE    2
-#define DST_TIME_REVOKE             3
-#define DST_TIME_INACTIVE    4
-#define DST_TIME_DELETE             5
-#define DST_TIME_DSPUBLISH   6
-#define DST_TIME_SYNCPUBLISH 7
-#define DST_TIME_SYNCDELETE  8
-#define DST_TIME_DNSKEY             9
-#define DST_TIME_ZRRSIG             10
-#define DST_TIME_KRRSIG             11
-#define DST_TIME_DS         12
-#define DST_TIME_DSDELETE    13
-#define DST_TIME_SIGPUBLISH  14
-#define DST_TIME_SIGDELETE   15
-#define DST_MAX_TIMES       15
+enum {
+       DST_TIME_CREATED = 0,
+       DST_TIME_PUBLISH = 1,
+       DST_TIME_ACTIVATE = 2,
+       DST_TIME_REVOKE = 3,
+       DST_TIME_INACTIVE = 4,
+       DST_TIME_DELETE = 5,
+       DST_TIME_DSPUBLISH = 6,
+       DST_TIME_SYNCPUBLISH = 7,
+       DST_TIME_SYNCDELETE = 8,
+       DST_TIME_DNSKEY = 9,
+       DST_TIME_ZRRSIG = 10,
+       DST_TIME_KRRSIG = 11,
+       DST_TIME_DS = 12,
+       DST_TIME_DSDELETE = 13,
+       DST_TIME_SIGPUBLISH = 14,
+       DST_TIME_SIGDELETE = 15,
+
+       DST_MAX_TIMES = 16 /* MUST BE LAST */
+};
 
 /* Numeric metadata definitions */
-#define DST_NUM_PREDECESSOR 0
-#define DST_NUM_SUCCESSOR   1
-#define DST_NUM_MAXTTL     2
-#define DST_NUM_ROLLPERIOD  3
-#define DST_NUM_LIFETIME    4
-#define DST_NUM_DSPUBCOUNT  5
-#define DST_NUM_DSDELCOUNT  6
-#define DST_MAX_NUMERIC            6
+enum {
+       DST_NUM_PREDECESSOR = 0,
+       DST_NUM_SUCCESSOR = 1,
+       DST_NUM_MAXTTL = 2,
+       DST_NUM_ROLLPERIOD = 3,
+       DST_NUM_LIFETIME = 4,
+       DST_NUM_DSPUBCOUNT = 5,
+       DST_NUM_DSDELCOUNT = 6,
+
+       DST_MAX_NUMERIC = 7 /* MUST BE LAST */
+};
 
 /* Boolean metadata definitions */
-#define DST_BOOL_KSK   0
-#define DST_BOOL_ZSK   1
-#define DST_MAX_BOOLEAN 1
+enum {
+       DST_BOOL_KSK = 0,
+       DST_BOOL_ZSK = 1,
+
+       DST_MAX_BOOLEAN = 2 /* MUST BE LAST */
+};
 
 /* Key state metadata definitions */
-#define DST_KEY_DNSKEY   0
-#define DST_KEY_ZRRSIG   1
-#define DST_KEY_KRRSIG   2
-#define DST_KEY_DS       3
-#define DST_KEY_GOAL     4
-#define DST_MAX_KEYSTATES 4
+enum {
+       DST_KEY_DNSKEY = 0,
+       DST_KEY_ZRRSIG = 1,
+       DST_KEY_KRRSIG = 2,
+       DST_KEY_DS = 3,
+       DST_KEY_GOAL = 4,
+
+       DST_MAX_KEYSTATES = 5 /* MUST BE LAST */
+};
 
 /*
  * Current format version number of the private key parser.
@@ -834,7 +846,7 @@ dst_key_getbool(const dst_key_t *key, int type, bool *valuep);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_BOOLEAN
+ *     "type" is smaller than DST_MAX_BOOLEAN
  *     "valuep" is not null.
  */
 
@@ -845,7 +857,7 @@ dst_key_setbool(dst_key_t *key, int type, bool value);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_BOOLEAN
+ *     "type" is smaller than DST_MAX_BOOLEAN
  */
 
 void
@@ -855,7 +867,7 @@ dst_key_unsetbool(dst_key_t *key, int type);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_BOOLEAN
+ *     "type" is smaller than DST_MAX_BOOLEAN
  */
 
 isc_result_t
@@ -865,7 +877,7 @@ dst_key_getnum(const dst_key_t *key, int type, uint32_t *valuep);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_NUMERIC
+ *     "type" is smaller than DST_MAX_NUMERIC
  *     "valuep" is not null.
  */
 
@@ -876,7 +888,7 @@ dst_key_setnum(dst_key_t *key, int type, uint32_t value);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_NUMERIC
+ *     "type" is smaller than DST_MAX_NUMERIC
  */
 
 void
@@ -886,7 +898,7 @@ dst_key_unsetnum(dst_key_t *key, int type);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_NUMERIC
+ *     "type" is smaller than DST_MAX_NUMERIC
  */
 
 isc_result_t
@@ -896,7 +908,7 @@ dst_key_gettime(const dst_key_t *key, int type, isc_stdtime_t *timep);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_TIMES
+ *     "type" is smaller than DST_MAX_TIMES
  *     "timep" is not null.
  */
 
@@ -907,7 +919,7 @@ dst_key_settime(dst_key_t *key, int type, isc_stdtime_t when);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_TIMES
+ *     "type" is smaller than DST_MAX_TIMES
  */
 
 void
@@ -917,7 +929,7 @@ dst_key_unsettime(dst_key_t *key, int type);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_TIMES
+ *     "type" is smaller than DST_MAX_TIMES
  */
 
 isc_result_t
@@ -927,7 +939,7 @@ dst_key_getstate(const dst_key_t *key, int type, dst_key_state_t *statep);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_KEYSTATES
+ *     "type" is smaller than DST_MAX_KEYSTATES
  *     "statep" is not null.
  */
 
@@ -939,7 +951,7 @@ dst_key_setstate(dst_key_t *key, int type, dst_key_state_t state);
  * Requires:
  *     "key" is a valid key.
  *     "state" is a valid state.
- *     "type" is no larger than DST_MAX_KEYSTATES
+ *     "type" is smaller than DST_MAX_KEYSTATES
  */
 
 void
@@ -949,7 +961,7 @@ dst_key_unsetstate(dst_key_t *key, int type);
  *
  * Requires:
  *     "key" is a valid key.
- *     "type" is no larger than DST_MAX_KEYSTATES
+ *     "type" is smaller than DST_MAX_KEYSTATES
  */
 
 isc_result_t
index 152c6016bb99e6d720c8df241a589d200a5812d8..81f689fe712b8b2c11e30b3f1fb680af434545bf 100644 (file)
 #define NA         DST_KEY_STATE_NA
 
 /* Quickly get key state timing metadata. */
-#define NUM_KEYSTATES (DST_MAX_KEYSTATES)
-static int keystatetimes[NUM_KEYSTATES] = { DST_TIME_DNSKEY, DST_TIME_ZRRSIG,
-                                           DST_TIME_KRRSIG, DST_TIME_DS };
+static int keystatetimes[] = { DST_TIME_DNSKEY, DST_TIME_ZRRSIG,
+                              DST_TIME_KRRSIG, DST_TIME_DS };
+#define NUM_KEYSTATES (int)ARRAY_SIZE(keystatetimes)
+
 /* Readable key state types and values. */
 static const char *keystatetags[NUM_KEYSTATES] = { "DNSKEY", "ZRRSIG", "KRRSIG",
                                                   "DS" };
-static const char *keystatestrings[4] = { "HIDDEN", "RUMOURED", "OMNIPRESENT",
-                                         "UNRETENTIVE" };
+static const char *keystatestrings[] = { "HIDDEN", "RUMOURED", "OMNIPRESENT",
+                                        "UNRETENTIVE" };
 
 static void
 log_key_overflow(dst_key_t *key, const char *what) {
index f918eee2089db0f8e543108edd5e892b60bdca20..f56b6b7e5314e1a33f3c224ca14e9fc872037645 100644 (file)
@@ -20568,7 +20568,7 @@ next_keyevent(dst_key_t *key, isc_stdtime_t *timep) {
 
        now = *timep;
 
-       for (i = 0; i <= DST_MAX_TIMES; i++) {
+       for (i = 0; i < DST_MAX_TIMES; i++) {
                result = dst_key_gettime(key, i, &event);
                if (result == ISC_R_SUCCESS && event > now &&
                    (then == 0 || event < then))