(der_get_unsigned): new function
(der_get_int): handle signed integers git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5347 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 1998 Kungliga Tekniska H<>gskolan
|
* Copyright (c) 1997, 1998, 1999 Kungliga Tekniska H<>gskolan
|
||||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -42,22 +42,16 @@ RCSID("$Id$");
|
|||||||
|
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* All decoding functions take a pointer `p' to first position in
|
|
||||||
* which to read, from the left, `len' which means the maximum
|
|
||||||
* number of characters we are able to read and return an int
|
|
||||||
* indicating how many actually got read, or <0 in case of errors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All decoding functions take a pointer `p' to first position in
|
* All decoding functions take a pointer `p' to first position in
|
||||||
* which to read, from the left, `len' which means the maximum number
|
* which to read, from the left, `len' which means the maximum number
|
||||||
* of characters we are able to read and return the status as an int
|
* of characters we are able to read, `ret' were the value will be
|
||||||
|
* returned and `size' where the number of used bytes is stored.
|
||||||
|
* Either 0 or an error code is returned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static int
|
||||||
int
|
der_get_unsigned (unsigned char *p, size_t len, unsigned *ret, size_t *size)
|
||||||
der_get_int (unsigned char *p, size_t len, unsigned *ret, size_t *size)
|
|
||||||
{
|
{
|
||||||
unsigned val = 0;
|
unsigned val = 0;
|
||||||
size_t oldlen = len;
|
size_t oldlen = len;
|
||||||
@@ -69,6 +63,21 @@ der_get_int (unsigned char *p, size_t len, unsigned *ret, size_t *size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
der_get_int (unsigned char *p, size_t len, int *ret, size_t *size)
|
||||||
|
{
|
||||||
|
int val = 0;
|
||||||
|
size_t oldlen = len;
|
||||||
|
|
||||||
|
if (len--)
|
||||||
|
val = (signed char)*p++;
|
||||||
|
while (len--)
|
||||||
|
val = val * 256 + *p++;
|
||||||
|
*ret = val;
|
||||||
|
if(size) *size = oldlen;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
der_get_length (unsigned char *p, size_t len, size_t *val, size_t *size)
|
der_get_length (unsigned char *p, size_t len, size_t *val, size_t *size)
|
||||||
{
|
{
|
||||||
@@ -94,7 +103,7 @@ der_get_length (unsigned char *p, size_t len, size_t *val, size_t *size)
|
|||||||
v &= 0x7F;
|
v &= 0x7F;
|
||||||
if (len < v)
|
if (len < v)
|
||||||
return ASN1_OVERRUN;
|
return ASN1_OVERRUN;
|
||||||
e = der_get_int (p, v, &tmp, &l);
|
e = der_get_unsigned (p, v, &tmp, &l);
|
||||||
if(e) return e;
|
if(e) return e;
|
||||||
*val = tmp;
|
*val = tmp;
|
||||||
if(size) *size = l + 1;
|
if(size) *size = l + 1;
|
||||||
@@ -206,7 +215,7 @@ der_match_tag_and_length (unsigned char *p, size_t len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
decode_integer (unsigned char *p, size_t len, unsigned *num, size_t *size)
|
decode_integer (unsigned char *p, size_t len, int *num, size_t *size)
|
||||||
{
|
{
|
||||||
size_t ret = 0;
|
size_t ret = 0;
|
||||||
size_t l, reallen;
|
size_t l, reallen;
|
||||||
|
Reference in New Issue
Block a user