static int DSA_meth_set1_name (DSA_METHOD *meth, const char *name) { CK_RV rv; rv = _pkcs11h_mem_strdup ((void *)&meth->name, name); return rv == CKR_OK ? 1 : 0; }
CK_RV pkcs11h_certificate_deserializeCertificateId ( OUT pkcs11h_certificate_id_t * const p_certificate_id, IN const char * const sz ) { pkcs11h_certificate_id_t certificate_id = NULL; CK_RV rv = CKR_FUNCTION_FAILED; char *p = NULL; char *_sz = NULL; _PKCS11H_ASSERT (p_certificate_id!=NULL); _PKCS11H_ASSERT (sz!=NULL); *p_certificate_id = NULL; _PKCS11H_DEBUG ( PKCS11H_LOG_DEBUG2, "PKCS#11: pkcs11h_certificate_deserializeCertificateId entry p_certificate_id=%p, sz='%s'", (void *)p_certificate_id, sz ); if ( (rv = _pkcs11h_mem_strdup ( (void *)&_sz, sz )) != CKR_OK ) { goto cleanup; } p = _sz; if ((rv = _pkcs11h_certificate_newCertificateId (&certificate_id)) != CKR_OK) { goto cleanup; } if ((p = strrchr (_sz, '/')) == NULL) { rv = CKR_ATTRIBUTE_VALUE_INVALID; goto cleanup; } *p = '\x0'; p++; if ( (rv = pkcs11h_token_deserializeTokenId ( &certificate_id->token_id, _sz )) != CKR_OK ) { goto cleanup; } certificate_id->attrCKA_ID_size = strlen (p)/2; if ( (rv = _pkcs11h_mem_malloc ( (void *)&certificate_id->attrCKA_ID, certificate_id->attrCKA_ID_size) ) != CKR_OK || (rv = _pkcs11h_util_hexToBinary ( certificate_id->attrCKA_ID, p, &certificate_id->attrCKA_ID_size )) != CKR_OK ) { goto cleanup; } *p_certificate_id = certificate_id; certificate_id = NULL; rv = CKR_OK; cleanup: if (certificate_id != NULL) { pkcs11h_certificate_freeCertificateId (certificate_id); certificate_id = NULL; } if (_sz != NULL) { _pkcs11h_mem_free ((void *)&_sz); } _PKCS11H_DEBUG ( PKCS11H_LOG_DEBUG2, "PKCS#11: pkcs11h_certificate_deserializeCertificateId return rv=%lu-'%s'", rv, pkcs11h_getMessage (rv) ); return rv; }
CK_RV pkcs11h_token_deserializeTokenId ( OUT pkcs11h_token_id_t *p_token_id, IN const char * const sz ) { #define __PKCS11H_TARGETS_NUMBER 4 struct { char *p; size_t s; } targets[__PKCS11H_TARGETS_NUMBER]; pkcs11h_token_id_t token_id = NULL; char *p1 = NULL; char *_sz = NULL; int e; CK_RV rv = CKR_FUNCTION_FAILED; _PKCS11H_ASSERT (p_token_id!=NULL); _PKCS11H_ASSERT (sz!=NULL); _PKCS11H_DEBUG ( PKCS11H_LOG_DEBUG2, "PKCS#11: pkcs11h_token_deserializeTokenId entry p_token_id=%p, sz='%s'", (void *)p_token_id, sz ); *p_token_id = NULL; if ( (rv = _pkcs11h_mem_strdup ( (void *)&_sz, sz )) != CKR_OK ) { goto cleanup; } p1 = _sz; if ((rv = _pkcs11h_token_newTokenId (&token_id)) != CKR_OK) { goto cleanup; } targets[0].p = token_id->manufacturerID; targets[0].s = sizeof (token_id->manufacturerID); targets[1].p = token_id->model; targets[1].s = sizeof (token_id->model); targets[2].p = token_id->serialNumber; targets[2].s = sizeof (token_id->serialNumber); targets[3].p = token_id->label; targets[3].s = sizeof (token_id->label); for (e=0;e < __PKCS11H_TARGETS_NUMBER;e++) { size_t l; char *p2 = NULL; /* * Don't search for last * separator */ if (e != __PKCS11H_TARGETS_NUMBER-1) { p2 = strchr (p1, '/'); if (p2 == NULL) { rv = CKR_ATTRIBUTE_VALUE_INVALID; goto cleanup; } else { *p2 = '\x0'; } } if ( (rv = _pkcs11h_util_unescapeString ( NULL, p1, &l )) != CKR_OK ) { goto cleanup; } if (l > targets[e].s) { rv = CKR_ATTRIBUTE_VALUE_INVALID; goto cleanup; } l = targets[e].s; if ( (rv = _pkcs11h_util_unescapeString ( targets[e].p, p1, &l )) != CKR_OK ) { goto cleanup; } p1 = p2+1; } strncpy ( token_id->display, token_id->label, sizeof (token_id->display) ); *p_token_id = token_id; token_id = NULL; rv = CKR_OK; cleanup: if (_sz != NULL) { _pkcs11h_mem_free ((void *)&_sz); } if (token_id != NULL) { pkcs11h_token_freeTokenId (token_id); } _PKCS11H_DEBUG ( PKCS11H_LOG_DEBUG2, "PKCS#11: pkcs11h_token_deserializeTokenId return rv=%lu-'%s'", rv, pkcs11h_getMessage (rv) ); return rv; #undef __PKCS11H_TARGETS_NUMBER }