Blame lib/randomart.c

Packit Service 4684c1
/*
Packit Service 4684c1
 * Copyright (C) 2001-2015 Free Software Foundation, Inc.
Packit Service 4684c1
 * Copyright (C) 2015 Nikos Mavrogiannopoulos
Packit Service 4684c1
 *
Packit Service 4684c1
 * Author: Nikos Mavrogiannopoulos
Packit Service 4684c1
 *
Packit Service 4684c1
 * This file is part of GnuTLS.
Packit Service 4684c1
 *
Packit Service 4684c1
 * The GnuTLS is free software; you can redistribute it and/or
Packit Service 4684c1
 * modify it under the terms of the GNU Lesser General Public License
Packit Service 4684c1
 * as published by the Free Software Foundation; either version 2.1 of
Packit Service 4684c1
 * the License, or (at your option) any later version.
Packit Service 4684c1
 *
Packit Service 4684c1
 * This library is distributed in the hope that it will be useful, but
Packit Service 4684c1
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4684c1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 4684c1
 * Lesser General Public License for more details.
Packit Service 4684c1
 *
Packit Service 4684c1
 * You should have received a copy of the GNU Lesser General Public License
Packit Service 4684c1
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
Packit Service 4684c1
 *
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
#include "gnutls_int.h"
Packit Service 4684c1
#include <extras/randomart.h>
Packit Service 4684c1
Packit Service 4684c1
/**
Packit Service 4684c1
 * gnutls_random_art:
Packit Service 4684c1
 * @type: The type of the random art (for now only %GNUTLS_RANDOM_ART_OPENSSH is supported)
Packit Service 4684c1
 * @key_type: The type of the key (RSA, DSA etc.)
Packit Service 4684c1
 * @key_size: The size of the key in bits
Packit Service 4684c1
 * @fpr: The fingerprint of the key
Packit Service 4684c1
 * @fpr_size: The size of the fingerprint
Packit Service 4684c1
 * @art: The returned random art
Packit Service 4684c1
 *
Packit Service 4684c1
 * This function will convert a given fingerprint to an "artistic"
Packit Service 4684c1
 * image. The returned image is allocated using gnutls_malloc(), is
Packit Service 4684c1
 * null-terminated but art->size will not account the terminating null.
Packit Service 4684c1
 *
Packit Service 4684c1
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
Packit Service 4684c1
 *   an error code is returned.
Packit Service 4684c1
 *
Packit Service 4684c1
 **/
Packit Service 4684c1
int gnutls_random_art(gnutls_random_art_t type,
Packit Service 4684c1
		      const char *key_type, unsigned int key_size,
Packit Service 4684c1
		      void *fpr, size_t fpr_size, gnutls_datum_t * art)
Packit Service 4684c1
{
Packit Service 4684c1
	if (type != GNUTLS_RANDOM_ART_OPENSSH)
Packit Service 4684c1
		return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
Packit Service 4684c1
Packit Service 4684c1
	art->data =
Packit Service 4684c1
	    (void *) _gnutls_key_fingerprint_randomart(fpr, fpr_size,
Packit Service 4684c1
						       key_type, key_size,
Packit Service 4684c1
						       NULL);
Packit Service 4684c1
	if (art->data == NULL)
Packit Service 4684c1
		return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
Packit Service 4684c1
Packit Service 4684c1
	art->size = strlen((char *) art->data);
Packit Service 4684c1
Packit Service 4684c1
	return 0;
Packit Service 4684c1
}
Packit Service 4684c1