
if (module_path) {
  ret = gnutls_pkcs11_init(GNUTLS_PKCS11_FLAG_MANUAL, NULL);
  if (ret < 0) {
    fprintf(stderr, "error in %d: %s\n", __LINE__, gnutls_strerror(ret));
    exit(1);
  }

  ret = gnutls_pkcs11_add_provider(module_path, NULL);
  if (ret < 0) {
    fprintf(stderr, "error in %d: %s\n", __LINE__, gnutls_strerror(ret));
    exit(1);
  }
}

if (key_pass)
  gnutls_pkcs11_set_pin_function(pin_function, key_pass);

ret = gnutls_privkey_init(&private_key);
if (ret < 0) {
  fprintf(stderr, "error in %d: %s\n", __LINE__, gnutls_strerror(ret));
  exit(1);
}

ret = gnutls_privkey_import_url(private_key, private_key_name, 0);
if (ret < 0) {
  fprintf(stderr, "error in %d: %s\n", __LINE__, gnutls_strerror(ret));
  exit(1);
}

ret = gnutls_privkey_sign_data(private_key, GNUTLS_DIG_SHA256, 0,
                               &testdata, &signature);
if (ret < 0) {
  fprintf(stderr, "error in %d: %s\n", __LINE__, gnutls_strerror(ret));
  exit(1);
}

gnutls_privkey_deinit(private_key);
gnutls_free(signature.data);

