asn1buf.c revision 505d05c73a6e56769f263d4803b22eddd168ee24
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Coding Buffer Implementation */
/*
Implementation
Encoding mode
The encoding buffer is filled from bottom (lowest address) to top
(highest address). This makes it easier to expand the buffer,
since realloc preserves the existing portion of the buffer.
Note: Since ASN.1 encoding must be done in reverse, this means
that you can't simply memcpy out the buffer data, since it will be
backwards. You need to reverse-iterate through it, instead.
***This decision may have been a mistake. In practice, the
implementation will probably be tuned such that reallocation is
rarely necessary. Also, the realloc probably has recopy the
buffer itself, so we don't really gain that much by avoiding an
explicit copy of the buffer. --Keep this in mind for future reference.
Decoding mode
The decoding buffer is in normal order and is created by wrapping
an asn1buf around a krb5_data structure.
*/
/* Abstraction Function
Programs should use just pointers to asn1buf's (e.g. asn1buf *mybuf).
These pointers must always point to a valid, allocated asn1buf
structure or be NULL.
The contents of the asn1buf represent an octet string. This string
begins at base and continues to the octet immediately preceding next.
If next == base or mybuf == NULL, then the asn1buf represents an empty
octet string. */
/* Representation Invariant
Pointers to asn1buf's must always point to a valid, allocated
asn1buf structure or be NULL.
base points to a valid, allocated octet array or is NULL
bound, if non-NULL, points to the last valid octet
next >= base
next <= bound+2 (i.e. next should be able to step just past the bound,
but no further. (The bound should move out in response
to being crossed by next.)) */
#define ASN1BUF_OMIT_INLINE_FUNCS
#include "asn1buf.h"
#include <stdio.h>
#include "asn1_get.h"
{
return 0;
}
{
return 0;
}
asn1_error_code asn1buf_imbed(asn1buf *subbuf, const asn1buf *buf, const unsigned int length, const int indef)
{
if (!indef) {
return ASN1_OVERRUN;
} else /* constructed indefinite */
return 0;
}
{
if (!seqindef) {
/* sequence was encoded as definite length */
if (retval)
return retval;
} else {
/* We have just read the EOC octets. */
}
return 0;
}
{
taginfo t;
int nestlevel;
if (!indef) {
else
return ASN1_OVERRUN;
}
while (nestlevel > 0) {
return ASN1_OVERRUN;
if (!t.indef) {
else
return ASN1_OVERRUN;
}
if (t.indef)
nestlevel++;
nestlevel--; /* got an EOC encoding */
}
return 0;
}
{
}
return 0;
}
#ifdef asn1buf_insert_octet
#endif
{
return 0;
}
asn1_error_code asn1buf_insert_octetstring(asn1buf *buf, const unsigned int len, const krb5_octet *s)
{
int length;
return 0;
}
{
int length;
return 0;
}
{
return 0;
}
{
int i;
if (len == 0) {
*s = 0;
return 0;
}
if (*s == NULL)
return ENOMEM;
for(i=0; i<len; i++)
return 0;
}
{
int i;
if (len == 0) {
*s = 0;
return 0;
}
for(i=0; i<len; i++)
return 0;
}
{
int remain;
/*
* Two 0 octets means the end of an indefinite encoding.
*/
return 0;
else return remain;
}
{
int i;
return ENOMEM;
}
return 0;
}
/* These parse and unparse procedures should be moved out. They're
useful only for debugging and superfluous in the production version. */
{
*s = malloc(sizeof("<NULL>"));
strcpy(*s,"<NULL>");
*s = malloc(sizeof("<EMPTY>"));
strcpy(*s,"<EMPTY>");
}else{
int i;
(*s)[length] = '\0';
for(i=0; i<length; i++) ;
/* OLDDECLARG( (*s)[i] = , (buf->base)[length-i-1]) */
}
return 0;
}
{
((d)<=15 ? ('A'+(d)-10) :\
'X'))
*s = malloc(sizeof("<NULL>"));
strcpy(*s,"<NULL>");
*s = malloc(sizeof("<EMPTY>"));
strcpy(*s,"<EMPTY>");
}else{
int i;
for(i = length-1; i >= 0; i--){
}
}
return 0;
}
/****************************************************************/
/* Private Procedures */
{
}
{
}
{
}
return 0;
}
{
#define STANDARD_INCREMENT 200
int bound_offset;
if (inc < STANDARD_INCREMENT)
else
return 0;
}
{
}