]> andersk Git - openssh.git/blob - uuencode.c
2540d7564646aebb0543962f613ba3d20a232964
[openssh.git] / uuencode.c
1 /*
2  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
3  */
4 #include "includes.h"
5 #include "xmalloc.h"
6
7 int
8 uuencode(unsigned char *src, unsigned int srclength,
9     char *target, size_t targsize)
10 {
11         return __b64_ntop(src, srclength, target, targsize);
12 }
13
14 int
15 uudecode(const char *src, unsigned char *target, size_t targsize)
16 {
17         int len;
18         char *encoded, *p;
19
20         /* copy the 'readonly' source */
21         encoded = xstrdup(src);
22         /* skip whitespace and data */
23         for (p = encoded; *p == ' ' || *p == '\t'; p++)
24                 ;
25         for (; *p != '\0' && *p != ' ' && *p != '\t'; p++)
26                 ;
27         /* and remote trailing whitespace because __b64_pton needs this */
28         *p = '\0';
29         len = __b64_pton(encoded, target, targsize);
30         xfree(encoded);
31         return len;
32 }
33
34 void
35 dump_base64(FILE *fp, unsigned char *data, int len)
36 {
37         unsigned char *buf = xmalloc(2*len);
38         int i, n;
39         n = uuencode(data, len, buf, 2*len);
40         for (i = 0; i < n; i++) {
41                 fprintf(fp, "%c", buf[i]);
42                 if (i % 70 == 69)
43                         fprintf(fp, "\n");
44         }
45         if (i % 70 != 69)
46                 fprintf(fp, "\n");
47         xfree(buf);
48 }
This page took 0.403583 seconds and 3 git commands to generate.