]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/auth/asn1dump.c
merge
[plan9front.git] / sys / src / cmd / auth / asn1dump.c
1 #include <u.h>
2 #include <libc.h>
3 #include <mp.h>
4 #include <libsec.h>
5
6 void
7 usage(void)
8 {
9         fprint(2, "auth/asn1dump [file]\n");
10         exits("usage");
11 }
12
13 void
14 main(int argc, char *argv[])
15 {
16         int fd, n, tot;
17         uchar *buf;
18         char *file;
19
20         fmtinstall('B', mpfmt);
21         fmtinstall('H', encodefmt);
22         fmtinstall('[', encodefmt);
23
24         ARGBEGIN{
25         default:
26                 usage();
27         }ARGEND
28
29         if(argc != 0 && argc != 1)
30                 usage();
31
32         if(argc == 1)
33                 file = argv[0];
34         else
35                 file = "#d/0";
36
37         if((fd = open(file, OREAD)) < 0)
38                 sysfatal("open %s: %r", file);
39
40         buf = nil;
41         tot = 0;
42         for(;;){
43                 buf = realloc(buf, tot+8192);
44                 if(buf == nil)
45                         sysfatal("realloc: %r");
46                 if((n = read(fd, buf+tot, 8192)) < 0)
47                         sysfatal("read: %r");
48                 if(n == 0)
49                         break;
50                 tot += n;
51         }
52
53         asn1dump(buf, tot);
54
55         X509dump(buf, tot);
56
57         exits(nil);
58 }