LCOV - code coverage report
Current view: top level - gcr - gcr-gnupg-util.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 27 0.0 %
Date: 2022-09-04 10:20:22 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 18 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2011 Collabora Ltd.
       3                 :            :  *
       4                 :            :  * This program is free software; you can redistribute it and/or modify
       5                 :            :  * it under the terms of the GNU Lesser General Public License as
       6                 :            :  * published by the Free Software Foundation; either version 2.1 of
       7                 :            :  * the License, or (at your option) any later version.
       8                 :            :  *
       9                 :            :  * This program is distributed in the hope that it will be useful, but
      10                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      11                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12                 :            :  * Lesser General Public License for more details.
      13                 :            :  *
      14                 :            :  * You should have received a copy of the GNU Lesser General Public
      15                 :            :  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
      16                 :            :  *
      17                 :            :  * Author: Stef Walter <stefw@collabora.co.uk>
      18                 :            :  */
      19                 :            : 
      20                 :            : #include "config.h"
      21                 :            : 
      22                 :            : #include "egg/egg-hex.h"
      23                 :            : 
      24                 :            : #include "gcr-gnupg-util.h"
      25                 :            : 
      26                 :            : #include <gcrypt.h>
      27                 :            : 
      28                 :            : /**
      29                 :            :  * _gcr_gnupg_build_xa1_record:
      30                 :            :  * @meta: Status metadata record about the attribute data.
      31                 :            :  * @attribute: Pointer to attribute data.
      32                 :            :  * @n_attribute: Length of attribute data.
      33                 :            :  *
      34                 :            :  * Build a record for attribute data. We use this records to convert attribute
      35                 :            :  * data into something we can keep with an array of GcrRecord.
      36                 :            :  *
      37                 :            :  * Returns: (transfer full): The newly allocated record.
      38                 :            :  */
      39                 :            : GcrRecord*
      40                 :          0 : _gcr_gnupg_build_xa1_record (GcrRecord *meta, gpointer attribute,
      41                 :            :                              gsize n_attribute)
      42                 :            : {
      43                 :            :         gchar hash[20];
      44                 :            :         gchar *hex;
      45                 :          0 :         gchar status = 0;
      46                 :            :         GcrRecord *record;
      47                 :            :         guint flags, type;
      48                 :            :         const gchar *created, *expiry;
      49                 :            : 
      50         [ #  # ]:          0 :         g_return_val_if_fail (meta, NULL);
      51                 :            : 
      52                 :          0 :         record = _gcr_record_new (GCR_RECORD_SCHEMA_XA1, GCR_RECORD_XA1_MAX, ':');
      53                 :            : 
      54                 :          0 :         gcry_md_hash_buffer (GCRY_MD_RMD160, hash, attribute, n_attribute);
      55                 :          0 :         hex = egg_hex_encode_full (hash, sizeof (hash), TRUE, NULL, 1);
      56                 :          0 :         _gcr_record_take_raw (record, GCR_RECORD_XA1_FINGERPRINT, hex);
      57                 :            : 
      58         [ #  # ]:          0 :         if (!_gcr_record_get_uint (meta, GCR_RECORD_ATTRIBUTE_FLAGS, &flags))
      59                 :          0 :                 flags = 0;
      60                 :            : 
      61         [ #  # ]:          0 :         if (_gcr_record_get_uint (meta, GCR_RECORD_ATTRIBUTE_TYPE, &type))
      62                 :          0 :                 _gcr_record_set_uint (record, GCR_RECORD_XA1_TYPE, type);
      63                 :            : 
      64                 :          0 :         created = _gcr_record_get_raw (meta, GCR_RECORD_ATTRIBUTE_TIMESTAMP);
      65         [ #  # ]:          0 :         if (created == NULL)
      66                 :          0 :                 _gcr_record_set_raw (record, GCR_RECORD_XA1_TIMESTAMP, created);
      67                 :            : 
      68                 :          0 :         expiry = _gcr_record_get_raw (meta, GCR_RECORD_ATTRIBUTE_EXPIRY);
      69         [ #  # ]:          0 :         if (expiry != NULL)
      70                 :          0 :                 _gcr_record_set_raw (record, GCR_RECORD_XA1_EXPIRY, expiry);
      71                 :            : 
      72                 :            :         /* These values are from gnupg doc/DETAILS */
      73         [ #  # ]:          0 :         if (flags & 0x02)
      74                 :          0 :                 status = 'r';
      75         [ #  # ]:          0 :         else if (flags & 0x04)
      76                 :          0 :                 status = 'e';
      77         [ #  # ]:          0 :         else if (flags & 0x01)
      78                 :          0 :                 status = 'P';
      79         [ #  # ]:          0 :         if (status != 0)
      80                 :          0 :                 _gcr_record_set_char (record, GCR_RECORD_XA1_TRUST, status);
      81                 :            : 
      82                 :          0 :         _gcr_record_set_base64 (record, GCR_RECORD_XA1_DATA, attribute, n_attribute);
      83                 :            : 
      84                 :          0 :         return record;
      85                 :            : }

Generated by: LCOV version 1.14