Skip to content
Snippets Groups Projects
Commit 899af3c0 authored by Niels Möller's avatar Niels Möller
Browse files

(sexp_iterator_get_uint32): New function.

Rev: src/nettle/sexp.c:1.12
Rev: src/nettle/sexp.h:1.9
parent f75832a1
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,8 @@
#include "sexp.h"
#include "macros.h"
#include <stdlib.h>
#include <string.h>
......@@ -222,6 +224,48 @@ sexp_iterator_subexpr(struct sexp_iterator *iterator,
return iterator->buffer + start;
}
int
sexp_iterator_get_uint32(struct sexp_iterator *iterator,
uint32_t *x)
{
if (iterator->type == SEXP_ATOM
&& !iterator->display
&& iterator->atom_length
&& iterator->atom[0] < 0x80)
{
unsigned length = iterator->atom_length;
const uint8_t *p = iterator->atom;
/* Skip leading zeros. */
while(length && !*p)
{
length--; p++;
}
switch(length)
{
case 0:
*x = 0;
break;
case 1:
*x = p[0];
break;
case 2:
*x = READ_UINT16(p);
break;
case 3:
*x = READ_UINT24(p);
break;
case 4:
*x = READ_UINT32(p);
break;
default:
return 0;
}
return sexp_iterator_next(iterator);
}
return 0;
}
int
sexp_iterator_check_type(struct sexp_iterator *iterator,
......
......@@ -83,6 +83,10 @@ const uint8_t *
sexp_iterator_subexpr(struct sexp_iterator *iterator,
unsigned *length);
int
sexp_iterator_get_uint32(struct sexp_iterator *iterator,
uint32_t *x);
/* Checks the type of the current expression, which should be a list
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment