ver
[libexssl.git] / test / dcr.c
bloba8cfeed55da1943b041189f3e909bdcff5627fa8
1 #include <unistd.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdlib.h>
7 #include "ssl.h"
9 int main (int argc, const char *argv[]) {
10 if (argc < 3) return 1;
11 const char *in_fname = argv[1],
12 *out_fname = argv[2];
13 if (-1 == ssl_init()) return 1;
14 str_t *src = load_all_file(in_fname, 512, 2048);
15 if (src) {
16 ssl_key_t *key = ssl_key_init();
17 if (0 == ssl_load_priv_fl("./key.pem", NULL, key)) {
18 str_t *dst = NULL;
19 if (0 == ssl_decrypt_priv(key, src->ptr, src->len, &dst)) {
20 FILE *fp = fopen(out_fname, "wt");
21 if (fp) {
22 fwrite(dst->ptr, dst->len, 1, fp);
23 fclose(fp);
25 free(dst);
28 ssl_free_key(key);
29 free(src);
31 ssl_done();
32 return 0;