+ if (gnutls_x509_crt_get_fingerprint(cert, algo, digest, &digest_size) < 0)
+ len = 0;
+ }
+ else
+ {
+ gnutls_pubkey_t pubkey;
+ unsigned char *der_pubkey = NULL;
+ size_t der_pubkey_len = 0;
+
+ if (gnutls_pubkey_init(&pubkey) == GNUTLS_E_SUCCESS)
+ {
+ if (gnutls_pubkey_import_x509(pubkey, cert, 0) == GNUTLS_E_SUCCESS)
+ {
+ if (gnutls_pubkey_export(pubkey, GNUTLS_X509_FMT_DER, der_pubkey, &der_pubkey_len) == GNUTLS_E_SHORT_MEMORY_BUFFER)
+ {
+ der_pubkey = rb_malloc(der_pubkey_len);
+
+ if (gnutls_pubkey_export(pubkey, GNUTLS_X509_FMT_DER, der_pubkey, &der_pubkey_len) != GNUTLS_E_SUCCESS)
+ {
+ rb_free(der_pubkey);
+ der_pubkey = NULL;
+ }
+ }
+ }
+
+ gnutls_pubkey_deinit(pubkey);
+ }
+
+ if (der_pubkey)
+ {
+ if (gnutls_hash_fast(algo, der_pubkey, der_pubkey_len, digest) != 0)
+ len = 0;
+
+ rb_free(der_pubkey);
+ }
+ else
+ {
+ len = 0;
+ }