shithub: riscv

ref: 899ec4d0b568a6d51a85e5344733a2189a7ba1ec
dir: /sys/src/cmd/auth/rsa2asn1.c/

View raw version
#include <u.h>
#include <libc.h>
#include <auth.h>
#include <mp.h>
#include <libsec.h>
#include "rsa2any.h"

void
usage(void)
{
	fprint(2, "usage: auth/rsa2asn1 [file]\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	uchar buf[16*1024];
	RSApriv *k;
	int n;

	ARGBEGIN{
	default:
		usage();
	}ARGEND

	if(argc > 1)
		usage();

	if((k = getrsakey(argc, argv, 0, nil)) == nil)
		sysfatal("%r");
	if((n = asn1encodeRSApub(&k->pub, buf, sizeof(buf))) < 0)
		sysfatal("asn1encodeRSApub: %r");
	if(write(1, buf, n) != n)
		sysfatal("write: %r");
	exits(nil);
}