Browse Source

change the ASN1 type to be a typedef

replace all 'default' cases in the switch statements
Steffen Jaeckel 11 years ago
parent
commit
6bba3a2a70

+ 3 - 3
src/headers/tomcrypt_pk.h

@@ -435,7 +435,7 @@ int dsa_shared_secret(void          *private_key, void *base,
 #ifdef LTC_DER
 /* DER handling */
 
-enum {
+typedef enum ltc_asn1_type_ {
  LTC_ASN1_EOL,
  LTC_ASN1_BOOLEAN,
  LTC_ASN1_INTEGER,
@@ -455,12 +455,12 @@ enum {
  LTC_ASN1_RAW_BIT_STRING,
  LTC_ASN1_TELETEX_STRING,
  LTC_ASN1_CONSTRUCTED,
-};
+} ltc_asn1_type;
 
 /** A LTC ASN.1 list type */
 typedef struct ltc_asn1_list_ {
    /** The LTC ASN.1 enumerated type identifier */
-   int           type;
+   ltc_asn1_type type;
    /** The data to encode or place for decoding */
    void         *data;
    /** The size of the input or resulting output */

+ 3 - 1
src/pk/asn1/der/choice/der_decode_choice.c

@@ -198,7 +198,9 @@ int der_decode_choice(const unsigned char *in,   unsigned long *inlen,
                }
                break;
 
-           default:
+           case LTC_ASN1_CHOICE:
+           case LTC_ASN1_CONSTRUCTED:
+           case LTC_ASN1_EOL:
                return CRYPT_INVALID_ARG;
        }
    }

+ 4 - 2
src/pk/asn1/der/sequence/der_decode_sequence_ex.c

@@ -31,7 +31,8 @@
 int der_decode_sequence_ex(const unsigned char *in, unsigned long  inlen,
                            ltc_asn1_list *list,     unsigned long  outlen, int ordered)
 {
-   int           err, type, i;
+   int           err, i;
+   ltc_asn1_type type;
    unsigned long size, x, y, z, blksize;
    void          *data;
 
@@ -282,7 +283,8 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long  inlen,
                }
                break;
 
-           default:
+           case LTC_ASN1_CONSTRUCTED:
+           case LTC_ASN1_EOL:
                err = CRYPT_INVALID_ARG;
                goto LBL_ERR;
        }

+ 9 - 10
src/pk/asn1/der/sequence/der_decode_sequence_multi.c

@@ -28,7 +28,8 @@
 */
 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
 {
-   int           err, type;
+   int           err;
+   ltc_asn1_type type;
    unsigned long size, x;
    void          *data;
    va_list       args;
@@ -40,7 +41,7 @@ int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
    va_start(args, inlen);
    x = 0;
    for (;;) {
-       type = va_arg(args, int);
+       type = va_arg(args, ltc_asn1_type);
        size = va_arg(args, unsigned long);
        data = va_arg(args, void*);
 
@@ -69,7 +70,8 @@ int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
                 ++x;
                 break;
 
-           default:
+           case LTC_ASN1_EOL:
+           case LTC_ASN1_CONSTRUCTED:
                va_end(args);
                return CRYPT_INVALID_ARG;
        }
@@ -90,7 +92,7 @@ int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
    va_start(args, inlen);
    x = 0;
    for (;;) {
-       type = va_arg(args, int);
+       type = va_arg(args, ltc_asn1_type);
        size = va_arg(args, unsigned long);
        data = va_arg(args, void*);
 
@@ -118,17 +120,14 @@ int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
            case LTC_ASN1_TELETEX_STRING:
                 LTC_SET_ASN1(list, x++, type, data, size);
                 break;
-
-           default:
-               va_end(args);
-               err = CRYPT_INVALID_ARG;
-               goto LBL_ERR;
+           case LTC_ASN1_EOL:
+           case LTC_ASN1_CONSTRUCTED:
+                break;
        }
    }
    va_end(args);
 
    err = der_decode_sequence(in, inlen, list, x);
-LBL_ERR:
    XFREE(list);
    return err;
 }

+ 10 - 3
src/pk/asn1/der/sequence/der_encode_sequence_ex.c

@@ -31,7 +31,8 @@
 int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
                            unsigned char *out,  unsigned long *outlen, int type_of)
 {
-   int           err, type;
+   int           err;
+   ltc_asn1_type type;
    unsigned long size, x, y, z, i;
    void          *data;
 
@@ -135,7 +136,10 @@ int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
                y += x;
                break;
 
-           default:
+           case LTC_ASN1_CHOICE:
+           case LTC_ASN1_CONSTRUCTED:
+           case LTC_ASN1_EOL:
+           case LTC_ASN1_TELETEX_STRING:
                err = CRYPT_INVALID_ARG;
                goto LBL_ERR;
        }
@@ -330,7 +334,10 @@ int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
                *outlen -= z;
                break;
 
-           default:
+           case LTC_ASN1_CHOICE:
+           case LTC_ASN1_CONSTRUCTED:
+           case LTC_ASN1_EOL:
+           case LTC_ASN1_TELETEX_STRING:
                err = CRYPT_INVALID_ARG;
                goto LBL_ERR;
        }

+ 12 - 5
src/pk/asn1/der/sequence/der_encode_sequence_multi.c

@@ -28,7 +28,8 @@
 */
 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
 {
-   int           err, type;
+   int           err;
+   ltc_asn1_type type;
    unsigned long size, x;
    void          *data;
    va_list       args;
@@ -41,7 +42,7 @@ int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
    va_start(args, outlen);
    x = 0;
    for (;;) {
-       type = va_arg(args, int);
+       type = va_arg(args, ltc_asn1_type);
        size = va_arg(args, unsigned long);
        data = va_arg(args, void*);
 
@@ -68,7 +69,10 @@ int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
                 ++x;
                 break;
 
-           default:
+           case LTC_ASN1_CHOICE:
+           case LTC_ASN1_CONSTRUCTED:
+           case LTC_ASN1_EOL:
+           case LTC_ASN1_TELETEX_STRING:
                va_end(args);
                return CRYPT_INVALID_ARG;
        }
@@ -89,7 +93,7 @@ int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
    va_start(args, outlen);
    x = 0;
    for (;;) {
-       type = va_arg(args, int);
+       type = va_arg(args, ltc_asn1_type);
        size = va_arg(args, unsigned long);
        data = va_arg(args, void*);
 
@@ -116,7 +120,10 @@ int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
                 LTC_SET_ASN1(list, x++, type, data, size);
                 break;
 
-           default:
+           case LTC_ASN1_CHOICE:
+           case LTC_ASN1_CONSTRUCTED:
+           case LTC_ASN1_EOL:
+           case LTC_ASN1_TELETEX_STRING:
                va_end(args);
                err = CRYPT_INVALID_ARG;
                goto LBL_ERR;