LCOV - code coverage report
Current view: top level - builds/gnutls/coverage/gnutls-git/lib - randomart.c (source / functions) Hit Total Coverage
Test: GnuTLS-3.6.14 Code Coverage Lines: 7 9 77.8 %
Date: 2020-10-30 04:50:48 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2001-2015 Free Software Foundation, Inc.
       3             :  * Copyright (C) 2015 Nikos Mavrogiannopoulos
       4             :  *
       5             :  * Author: Nikos Mavrogiannopoulos
       6             :  *
       7             :  * This file is part of GnuTLS.
       8             :  *
       9             :  * The GnuTLS is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public License
      11             :  * as published by the Free Software Foundation; either version 2.1 of
      12             :  * the License, or (at your option) any later version.
      13             :  *
      14             :  * This library is distributed in the hope that it will be useful, but
      15             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  *
      19             :  * You should have received a copy of the GNU Lesser General Public License
      20             :  * along with this program.  If not, see <https://www.gnu.org/licenses/>
      21             :  *
      22             :  */
      23             : 
      24             : #include "gnutls_int.h"
      25             : #include <extras/randomart.h>
      26             : 
      27             : /**
      28             :  * gnutls_random_art:
      29             :  * @type: The type of the random art (for now only %GNUTLS_RANDOM_ART_OPENSSH is supported)
      30             :  * @key_type: The type of the key (RSA, DSA etc.)
      31             :  * @key_size: The size of the key in bits
      32             :  * @fpr: The fingerprint of the key
      33             :  * @fpr_size: The size of the fingerprint
      34             :  * @art: The returned random art
      35             :  *
      36             :  * This function will convert a given fingerprint to an "artistic"
      37             :  * image. The returned image is allocated using gnutls_malloc(), is
      38             :  * null-terminated but art->size will not account the terminating null.
      39             :  *
      40             :  * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
      41             :  *   an error code is returned.
      42             :  *
      43             :  **/
      44           3 : int gnutls_random_art(gnutls_random_art_t type,
      45             :                       const char *key_type, unsigned int key_size,
      46             :                       void *fpr, size_t fpr_size, gnutls_datum_t * art)
      47             : {
      48           3 :         if (type != GNUTLS_RANDOM_ART_OPENSSH)
      49           0 :                 return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
      50             : 
      51           6 :         art->data =
      52           3 :             (void *) _gnutls_key_fingerprint_randomart(fpr, fpr_size,
      53             :                                                        key_type, key_size,
      54             :                                                        NULL);
      55           3 :         if (art->data == NULL)
      56           0 :                 return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
      57             : 
      58           3 :         art->size = strlen((char *) art->data);
      59             : 
      60           3 :         return 0;
      61             : }
      62             : 

Generated by: LCOV version 1.14