/[winpt]/trunk/MyGPGME/sig.c
ViewVC logotype

Annotation of /trunk/MyGPGME/sig.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 3473 byte(s)
WinPT initial checkin.


1 twoaday 2 /* sig.c - General signature API
2     * Copyright (C) 2001, 2002, 2003 Timo Schulz
3     *
4     * This file is part of MyGPGME.
5     *
6     * MyGPGME is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * MyGPGME 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
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #include <stdio.h>
22     #include <string.h>
23     #include <stdlib.h>
24    
25     #include "gpgme.h"
26     #include "context.h"
27     #include "util.h"
28    
29    
30     gpgme_error_t
31     gpgme_sig_new( gpgme_sig_t *r_sig )
32     {
33     gpgme_sig_t sig;
34    
35     sig = calloc( 1, sizeof *sig );
36     if( !sig )
37     return mk_error( Out_Of_Core );
38     *r_sig = sig;
39     return 0;
40     } /* gpgme_sig_new */
41    
42    
43     void
44     gpgme_sig_release( gpgme_sig_t sig )
45     {
46     if( !sig )
47     return;
48     if( sig->ref_count > 0 ) {
49     sig->ref_count--;
50     return;
51     }
52     safe_free( sig->notation );
53     safe_free( sig->policy_url );
54     safe_free( sig->user_id );
55     safe_free( sig->file_name );
56     safe_free (sig->key_server);
57     safe_free( sig );
58     } /* gpgme_sig_release */
59    
60    
61     void
62     _gpgme_sig_ref( gpgme_sig_t sig )
63     {
64     if( sig )
65     sig->ref_count++;
66     } /* _gpgme_sig_ref */
67    
68    
69     void
70     gpgme_sig_set_key_ctx( gpgme_sig_t sig, gpgme_keycache_t cache )
71     {
72     if( sig && cache )
73     gpgme_keycache_find_key( cache, sig->id, 0, &sig->key );
74     } /* gpgme_sig_set_key_ctx */
75    
76    
77     ulong
78     gpgme_sig_get_ulong_attr( gpgme_sig_t sig, int idx, int what )
79     {
80     gpgme_sig_t s;
81     int pos = 0;
82    
83     if( !sig )
84     return 0;
85    
86     switch( what ) {
87     case GPGME_ATTR_EXPIRES: return sig->expired;
88     case GPGME_ATTR_EXPIRE: return sig->flags.expired;;
89     case GPGME_ATTR_VALIDITY: return sig->sigstat;
90     case GPGME_ATTR_OTRUST: return sig->trust;
91     case GPGME_ATTR_CREATED: return sig->created;
92     case GPGME_ATTR_TYPE: return (ulong)sig->key;
93     case GPGME_ATTR_ALGO: return sig->key_algo;
94     case GPGME_ATTR_OPAQUE:
95     for( s = sig; s && idx > 0; s=s->next, idx-- )
96     ;
97     return (ulong)s;
98    
99     case GPGME_ATTR_LEVEL:
100     for( s = sig; s; s = s->next )
101     pos++;
102     return pos;
103     case GPGME_ATTR_KEYID:
104     if( strlen( sig->id ) == 40 ) pos = 32;
105     else if( strlen( sig->id ) == 16 ) pos = 8;
106     return strtoul( sig->id + pos, NULL, 16 );
107     }
108     return 0;
109     } /* gpgme_sig_get_ulong_attr */
110    
111    
112     const char*
113     gpgme_sig_get_string_attr( gpgme_sig_t sig, int what )
114     {
115     if( !sig )
116     return NULL;
117    
118     switch( what ) {
119     case GPGME_ATTR_NOTATION:
120     return sig->notation;
121     case GPGME_ATTR_NAME:
122     return sig->file_name;
123     case GPGME_ATTR_USERID:
124     return sig->user_id;
125     case GPGME_ATTR_POLICY_URL:
126     return sig->policy_url;
127     case GPGME_ATTR_KEYSERVER:
128     return sig->key_server;
129     case GPGME_ATTR_KEYID:
130     if( strlen( sig->id ) == 40 )
131     return sig->id + 24;
132     return sig->id;
133     }
134     return NULL;
135     } /* gpgme_sig_get_string_attr */
136    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26