diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2014-05-17 09:46:24 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2014-05-17 09:47:29 +0200 |
commit | f9d9fde34a6c563b3f5b1b94796d14caa5acba5a (patch) | |
tree | 72022107548917fd056232f3aabcf3d365a807ed | |
parent | ecae6fd894ad140b3e099fa176f2d4b286caaf65 (diff) | |
download | gnutls-f9d9fde34a6c563b3f5b1b94796d14caa5acba5a.tar.gz |
gnutls_x509_crt_get_signature() will use the internal _gnutls_x509_get_signature().
That prevents unnecessary replication of its code.
-rw-r--r-- | lib/x509/x509.c | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/lib/x509/x509.c b/lib/x509/x509.c index aee162a668..f1f581a4e2 100644 --- a/lib/x509/x509.c +++ b/lib/x509/x509.c @@ -568,7 +568,7 @@ int gnutls_x509_crt_get_signature_algorithm(gnutls_x509_crt_t cert) * gnutls_x509_crt_get_signature: * @cert: should contain a #gnutls_x509_crt_t structure * @sig: a pointer where the signature part will be copied (may be null). - * @sizeof_sig: initially holds the size of @sig + * @sig_size: initially holds the size of @sig * * This function will extract the signature field of a certificate. * @@ -577,45 +577,28 @@ int gnutls_x509_crt_get_signature_algorithm(gnutls_x509_crt_t cert) **/ int gnutls_x509_crt_get_signature(gnutls_x509_crt_t cert, - char *sig, size_t * sizeof_sig) + char *sig, size_t * sig_size) { - int result; - unsigned int bits; - int len; - - if (cert == NULL) { - gnutls_assert(); - return GNUTLS_E_INVALID_REQUEST; - } - - len = 0; - result = asn1_read_value(cert->cert, "signature", NULL, &len); - if (result != ASN1_MEM_ERROR) { - gnutls_assert(); - return _gnutls_asn2err(result); - } - - bits = len; - if (bits % 8 != 0 || bits < 8) { - gnutls_assert(); - return GNUTLS_E_CERTIFICATE_ERROR; - } + gnutls_datum_t dsig = {NULL, 0}; + int ret; - len = bits / 8; + if (cert == NULL) + return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); - if (*sizeof_sig < (unsigned int) len) { - *sizeof_sig = len; - return GNUTLS_E_SHORT_MEMORY_BUFFER; - } + ret = _gnutls_x509_get_signature(cert->cert, "signature", &dsig); + if (ret < 0) + return gnutls_assert_val(ret); - result = asn1_read_value(cert->cert, "signature", sig, &len); - if (result != ASN1_SUCCESS) { + ret = _gnutls_copy_data(&dsig, (uint8_t*)sig, sig_size); + if (ret < 0) { gnutls_assert(); - return _gnutls_asn2err(result); + goto cleanup; } - *sizeof_sig = (unsigned)(len/8); - return 0; + ret = 0; + cleanup: + gnutls_free(dsig.data); + return ret; } /** |