Blame lib/randomart.c

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