3 Parsing s-expressions in transport format.
5 Copyright (C) 2002 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
45 /* NOTE: Decodes the input string in place */
47 sexp_transport_iterator_first(struct sexp_iterator *iterator,
48 size_t length, uint8_t *input)
50 /* We first base64 decode any transport encoded sexp at the start of
59 case ' ': /* SPC, TAB, LF, CR */
66 case ';': /* Comments */
67 while (++in < length && input[in] != '\n')
73 /* Found transport encoding */
74 struct base64_decode_ctx ctx;
78 for (end = ++in; end < length && input[end] != '}'; end++)
84 base64_decode_init(&ctx);
86 if (base64_decode_update(&ctx, &coded_length, input + out,
87 end - in, (const char*) (input + in))
88 && base64_decode_final(&ctx))
99 /* Expression isn't in transport encoding. Rest of the input
100 * should be in canonical encoding. */
106 /* Here, we have two, possibly empty, input parts in canonical
109 * 0...out-1, in...length -1
111 * If the input was already in canonical encoding, out = 0 and in =
112 * amount of leading space.
114 * If all input was in transport encoding, in == length.
121 else if (in == length)
124 /* Unusual case, nothing happens */
128 /* Both parts non-empty */
130 memmove(input + out, input + in, length - in);
131 length -= (in - out);
134 return sexp_iterator_first(iterator, length, input);