miniroon

Simplistic macaroon-based authorization for Unix systems
git clone https://ccx.te2000.cz/git/miniroon
Log | Files | Refs

miniroon_caveat_name_perfhash.c (3442B)


      1 #include "miniroon_caveat_name_perfhash.h"
      2 static enum miniroon_caveat_name_perfhash_key miniroon_caveat_name_perfhash_hash6(const char *string)
      3 {
      4     switch(string[0]) {
      5     case 'e':
      6         switch(string[1]) {
      7         case 'n':
      8             switch(string[2]) {
      9             case 'v':
     10                 switch(string[3]) {
     11                 case '-':
     12                     switch(string[4]) {
     13                     case 'i':
     14                         switch(string[5]) {
     15                         case 's':
     16                             return MINIROON_CAVEAT_ENV_IS;
     17                         }
     18                         break;
     19                     case 'r':
     20                         switch(string[5]) {
     21                         case 'e':
     22                             return MINIROON_CAVEAT_ENV_REGMATCH;
     23                         }
     24                     }
     25                 }
     26             }
     27         }
     28     }
     29     return MINIROON_CAVEAT_UNDEFINED;
     30 }
     31 static enum miniroon_caveat_name_perfhash_key miniroon_caveat_name_perfhash_hash8(const char *string)
     32 {
     33     switch(string[0]) {
     34     case 'e':
     35         switch(string[1]) {
     36         case 'n':
     37             switch(string[2]) {
     38             case 'v':
     39                 switch(string[3]) {
     40                 case '-':
     41                     switch(string[4]) {
     42                     case 'g':
     43                         switch(string[5]) {
     44                         case 'l':
     45                             switch(string[6]) {
     46                             case 'o':
     47                                 switch(string[7]) {
     48                                 case 'b':
     49                                     return MINIROON_CAVEAT_ENV_FNMATCH;
     50                                 }
     51                             }
     52                         }
     53                     }
     54                 }
     55             }
     56         }
     57     }
     58     return MINIROON_CAVEAT_UNDEFINED;
     59 }
     60 static enum miniroon_caveat_name_perfhash_key miniroon_caveat_name_perfhash_hash10(const char *string)
     61 {
     62     switch(string[0]) {
     63     case 'e':
     64         switch(string[1]) {
     65         case 'n':
     66             switch(string[2]) {
     67             case 'v':
     68                 switch(string[3]) {
     69                 case '-':
     70                     switch(string[4]) {
     71                     case 'a':
     72                         switch(string[5]) {
     73                         case 'b':
     74                             switch(string[6]) {
     75                             case 's':
     76                                 switch(string[7]) {
     77                                 case 'e':
     78                                     switch(string[8]) {
     79                                     case 'n':
     80                                         switch(string[9]) {
     81                                         case 't':
     82                                             return MINIROON_CAVEAT_ENV_ABSENT;
     83                                         }
     84                                     }
     85                                 }
     86                             }
     87                         }
     88                     }
     89                 }
     90             }
     91         }
     92     }
     93     return MINIROON_CAVEAT_UNDEFINED;
     94 }
     95 enum miniroon_caveat_name_perfhash_key miniroon_caveat_name_perfhash_hash(const char *string, size_t length)
     96 {
     97     switch (length) {
     98     case 6:
     99         return miniroon_caveat_name_perfhash_hash6(string);
    100     case 8:
    101         return miniroon_caveat_name_perfhash_hash8(string);
    102     case 10:
    103         return miniroon_caveat_name_perfhash_hash10(string);
    104     default:
    105         return MINIROON_CAVEAT_UNDEFINED;
    106     }
    107 }