Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,15 @@
#define LTC_DER_CHAR_TO_INT
static LTC_INLINE int s_char_to_int(unsigned char x)
{
switch (x) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default: return 100;
}
if(x < '0' || '9' < x)
return 100;
return (int) x - '0';
}
#endif

#define DECODE_V(y, max) do {\
if (x + 2 > declen) return CRYPT_INVALID_PACKET; \
y = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
y = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
if (y >= max) return CRYPT_INVALID_PACKET; \
x += 2; \
} while(0)
Expand Down
27 changes: 9 additions & 18 deletions src/pk/asn1/der/utctime/der_decode_utctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
@file der_decode_utctime.c
ASN.1 DER, decode a UTCTIME, Tom St Denis
ASN.1 DER, decode a UTCTIME, Tom St Denis
*/

#ifdef LTC_DER
Expand All @@ -13,27 +13,18 @@
#define LTC_DER_CHAR_TO_INT
static LTC_INLINE int s_char_to_int(unsigned char x)
{
switch (x) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default: return 100;
}
if(x < '0' || '9' < x)
return 100;
return (int) x - '0';
}
#endif

#define DECODE_V(y, max) \
if (x + 2 > declen) return CRYPT_INVALID_PACKET; \
y = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
#define DECODE_V(y, max) do {\
if (x + 2 > declen) return CRYPT_INVALID_PACKET; \
y = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
if (y >= max) return CRYPT_INVALID_PACKET; \
x += 2;
x += 2; \
} while(0)

/**
Decodes a UTC time structure in DER format (reads all 6 valid encoding formats)
Expand Down