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