clearification of keysize descriptor stuff
authorbg <daniel.otte@rub.de>
Tue, 18 Sep 2012 15:18:55 +0000 (17:18 +0200)
committerbg <daniel.otte@rub.de>
Tue, 18 Sep 2012 15:18:55 +0000 (17:18 +0200)
bcal/keysize_descriptor.c

index 579ef56..20f5caf 100644 (file)
 #include <stdlib.h>
 #include "keysize_descriptor.h"
 
+#define KS8 ((uint8_t*)ks_desc)
 uint8_t is_valid_keysize_P(const void* ks_desc, uint16_t keysize){
        uint8_t type;
-       type = *((uint8_t*)ks_desc);
-       ks_desc = (uint8_t*)ks_desc + 1;
+       type = KS8[0];
+       ks_desc = KS8 + 1;
        if(type==KS_TYPE_TERMINATOR)
                return 0;
        if(type==KS_TYPE_LIST){
                uint8_t items;
                uint16_t item;
-               items = *((uint8_t*)ks_desc);
-               ks_desc = (uint8_t*)ks_desc + 1;
+               items = KS8[0];
+               ks_desc = KS8 + 1;
                while(items--){
-                       item = *((uint16_t*)ks_desc);
-                       ks_desc = (uint8_t*)ks_desc + 2;
+                       item = KS8[1] * 256 + KS8[0];
+                       ks_desc = KS8 + 2;
                        if(item==keysize)
                                return 1;
                }
-               ks_desc = (uint8_t*)ks_desc - 2;
+               ks_desc = KS8 - 2;
        }
        if(type==KS_TYPE_RANGE){
                uint16_t max, min;
-               min = *((uint16_t*)ks_desc);
+               min = KS8[1] * 256 + KS8[0];
                ks_desc = (uint8_t*)ks_desc + 2;
-               max = *((uint16_t*)ks_desc);
-               if(min<=keysize && keysize<=max)
+               max = KS8[1] * 256 + KS8[0];
+               if(min <= keysize && keysize <= max)
                        return 1;
        }
        if(type==KS_TYPE_ARG_RANGE){
                uint16_t max, min, dist, offset;
-               min = *((uint16_t*)ks_desc);
-               ks_desc = (uint8_t*)ks_desc + 2;
-               max = *((uint16_t*)ks_desc);
-               ks_desc = (uint8_t*)ks_desc + 2;
-               dist = *((uint16_t*)ks_desc);
-               ks_desc = (uint8_t*)ks_desc + 2;
-               offset = *((uint16_t*)ks_desc);
-               if(min<=keysize && keysize<=max && (keysize%dist==offset))
+               min     = KS8[1] * 256 + KS8[0];
+               max     = KS8[3] * 256 + KS8[2];
+               dist    = KS8[5] * 256 + KS8[4];
+               offset  = KS8[7] * 256 + KS8[6];
+               ks_desc = KS8 + 6;
+               if(min <= keysize && keysize <= max && (keysize % dist == offset))
                        return 1;
        }
        if(type>KS_TYPE_ARG_RANGE){
                /* bad error, you may insert a big warning message here */
                return 0;
        }
-       return is_valid_keysize_P((uint8_t*)ks_desc+1, keysize); /* search the next record */
+       return is_valid_keysize_P(KS8+1, keysize); /* search the next record */
 }
 
 uint16_t get_keysize(const void* ks_desc){