1 /* sexp-parse.h - S-Exp helper functions
2 * Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include <gpg-error.h>
27 /* Return the length of the next S-Exp part and update the pointer to
28 the first data byte. 0 is returned on error */
30 snext (unsigned char const **buf
)
32 const unsigned char *s
;
36 for (n
=0; *s
&& *s
!= ':' && (*s
>= '0' && *s
<= '9'); s
++)
37 n
= n
*10 + (*s
- '0');
39 return 0; /* we don't allow empty lengths */
44 /* Skip over the S-Expression BUF points to and update BUF to point to
45 the chacter right behind. DEPTH gives the initial number of open
46 lists and may be passed as a positive number to skip over the
47 remainder of an S-Expression if the current position is somewhere
48 in an S-Expression. The function may return an error code if it
49 encounters an impossible conditions */
50 static inline gpg_error_t
51 sskip (unsigned char const **buf
, int *depth
)
53 const unsigned char *s
= *buf
;
72 return gpg_error (GPG_ERR_INV_SEXP
);
75 return gpg_error (GPG_ERR_INV_SEXP
);
85 /* Check whether the the string at the address BUF points to matches
86 the token. Return true on match and update BUF to point behind the
87 token. Return false and dont update tha buffer if it does not
90 smatch (unsigned char const **buf
, size_t buflen
, const char *token
)
92 size_t toklen
= strlen (token
);
94 if (buflen
!= toklen
|| memcmp (*buf
, token
, toklen
))
100 #endif /*SEXP_PARSE_H*/