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