blob: cf7bfc77d885a2ed69ac1e2e88e7303274b81dc2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include <u.h>
#include <libc.h>
#include <auth.h>
#include <mp.h>
#include <libsec.h>
#include "rsa2any.h"
int privatekey = 0;
void
usage(void)
{
fprint(2, "usage: auth/rsa2asn1 [-a] [file]\n");
exits("usage");
}
void
main(int argc, char **argv)
{
uchar buf[16*1024];
RSApriv *k;
int n;
ARGBEGIN{
case 'a':
privatekey = 1;
break;
default:
usage();
}ARGEND
if(argc > 1)
usage();
if((k = getrsakey(argc, argv, privatekey, nil)) == nil)
sysfatal("%r");
if(privatekey){
if((n = asn1encodeRSApriv(k, buf, sizeof(buf))) < 0)
sysfatal("asn1encodeRSApriv: %r");
}else{
if((n = asn1encodeRSApub(&k->pub, buf, sizeof(buf))) < 0)
sysfatal("asn1encodeRSApub: %r");
}
if(write(1, buf, n) != n)
sysfatal("write: %r");
exits(nil);
}
|