The example below searches all attributes of a personality given by its name pers_name for an X.509 DeviceIdentity certificate.
- bool b_loop_attr = true;
- gta_enum_handle_t h_enum_attr = GTA_HANDLE_ENUM_FIRST;
- while (b_loop_attr) {
- char attr_name[STR_LEN_MAX];
- char attr_type[STR_LEN_MAX];
- myio_obufstream_t ostream_attr_name = { 0 };
- myio_obufstream_t ostream_attr_type = { 0 };
- myio_open_obufstream(&ostream_attr_name, attr_name,
- sizeof(attr_name), &errinfo);
- myio_open_obufstream(&ostream_attr_type, attr_type,
- sizeof(attr_type), &errinfo);
- if (gta_personality_attributes_enumerate(h_inst,
- pers_name,
- h_enum_attr,
- (gtaio_ostream_t *)&ostream_attr_name,
- (gtaio_ostream_t *)&ostream_attr_type,
- &errinfo)) {
- /* Get the attribute holding the
- DeviceIdentity Certificate */
- if (0 == strncmp(attr_type,
- "ch.iec.30168.trustlist.certificate.self.x509",
- STR_LEN_MAX)) {
- h_ctx = gta_context_open(h_inst,
- pers_name,
- "org.opcfoundation.ECC-nistP256",
- &errinfo);
- /* get application certificate */
- char devid_cert[CERT_SIZE_MAX];
- myio_obufstream_t ostream_devid_cert = { 0 };
- myio_open_obufstream(&ostream_devid_cert,
- devid_cert, sizeof(devid_cert), &errinfo);
- gta_personality_get_attribute(h_ctx,
- attr_name, (gtaio_ostream_t *)&ostream_devid_cert,
- &errinfo);
- /* ... make use of this DeviceIdentity Cerficate
- (e.g., add it to a list) ... */
- gta_context_close(h_ctx, &errinfo);
- }
- }
- else {
- b_loop_attr = false;
- }
- myio_close_obufstream(&ostream_attr_name, &errinfo);
- myio_close_obufstream(&ostream_attr_type, &errinfo);
- }