introduced ASN1_EXIT command in ASN.1 object syntax definition

This commit is contained in:
Andreas Steffen
2008-04-28 16:00:52 +00:00
parent 63cdbca211
commit 460025e253
13 changed files with 178 additions and 229 deletions
+11 -12
View File
@@ -453,11 +453,11 @@ bool asn1_parse_simple_object(chunk_t *object, asn1_t type, u_int level, const c
static const asn1Object_t algorithmIdentifierObjects[] = {
{ 0, "algorithmIdentifier", ASN1_SEQUENCE, ASN1_NONE }, /* 0 */
{ 1, "algorithm", ASN1_OID, ASN1_BODY }, /* 1 */
{ 1, "parameters", ASN1_EOC, ASN1_RAW } /* 2 */
{ 1, "parameters", ASN1_EOC, ASN1_RAW }, /* 2 */
{ 0, "exit", ASN1_EOC, ASN1_EXIT }
};
#define ALGORITHM_ID_ALG 1
#define ALGORITHM_ID_PARAMETERS 2
#define ALGORITHM_ID_ROOF 3
#define ALGORITHM_ID_ALG 1
#define ALGORITHM_ID_PARAMETERS 2
/*
* Defined in header
@@ -469,8 +469,7 @@ int asn1_parse_algorithmIdentifier(chunk_t blob, int level0, chunk_t *parameters
int objectID;
int alg = OID_UNKNOWN;
parser = asn1_parser_create(algorithmIdentifierObjects, ALGORITHM_ID_ROOF,
blob);
parser = asn1_parser_create(algorithmIdentifierObjects, blob);
parser->set_top_level(parser, level0);
while (parser->iterate(parser, &objectID, &object))
@@ -682,14 +681,14 @@ chunk_t asn1_wrap(asn1_t type, const char *mode, ...)
* ASN.1 definition of time
*/
static const asn1Object_t timeObjects[] = {
{ 0, "utcTime", ASN1_UTCTIME, ASN1_OPT|ASN1_BODY }, /* 0 */
{ 0, "end opt", ASN1_EOC, ASN1_END }, /* 1 */
{ 0, "generalizeTime",ASN1_GENERALIZEDTIME, ASN1_OPT|ASN1_BODY }, /* 2 */
{ 0, "end opt", ASN1_EOC, ASN1_END } /* 3 */
{ 0, "utcTime", ASN1_UTCTIME, ASN1_OPT|ASN1_BODY }, /* 0 */
{ 0, "end opt", ASN1_EOC, ASN1_END }, /* 1 */
{ 0, "generalizeTime", ASN1_GENERALIZEDTIME, ASN1_OPT|ASN1_BODY }, /* 2 */
{ 0, "end opt", ASN1_EOC, ASN1_END }, /* 3 */
{ 0, "exit", ASN1_EOC, ASN1_EXIT }
};
#define TIME_UTC 0
#define TIME_GENERALIZED 2
#define TIME_ROOF 4
/**
* extracts and converts a UTCTIME or GENERALIZEDTIME object
@@ -701,7 +700,7 @@ time_t asn1_parse_time(chunk_t blob, int level0)
int objectID;
time_t utc_time = 0;
parser= asn1_parser_create(timeObjects, TIME_ROOF, blob);
parser= asn1_parser_create(timeObjects, blob);
parser->set_top_level(parser, level0);
while (parser->iterate(parser, &objectID, &object))
+5 -9
View File
@@ -45,11 +45,6 @@ struct private_asn1_parser_t {
*/
asn1Object_t const *objects;
/**
* Total number of syntax definition lines
*/
int roof;
/**
* Current syntax definition line
*/
@@ -98,12 +93,14 @@ static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
*object = chunk_empty;
/* Advance to the next object syntax definition line */
obj = this->objects[++(this->line)];
/* Terminate if the end of the object syntax definition has been reached */
if (++(this->line) >= this->roof)
if (obj.flags & ASN1_EXIT)
{
return FALSE;
}
obj = this->objects[this->line];
if (obj.flags & ASN1_END) /* end of loop or option found */
{
@@ -284,7 +281,7 @@ static void destroy(private_asn1_parser_t *this)
/**
* Defined in header.
*/
asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, int roof, chunk_t blob)
asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, chunk_t blob)
{
private_asn1_parser_t *this = malloc_thing(private_asn1_parser_t);
@@ -292,7 +289,6 @@ asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, int roof, chunk_t
this->objects = objects;
this->blobs[0] = blob;
this->line = -1;
this->roof = roof;
this->success = TRUE;
this->public.iterate = (bool (*)(asn1_parser_t*, int*, chunk_t*))iterate;
+2 -2
View File
@@ -40,6 +40,7 @@
#define ASN1_OBJ 0x10
#define ASN1_BODY 0x20
#define ASN1_RAW 0x40
#define ASN1_EXIT 0x80
typedef struct asn1Object_t asn1Object_t;
@@ -110,10 +111,9 @@ struct asn1_parser_t {
* Create an ASN.1 parser
*
* @param objects syntax definition of the ASN.1 object to be parsed
* @param roof number of syntax definition lines
* @param blob ASN.1 coded binary blob
* @return ASN.1 context
*/
asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, int roof, chunk_t blob);
asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, chunk_t blob);
#endif /* ASN1_PARSER_H_ @}*/