2 .\" Copyright (C) 1990, Regents of the University of Michigan. All Rights Reserved.
3 .\" Portions Copyright (C) 2008, Sun Microsystems, Inc. All Rights Reserved.
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH BER_ENCODE 3LDAP "Oct 6, 2008"
9 ber_encode, ber_alloc, ber_printf, ber_put_int, ber_put_ostring,
10 ber_put_string, ber_put_null, ber_put_boolean, ber_put_bitstring,
11 ber_start_seq, ber_start_set, ber_put_seq, ber_put_set \- simplified Basic
12 Encoding Rules library encoding functions
16 cc[ \fIflag\fR... ] \fIfile\fR... -lldap[ \fIlibrary\fR... ]
19 \fBBerElement *\fR\fBber_alloc\fR();
24 \fB\fR\fBber_printf\fR(\fBBerElement\fR \fI*ber\fR, \fBchar\fR \fI**fmt\fR[, \fIarg\fR... ]);
29 \fB\fR\fBber_put_int\fR(\fBBerElement\fR \fI*ber\fR, \fBlong\fR \fInum\fR, \fBchar\fR \fItag\fR);
34 \fB\fR\fBber_put_ostring\fR(\fBBerElement\fR \fI*ber\fR, \fBchar\fR \fI**str\fR, \fBunsigned long\fR \fIlen\fR,
35 \fBchar\fR \fItag\fR);
40 \fB\fR\fBber_put_string\fR(\fBBerElement\fR \fI*ber\fR, \fBchar\fR \fI**str\fR, \fBchar\fR \fItag\fR);
45 \fB\fR\fBber_put_null\fR(\fBBerElement\fR \fI*ber\fR, \fBchar\fR \fItag\fR);
50 \fB\fR\fBber_put_boolean\fR(\fBBerElement\fR \fI*ber\fR, \fBint\fR \fIbool\fR, \fBchar\fR \fItag\fR);
55 \fB\fR\fBber_put_bitstring\fR(\fBBerElement\fR \fI*ber\fR, \fBchar\fR \fI*str\fR, \fBint\fR \fIblen\fR, \fBchar\fR \fItag\fR);
60 \fB\fR\fBber_start_seq\fR(\fBBerElement\fR \fI*ber\fR, \fBchar\fR \fItag\fR);
65 \fB\fR\fBber_start_set\fR(\fBBerElement\fR \fI*ber\fR, \fBchar\fR \fItag\fR);
70 \fB\fR\fBber_put_seq\fR(\fBBerElement\fR \fI*ber\fR);
75 \fB\fR\fBber_put_set\fR(\fBBerElement\fR \fI*ber\fR);
81 These functions provide a subfunction interface to a simplified implementation
82 of the Basic Encoding Rules of ASN.1. The version of BER these functions
83 support is the one defined for the LDAP protocol. The encoding rules are the
84 same as BER, except that only definite form lengths are used, and bitstrings
85 and octet strings are always encoded in primitive form. In addition, these
86 lightweight BER functions restrict tags and class to fit in a single octet
87 (this means the actual tag must be less than 31). When a "tag"is specified in
88 the descriptions below, it refers to the tag, class, and primitive or
89 constructed bit in the first octet of the encoding. This man page describes
90 the encoding functions in the lber library. See \fBber_decode\fR(3LDAP) for
91 details on the corresponding decoding functions.
94 Normally, the only functions that need be called by an application are
95 \fBber_alloc()\fR, to allocate a \fBBER\fR element, and \fBber_printf()\fR to
96 do the actual encoding. The other functions are provided for those
97 applications that need more control than \fBber_printf()\fR provides. In
98 general, these functions return the length of the element encoded, or
99 \fB\(mi1\fR if an error occurred.
102 The \fBber_alloc()\fR function is used to allocate a new BER element.
105 The \fBber_printf()\fR function is used to encode a BER element in much the
106 same way that \fBsprintf(3C)\fR works. One important difference, though, is
107 that some state information is kept with the \fIber\fR parameter so that
108 multiple calls can be made to \fBber_printf()\fR to append things to the end
109 of the BER element. \fBBer_printf()\fR writes to \fIber\fR, a pointer to a
110 \fBBerElement\fR such as returned by \fBber_alloc()\fR. It interprets and
111 formats its arguments according to the format string \fBfmt\fR. The format
112 string can contain the following characters:
119 Boolean. An integer parameter should be supplied. A boolean element is
129 Bitstring. A \fBchar *\fR pointer to the start of the bitstring is supplied,
130 followed by the number of bits in the bitstring. A bitstring element is
140 Integer. An integer parameter should be supplied. An integer element is
150 Null. No parameter is required. A null element is output.
159 Octet string. A \fBchar *\fR is supplied, followed by the length of the string
160 pointed to. An octet string element is output.
169 Octet string. A \fBstruct berval *\fR is supplied. An octet string element is
179 Octet string. A null-terminated string is supplied. An octet string element
180 is output, not including the trailing null octet.
189 Tag. An int specifying the tag to give the next element is provided. This
199 Several octet strings. A null-terminated array of \fBchar *\fR is supplied.
200 Note that a construct like '{v}' is required to get an actual sequence of octet
210 Begin sequence. No parameter is required.
219 End sequence. No parameter is required.
228 Begin set. No parameter is required.
237 End set. No parameter is required.
242 The \fBber_put_int()\fR function writes the integer element \fInum\fR to the
243 BER element \fIber\fR.
246 The \fBber_put_boolean()\fR function writes the boolean value given by
247 \fIbool\fR to the BER element.
250 The \fBber_put_bitstring()\fR function writes \fIblen\fR bits starting at
251 \fIstr\fR as a bitstring value to the given BER element. Note that \fIblen\fR
252 is the length in \fIbits\fR of the bitstring.
255 The \fBber_put_ostring()\fR function writes \fIlen\fR bytes starting at
256 \fIstr\fR to the BER element as an octet string.
259 The \fBber_put_string()\fR function writes the null-terminated string (minus
260 the terminating '') to the BER element as an octet string.
263 The \fBber_put_null()\fR function writes a \fINULL\fR element to the BER
267 The \fBber_start_seq()\fR function is used to start a sequence in the BER
268 element. The \fBber_start_set()\fR function works similarly. The end of the
269 sequence or set is marked by the nearest matching call to \fBber_put_seq()\fR
270 or \fBber_put_set()\fR, respectively.
273 The \fBber_first_element()\fR function is used to return the tag and length of
274 the first element in a set or sequence. It also returns in \fIcookie\fR a
275 magic cookie parameter that should be passed to subsequent calls to
276 \fBber_next_element()\fR, which returns similar information.
279 \fBExample 1 \fRAssuming the following variable declarations, and that the
280 variables have been assigned appropriately, an BER encoding of the following
285 AlmostASearchRequest := SEQUENCE {
286 baseObject DistinguishedName,
292 derefAliases ENUMERATED {
293 neverDerefaliases (0),
294 derefInSearching (1),
295 derefFindingBaseObj (2),
296 alwaysDerefAliases (3N)
298 sizelimit INTEGER (0 .. 65535),
299 timelimit INTEGER (0 .. 65535),
301 attributes SEQUENCE OF AttributeType
308 can be achieved like so:
312 int scope, ali, size, time, attrsonly;
315 /* ... fill in values ... */
316 if ( (ber = ber_alloc(\|)) == NULLBER )
319 if ( ber_printf( ber, "{siiiib{v}}", dn, scope, ali,
320 size, time, attrsonly, attrs ) == -1 )
330 If an error occurs during encoding, \fBber_alloc()\fR returns \fINULL\fR; other
331 functions generally return \fB\(mi1\fR\&.
335 See \fBattributes\fR(7) for a description of the following attributes:
343 ATTRIBUTE TYPE ATTRIBUTE VALUE
345 Interface Stability Committed
351 .BR ber_decode (3LDAP),
355 Yeong, W., Howes, T., and Hardcastle-Kille, S., "Lightweight Directory Access
356 Protocol", OSI-DS-26, April 1992.
359 Information Processing - Open Systems Interconnection - Model and Notation -
360 Service Definition - Specification of Basic Encoding Rules for Abstract Syntax
361 Notation One, International Organization for Standardization, International
366 The return values for all of these functions are declared in \fB<lber.h>\fR.