LCOV - code coverage report
Current view: top level - lib/crypto - gnutls_error.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 0 56 0.0 %
Date: 2024-04-21 15:09:00 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2019      Andreas Schneider <asn@samba.org>
       3             :  *
       4             :  * This program is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 3 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * This program is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "includes.h"
      19             : #include "gnutls_helpers.h"
      20             : 
      21             : #include <gnutls/gnutls.h>
      22             : 
      23           0 : NTSTATUS _gnutls_error_to_ntstatus(int gnutls_rc,
      24             :                                    NTSTATUS blocked_status,
      25             :                                    const char *function,
      26             :                                    const char *location)
      27             : {
      28           0 :         NTSTATUS status;
      29             : 
      30           0 :         if (gnutls_rc == GNUTLS_E_SUCCESS) {
      31           0 :                 return NT_STATUS_OK;
      32             :         }
      33             : 
      34           0 :         switch (gnutls_rc) {
      35           0 :         case GNUTLS_E_UNWANTED_ALGORITHM:
      36           0 :                 status = blocked_status;
      37           0 :                 break;
      38           0 :         case GNUTLS_E_MEMORY_ERROR:
      39           0 :                 status = NT_STATUS_NO_MEMORY;
      40           0 :                 break;
      41           0 :         case GNUTLS_E_INVALID_REQUEST:
      42           0 :                 status = NT_STATUS_INVALID_VARIANT;
      43           0 :                 break;
      44           0 :         case GNUTLS_E_DECRYPTION_FAILED:
      45           0 :                 status = NT_STATUS_DECRYPTION_FAILED;
      46           0 :                 break;
      47           0 :         case GNUTLS_E_ENCRYPTION_FAILED:
      48           0 :                 status = NT_STATUS_ENCRYPTION_FAILED;
      49           0 :                 break;
      50           0 :         case GNUTLS_E_SHORT_MEMORY_BUFFER:
      51           0 :                 status = NT_STATUS_INVALID_PARAMETER;
      52           0 :                 break;
      53           0 :         case GNUTLS_E_BASE64_DECODING_ERROR:
      54             :         case GNUTLS_E_HASH_FAILED:
      55             :         case GNUTLS_E_LIB_IN_ERROR_STATE:
      56             :         case GNUTLS_E_INTERNAL_ERROR:
      57             :         default:
      58           0 :                 status = NT_STATUS_INTERNAL_ERROR;
      59           0 :                 break;
      60             :         }
      61             : 
      62           0 :         D_WARNING("%s: GNUTLS ERROR: %s, NTSTATUS: %s at %s\n",
      63             :                   function,
      64             :                   gnutls_strerror_name(gnutls_rc),
      65             :                   nt_errstr(status),
      66             :                   location);
      67             : 
      68           0 :         return status;
      69             : }
      70             : 
      71           0 : WERROR _gnutls_error_to_werror(int gnutls_rc,
      72             :                                WERROR blocked_werr,
      73             :                                const char *function,
      74             :                                const char *location)
      75             : {
      76           0 :         WERROR werr;
      77             : 
      78           0 :         if (gnutls_rc == GNUTLS_E_SUCCESS) {
      79           0 :                 return WERR_OK;
      80             :         }
      81             : 
      82           0 :         switch (gnutls_rc) {
      83           0 :         case GNUTLS_E_UNWANTED_ALGORITHM:
      84           0 :                 werr = blocked_werr;
      85           0 :                 break;
      86           0 :         case GNUTLS_E_MEMORY_ERROR:
      87           0 :                 werr = WERR_NOT_ENOUGH_MEMORY;
      88           0 :                 break;
      89           0 :         case GNUTLS_E_INVALID_REQUEST:
      90           0 :                 werr = WERR_INVALID_VARIANT;
      91           0 :                 break;
      92           0 :         case GNUTLS_E_DECRYPTION_FAILED:
      93           0 :                 werr = WERR_DECRYPTION_FAILED;
      94           0 :                 break;
      95           0 :         case GNUTLS_E_ENCRYPTION_FAILED:
      96           0 :                 werr = WERR_ENCRYPTION_FAILED;
      97           0 :                 break;
      98           0 :         case GNUTLS_E_SHORT_MEMORY_BUFFER:
      99           0 :                 werr = WERR_INVALID_PARAMETER;
     100           0 :                 break;
     101           0 :         case GNUTLS_E_BASE64_DECODING_ERROR:
     102             :         case GNUTLS_E_HASH_FAILED:
     103             :         case GNUTLS_E_LIB_IN_ERROR_STATE:
     104             :         case GNUTLS_E_INTERNAL_ERROR:
     105             :         default:
     106           0 :                 werr = WERR_INTERNAL_ERROR;
     107           0 :                 break;
     108             :         }
     109             : 
     110           0 :         D_WARNING("%s: GNUTLS ERROR: %s, WERROR: %s at %s\n",
     111             :                   function,
     112             :                   gnutls_strerror_name(gnutls_rc),
     113             :                   win_errstr(werr),
     114             :                   location);
     115             : 
     116           0 :         return werr;
     117             : }

Generated by: LCOV version 1.14