root/openpgpsdk/trunk/examples/verify.c

Revision 456 (checked in by ben, 6 years ago)

Memory leak.

Line 
1 #include <openpgpsdk/packet.h>
2 #include <openpgpsdk/packet-parse.h>
3 #include <openpgpsdk/util.h>
4 #include <openpgpsdk/accumulate.h>
5 #include <openpgpsdk/keyring.h>
6 #include <openpgpsdk/validate.h>
7 #include <unistd.h>
8 #include <string.h>
9 #include <fcntl.h>
10
11 #include <openpgpsdk/final.h>
12
13 int main(int argc,char **argv)
14     {
15     ops_parse_info_t *pinfo;
16     ops_keyring_t keyring;
17     const char *target;
18     int fd;
19     ops_validate_result_t result;
20
21     if(argc != 2)
22         {
23         fprintf(stderr,"%s <file to verify>\n",argv[0]);
24         exit(1);
25         }
26
27     target=argv[1];
28
29     ops_init();
30
31     memset(&keyring,'\0',sizeof keyring);
32
33     pinfo=ops_parse_info_new();
34
35     if(!strcmp(target,"-"))
36         fd=0;
37     else
38         {
39         fd=open(target,O_RDONLY);
40         if(fd < 0)
41             {
42             perror(target);
43             exit(2);
44             }
45         }
46
47     ops_reader_set_fd(pinfo,fd);
48
49     ops_parse_and_accumulate(&keyring,pinfo);
50
51     ops_dump_keyring(&keyring);
52
53     ops_validate_all_signatures(&result,&keyring);
54
55     ops_keyring_free(&keyring);
56
57     ops_parse_info_delete(pinfo);
58
59     ops_finish();
60
61     printf("valid signatures   = %d\n",result.valid_count);
62     printf("invalid signatures = %d\n",result.invalid_count);
63     printf("unknown signer     = %d\n",result.unknown_signer_count);
64
65     if(result.invalid_count)
66         return 1;
67
68     return 0;
69     }
Note: See TracBrowser for help on using the browser.