cfindfield Function (ROM Call 0x12A)

cert.h

short cfindfield (CFILE *context, unsigned short FieldID, CERT_FIELD *dest);

Finds a matching field from a context.

cfindfield searches a file associated with the file context pointed to by context for a field which has field ID number equal to FieldID (length bits should be set to 0). If such field is found, cfindfield fills the field descriptor structure pointed to by dest and returns TRUE, else returns FALSE.

cfindfield is used often in TIOS to access particular data in a certificate file. Usually, function copensub is called immediately after cfindfield to get access to the content of the field. If the field contains subfields, this procedure may be repeated several times if necessary.

As an illustration of layout of certificate files, the layout of certificate files used in TIOS is given below. First, the field ID number is shown, then the short description of the field follows. Indentation shows that a particular field is a subfield of the field with smaller indentation.

As it is not possible to access the certificate part of Flash ROM directly, ecxept from the Base Code part of TIOS (this area of ROM is read-protected), the usuall method for reading certificates is to call FL_getCert first. This function will copy all data from the certificate area which may be shown to the public into the RAM, so the certificate can be read later from the RAM. For example, if you need to access the certificate data which shows the name of the author of an Flash application (assuming that such data is present in the certificate), the usual procedure is:
HANDLE handle;
unsigned long size;
CFILE context;
CERT_FIELD field;
...
FL_getCert (&handle, &size, FALSE);
copen (&context, HeapDeref (handle), size);
cfindfield (&context, 0x300, &field);
copensub (&context, &field);
cfindfield (&context, 0x500, &field);
copensub (&context, &field);
cfindfield (&context, 0x510, &field);
copensub (&context, &field);
After this, context.Pos will point to the author name. Alternatively, you can pick the name character-by-character using cgetc. If any of calls to cfindfield functions fail (i.e. return FALSE), then such data are not present in the certificate area.


Uses: cread
Used by: AB_prodid, AB_prodname, ROM Call 0x504