LCOV - code coverage report
Current view: top level - egg - egg-oid.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 28 28
Test Date: 2024-05-07 18:02:03 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
       2              : /* egg-oid.c - OID helper routines
       3              : 
       4              :    Copyright (C) 2007 Stefan Walter
       5              : 
       6              :    The Gnome Keyring Library is free software; you can redistribute it and/or
       7              :    modify it under the terms of the GNU Library General Public License as
       8              :    published by the Free Software Foundation; either version 2 of the
       9              :    License, or (at your option) any later version.
      10              : 
      11              :    The Gnome Keyring Library is distributed in the hope that it will be useful,
      12              :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14              :    Library General Public License for more details.
      15              : 
      16              :    You should have received a copy of the GNU Library General Public
      17              :    License along with the Gnome Library; see the file COPYING.LIB.  If not,
      18              :    <http://www.gnu.org/licenses/>.
      19              : 
      20              :    Author: Stef Walter <stef@memberwebs.com>
      21              : */
      22              : 
      23              : #include "config.h"
      24              : 
      25              : #include "egg-oid.h"
      26              : 
      27              : #include <string.h>
      28              : 
      29              : #include <glib/gi18n-lib.h>
      30              : 
      31              : typedef struct _OidInfo {
      32              :         GQuark oid;
      33              :         const gchar *oidstr;
      34              :         const gchar *attr;
      35              :         const gchar *description;
      36              :         guint flags;
      37              : } OidInfo;
      38              : 
      39              : static OidInfo oid_info[] = {
      40              :         { 0, "0.9.2342.19200300.100.1.25", "DC", N_("Domain Component"), 
      41              :                 EGG_OID_PRINTABLE },
      42              :         { 0, "0.9.2342.19200300.100.1.1", "UID", N_("User ID"), 
      43              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      44              : 
      45              :         { 0, "1.2.840.113549.1.9.1", "EMAIL", N_("Email Address"),
      46              :                 EGG_OID_PRINTABLE },
      47              :         { 0, "1.2.840.113549.1.9.7", NULL, NULL, 
      48              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      49              :                 
      50              :         { 0, "1.2.840.113549.1.9.20", NULL, NULL, 
      51              :                 EGG_OID_PRINTABLE },
      52              :         
      53              :         { 0, "1.3.6.1.5.5.7.9.1", "dateOfBirth", N_("Date of Birth"), 
      54              :                 EGG_OID_PRINTABLE },
      55              :         { 0, "1.3.6.1.5.5.7.9.2", "placeOfBirth", N_("Place of Birth"), 
      56              :                 EGG_OID_PRINTABLE },
      57              :         { 0, "1.3.6.1.5.5.7.9.3", "gender", N_("Gender"), 
      58              :                 EGG_OID_PRINTABLE },
      59              :         { 0, "1.3.6.1.5.5.7.9.4", "countryOfCitizenship", N_("Country of Citizenship"),
      60              :                 EGG_OID_PRINTABLE },
      61              :         { 0, "1.3.6.1.5.5.7.9.5", "countryOfResidence", N_("Country of Residence"),
      62              :                 EGG_OID_PRINTABLE },
      63              : 
      64              :         { 0, "2.5.4.3", "CN", N_("Common Name"), 
      65              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      66              :         { 0, "2.5.4.4", "surName", N_("Surname"), 
      67              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      68              :         { 0, "2.5.4.5", "serialNumber", N_("Serial Number"), 
      69              :                 EGG_OID_PRINTABLE },
      70              :         { 0, "2.5.4.6", "C", N_("Country"), 
      71              :                 EGG_OID_PRINTABLE, },
      72              :         { 0, "2.5.4.7", "L", N_("Locality"), 
      73              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      74              :         { 0, "2.5.4.8", "ST", N_("State"), 
      75              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      76              :         { 0, "2.5.4.9", "STREET", N_("Street"), 
      77              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      78              :         { 0, "2.5.4.10", "O", N_("Organization"), 
      79              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      80              :         { 0, "2.5.4.11", "OU", N_("Organizational Unit"), 
      81              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      82              :         { 0, "2.5.4.12", "T", N_("Title"), 
      83              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      84              :         { 0, "2.5.4.20", "telephoneNumber", N_("Telephone Number"), 
      85              :                 EGG_OID_PRINTABLE },
      86              :         { 0, "2.5.4.42", "givenName", N_("Given Name"), 
      87              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      88              :         { 0, "2.5.4.43", "initials", N_("Initials"), 
      89              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      90              :         { 0, "2.5.4.44", "generationQualifier", N_("Generation Qualifier"), 
      91              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      92              :         { 0, "2.5.4.46", "dnQualifier", N_("DN Qualifier"), 
      93              :                 EGG_OID_PRINTABLE },
      94              :         { 0, "2.5.4.65", "pseudonym", N_("Pseudonym"), 
      95              :                 EGG_OID_PRINTABLE | EGG_OID_IS_CHOICE },
      96              : 
      97              :         { 0, "1.2.840.113549.1.1.1", "rsaEncryption", N_("RSA"), 0 },
      98              :         { 0, "1.2.840.113549.1.1.2", "md2WithRSAEncryption", N_("MD2 with RSA"), 0 },
      99              :         { 0, "1.2.840.113549.1.1.4", "md5WithRSAEncryption", N_("MD5 with RSA"), 0 },
     100              :         { 0, "1.2.840.113549.1.1.5", "sha1WithRSAEncryption", N_("SHA1 with RSA"), 0 },
     101              : 
     102              :         { 0, "1.2.840.10040.4.1", "dsa", N_("DSA"), 0 },
     103              :         { 0, "1.2.840.10040.4.3", "sha1WithDSA", N_("SHA1 with DSA"), 0 },
     104              : 
     105              :         /* Extended Key Usages */
     106              :         { 0, "1.3.6.1.5.5.7.3.1", NULL, N_("Server Authentication"), 0 },
     107              :         { 0, "1.3.6.1.5.5.7.3.2", NULL, N_("Client Authentication"), 0 },
     108              :         { 0, "1.3.6.1.5.5.7.3.3", NULL, N_("Code Signing"), 0 },
     109              :         { 0, "1.3.6.1.5.5.7.3.4", NULL, N_("Email Protection"), 0 },
     110              :         { 0, "1.3.6.1.5.5.7.3.8", NULL, N_("Time Stamping"), 0 },
     111              : 
     112              :         { 0, NULL, NULL, NULL, FALSE }
     113              : };
     114              : 
     115              : static OidInfo*
     116          102 : find_oid_info (GQuark oid)
     117              : {
     118              :         static gsize inited_oids = 0;
     119              :         int i;
     120              :         
     121          102 :         g_return_val_if_fail (oid != 0, NULL);
     122              : 
     123              :         /* Initialize first time around */
     124          102 :         if (g_once_init_enter (&inited_oids)) {
     125          190 :                 for (i = 0; oid_info[i].oidstr != NULL; ++i)
     126          185 :                         oid_info[i].oid = g_quark_from_static_string (oid_info[i].oidstr);
     127            5 :                 g_once_init_leave (&inited_oids, 1);
     128              :         }
     129              :         
     130         1420 :         for (i = 0; oid_info[i].oidstr != NULL; ++i) {
     131         1416 :                 if (oid_info[i].oid == oid)
     132           98 :                         return &oid_info[i];
     133              :         }
     134              :         
     135            4 :         return NULL;
     136              : }
     137              : 
     138              : const gchar*
     139           66 : egg_oid_get_name (GQuark oid)
     140              : {
     141              :         OidInfo *info;
     142              :         
     143           66 :         g_return_val_if_fail (oid, NULL);
     144              :         
     145           66 :         info = find_oid_info (oid);
     146           66 :         if (info == NULL)
     147            1 :                 return g_quark_to_string (oid);
     148              :         
     149           65 :         return info->attr;   
     150              : }
     151              : 
     152              : const gchar*
     153            2 : egg_oid_get_description (GQuark oid)
     154              : {
     155              :         OidInfo *info;
     156              :         
     157            2 :         g_return_val_if_fail (oid, NULL);
     158              :         
     159            2 :         info = find_oid_info (oid);
     160            2 :         if (info == NULL)
     161            1 :                 return g_quark_to_string (oid);
     162              :         
     163            1 :         return gettext (info->description);
     164              : }
     165              : 
     166              : guint
     167           34 : egg_oid_get_flags (GQuark oid)
     168              : {
     169              :         OidInfo *info;
     170              :         
     171           34 :         g_return_val_if_fail (oid, 0);
     172              :         
     173           34 :         info = find_oid_info (oid);
     174           34 :         if (info == NULL)
     175            2 :                 return 0;
     176              :         
     177           32 :         return info->flags;  
     178              : }
        

Generated by: LCOV version 2.0-1