"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.8.3/src/knot/dnssec/kasp/keystate.c" (16 Jul 2019, 2094 Bytes) of package /linux/misc/dns/knot-2.8.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "keystate.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.7.6_vs_2.8.0.

    1 /*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15 */
   16 
   17 #include "knot/dnssec/kasp/keystate.h"
   18 
   19 key_state_t get_key_state(const knot_kasp_key_t *key, knot_time_t moment)
   20 {
   21     if (!key || moment <= 0) {
   22         return DNSSEC_KEY_STATE_INVALID;
   23     }
   24 
   25     const knot_kasp_key_timing_t *t = &key->timing;
   26 
   27     bool removed = (knot_time_cmp(t->remove, moment) <= 0);
   28     bool post_active = (knot_time_cmp(t->post_active, moment) <= 0);
   29     bool retired = (knot_time_cmp(t->retire, moment) <= 0);
   30     bool retire_active = (knot_time_cmp(t->retire_active, moment) <= 0);
   31     bool active = (knot_time_cmp(t->active, moment) <= 0);
   32     bool ready = (knot_time_cmp(t->ready, moment) <= 0);
   33     bool published = (knot_time_cmp(t->publish, moment) <= 0);
   34     bool pre_active = (knot_time_cmp(t->pre_active, moment) <= 0);
   35     bool created = (knot_time_cmp(t->created, moment) <= 0);
   36 
   37     if (removed) {
   38         return DNSSEC_KEY_STATE_REMOVED;
   39     }
   40     if (post_active) {
   41         if (retired) {
   42             return DNSSEC_KEY_STATE_INVALID;
   43         } else {
   44             return DNSSEC_KEY_STATE_POST_ACTIVE;
   45         }
   46     }
   47     if (retired) {
   48         return DNSSEC_KEY_STATE_RETIRED;
   49     }
   50     if (retire_active) {
   51         return DNSSEC_KEY_STATE_RETIRE_ACTIVE;
   52     }
   53     if (active) {
   54         return DNSSEC_KEY_STATE_ACTIVE;
   55     }
   56     if (ready) {
   57         return DNSSEC_KEY_STATE_READY;
   58     }
   59     if (published) {
   60         return DNSSEC_KEY_STATE_PUBLISHED;
   61     }
   62     if (pre_active) {
   63         return DNSSEC_KEY_STATE_PRE_ACTIVE;
   64     }
   65     if (created) {
   66         // don't care
   67     }
   68 
   69     return DNSSEC_KEY_STATE_INVALID;
   70 }