2N/A * -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2N/A * The contents of this file are subject to the Netscape Public License 2N/A * Version 1.0 (the "NPL"); you may not use this file except in 2N/A * compliance with the NPL. You may obtain a copy of the NPL at 2N/A * Software distributed under the NPL is distributed on an "AS IS" basis, 2N/A * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL 2N/A * for the specific language governing rights and limitations under the 2N/A * The Initial Developer of this code under the NPL is Netscape 2N/A * Communications Corporation. Portions created by Netscape are 2N/A * Copyright (C) 1998 Netscape Communications Corporation. All Rights 2N/A * Copyright (c) 1990 Regents of the University of Michigan. 2N/A * All rights reserved. 2N/A * Redistribution and use in source and binary forms are permitted 2N/A * provided that this notice is preserved and that due credit is given 2N/A * to the University of Michigan at Ann Arbor. The name of the University 2N/A * may not be used to endorse or promote products derived from this 2N/A * software without specific prior written permission. This software 2N/A * is provided ``as is'' without express or implied warranty. 2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A/* the following constants are used in kmfber_calc_lenlen */ 2N/A /* find the first non-all-zero byte in the tag */ 2N/A * short len if it's less than 128 - one byte giving the len, 2N/A * long len otherwise - one byte with bit 8 set, giving the 2N/A * length of the length, followed by the length itself. 2N/A * short len if it's less than 128 - one byte giving the len, 2N/A * long len otherwise - one byte with bit 8 set, giving the 2N/A * length of the length, followed by the length itself. 2N/A /* find the first non-all-zero byte */ 2N/A /* write the length of the length */ 2N/A /* write the length itself */ 2N/A * high bit is set - look for first non-all-one byte 2N/A * high bit is clear - look for first non-all-zero byte 2N/A * we now have the "leading byte". if the high bit on this 2N/A * byte matches the sign bit, we need to "back up" a byte. 2N/A /* length of tag + length + contents */ 2N/A tag =
0x06;
/* TODO: Add new OID constant to header */ 2N/A /* return length of tag + length + contents */ 2N/A /* Add a leading 0 if the high order bit is set */ 2N/A /* add leading 0 if hi bit set */ 2N/A /* Adjust the length of the write if hi-order bit is set */ 2N/A /* return length of tag + length + contents */ 2N/A#
endif /* STR_TRANSLATION */ 2N/A#
endif /* STR_TRANSLATION */ 2N/A * Note: below is a spot where we limit ber_write 2N/A * to signed long (instead of unsigned long) 2N/A /* return length of tag + length + contents */ 2N/A#
endif /* STR_TRANSLATION */ 2N/A /* return length of tag + length + unused bit count + contents */ 2N/A * The idea here is roughly this: we maintain a stack of these Seqorset 2N/A * structures. This is pushed when we see the beginning of a new set or 2N/A * sequence. It is popped when we see the end of a set or sequence. 2N/A * Since we don't want to malloc and free these structures all the time, 2N/A * we pre-allocate a small set of them within the ber element structure. 2N/A * thus we need to spot when we've overflowed this stack and fall back to 2N/A * malloc'ing instead. 2N/A /* can we fit into the local stack ? */ 2N/A /* Set aside room for a 4 byte length field */ 2N/A * If this is the toplevel sequence or set, we need to actually 2N/A * write the stuff out. Otherwise, it's already been put in 2N/A * the appropriate buffer and will be written when the toplevel 2N/A * one is written. In this case all we need to do is update the 2N/A /* Write the length in the minimum # of octets */ 2N/A * We set aside FOUR_BYTE_LEN bytes for 2N/A * the length field. Move the data if 2N/A * we don't actually need that much 2N/A /* Fill FOUR_BYTE_LEN bytes for length field */ 2N/A /* one byte of length length */ 2N/A /* the length itself */ 2N/A /* The ber_ptr is at the set/seq start - move it to the end */ 2N/A /* one byte of length length */ 2N/A /* Write the length itself */ 2N/A * We set aside FOUR_BYTE_LEN bytes for 2N/A * the length field. Move the data if 2N/A * we don't actually need that much 2N/A /* the length itself */ 2N/A /* we're done with this seqorset, so free it up */ 2N/A /* was this one from the local stack ? */ 2N/A case 'b':
/* boolean */ 2N/A case 'D':
/* Object ID */ 2N/A case 'e':
/* enumeration */ 2N/A case 'n':
/* null */ 2N/A case 'o':
/* octet string (non-null terminated) */ 2N/A case 's':
/* string */ 2N/A case 'B':
/* bit string */ 2N/A case 't':
/* tag for the next element */ 2N/A case 'T':
/* Write an explicit tag, but don't change current */ 2N/A case 'v':
/* vector of strings */ 2N/A case 'V':
/* sequences of strings + lengths */ 2N/A case '{':
/* begin sequence */ 2N/A case '}':
/* end sequence */ 2N/A case '[':
/* begin set */ 2N/A case ']':
/* end set */