3 * Parsing s-expressions in transport format.
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2002 Niels Möller
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
37 /* NOTE: Decodes the input string in place */
39 sexp_transport_iterator_first(struct sexp_iterator *iterator,
40 unsigned length, uint8_t *input)
42 /* We first base64 decode any transport encoded sexp at the start of
51 case ' ': /* SPC, TAB, LF, CR */
58 case ';': /* Comments */
59 while (++in < length && input[in] != '\n')
65 /* Found transport encoding */
66 struct base64_decode_ctx ctx;
67 unsigned coded_length;
70 for (end = ++in; end < length && input[end] != '}'; end++)
76 base64_decode_init(&ctx);
77 coded_length = end - in;
79 if (base64_decode_update(&ctx, &coded_length, input + out,
80 coded_length, input + in)
81 && base64_decode_final(&ctx))
92 /* Expression isn't in transport encoding. Rest of the input
93 * should be in canonical encoding. */
99 /* Here, we have two, possibly empty, input parts in canonical
102 * 0...out-1, in...length -1
104 * If the input was already in canonical encoding, out = 0 and in =
105 * amount of leading space.
107 * If all input was in transport encoding, in == length.
114 else if (in == length)
117 /* Unusual case, nothing happens */
121 /* Both parts non-empty */
123 memmove(input + out, input + in, length - in);
124 length -= (in - out);
127 return sexp_iterator_first(iterator, length, input);