1ber_encode(3LDAP)           LDAP Library Functions           ber_encode(3LDAP)
2
3
4

NAME

6       ber_encode,   ber_alloc,   ber_printf,   ber_put_int,  ber_put_ostring,
7       ber_put_string,   ber_put_null,   ber_put_boolean,   ber_put_bitstring,
8       ber_start_seq,  ber_start_set,  ber_put_seq,  ber_put_set  - simplified
9       Basic Encoding Rules library encoding functions
10

SYNOPSIS

12       cc[ flag... ] file... -lldap[ library... ]
13       #include <lber.h>
14
15       BerElement *ber_alloc();
16
17
18       ber_printf(BerElement *ber, char **fmt[, arg... ]);
19
20
21       ber_put_int(BerElement *ber, long num, char tag);
22
23
24       ber_put_ostring(BerElement *ber, char **str, unsigned long len,
25            char tag);
26
27
28       ber_put_string(BerElement *ber, char **str, char tag);
29
30
31       ber_put_null(BerElement *ber, char tag);
32
33
34       ber_put_boolean(BerElement *ber, int bool, char tag);
35
36
37       ber_put_bitstring(BerElement *ber, char *str, int blen, char tag);
38
39
40       ber_start_seq(BerElement *ber, char tag);
41
42
43       ber_start_set(BerElement *ber, char tag);
44
45
46       ber_put_seq(BerElement *ber);
47
48
49       ber_put_set(BerElement *ber);
50
51

DESCRIPTION

53       These functions provide a subfunction interface to a simplified  imple‐
54       mentation  of  the  Basic  Encoding Rules of ASN.1.  The version of BER
55       these functions support is the one defined for the LDAP protocol.   The
56       encoding  rules  are  the  same as BER, except that  only definite form
57       lengths are used, and bitstrings and octet strings are  always  encoded
58       in  primitive  form.   In  addition,  these  lightweight  BER functions
59       restrict tags and class to fit in a single octet (this means the actual
60       tag must be less than 31). When a "tag"is specified in the descriptions
61       below, it refers to the tag, class, and primitive or constructed bit in
62       the  first octet of the encoding.  This man page describes the encoding
63       functions in the lber library.  See ber_decode(3LDAP)  for  details  on
64       the corresponding decoding functions.
65
66
67       Normally,  the only functions that need be called by an application are
68       ber_alloc(), to allocate a BER element,  and  ber_printf()  to  do  the
69       actual  encoding.   The other functions are provided for those applica‐
70       tions that need more control than  ber_printf() provides.  In  general,
71       these  functions  return the length of the element encoded, or −1 if an
72       error occurred.
73
74
75       The  ber_alloc() function is used to allocate a new BER element.
76
77
78       The  ber_printf() function is used to encode a BER element in much  the
79       same way that  sprintf(3S) works.  One important difference, though, is
80       that some state information is kept with the ber parameter so that mul‐
81       tiple calls can be made to  ber_printf() to append things to the end of
82       the BER element.   Ber_printf() writes to ber, a pointer to  a  BerEle‐
83       ment  such  as  returned by  ber_alloc(). It interprets and formats its
84       arguments according to the format string fmt.  The  format  string  can
85       contain the following characters:
86
87       b    Boolean.  An integer parameter should be supplied.  A boolean ele‐
88            ment is output.
89
90
91       B    Bitstring.  A char * pointer to the start of the bitstring is sup‐
92            plied,  followed  by  the number of bits in the bitstring.  A bit‐
93            string element is output.
94
95
96       i    Integer.  An integer parameter should  be  supplied.   An  integer
97            element is output.
98
99
100       n    Null.  No parameter is required.  A null element is output.
101
102
103       o    Octet string.  A char * is supplied, followed by the length of the
104            string pointed to.  An octet string element is output.
105
106
107       O    Octet string.  A struct berval * is  supplied.   An  octet  string
108            element is output.
109
110
111       s    Octet  string.   A  null-terminated  string is supplied.  An octet
112            string element is output, not including the trailing null octet.
113
114
115       t    Tag.  An int specifying the tag to give the next element  is  pro‐
116            vided. This works across calls.
117
118
119       v    Several  octet strings.  A null-terminated array of char * is sup‐
120            plied.  Note that a construct like '{v}' is  required  to  get  an
121            actual sequence of octet strings.
122
123
124       {    Begin sequence.  No parameter is required.
125
126
127       }    End sequence.  No parameter is required.
128
129
130       [    Begin set.  No parameter is required.
131
132
133       ]    End set.  No parameter is required.
134
135
136
137       The   ber_put_int()  function writes the integer element num to the BER
138       element ber.
139
140
141       The  ber_put_boolean() function writes the boolean value given by  bool
142       to the BER element.
143
144
145       The  ber_put_bitstring() function writes blen bits starting at str as a
146       bitstring value to the given BER element.  Note that blen is the length
147       in bits of the bitstring.
148
149
150       The  ber_put_ostring() function writes len bytes starting at str to the
151       BER element as an octet string.
152
153
154       The  ber_put_string() function writes the null-terminated string (minus
155       the terminating '') to the BER element as an octet string.
156
157
158       The  ber_put_null() function writes a  NULL element to the BER element.
159
160
161       The   ber_start_seq()  function  is used to start a sequence in the BER
162       element.  The  ber_start_set() function works similarly. The end of the
163       sequence   or   set   is   marked  by  the  nearest  matching  call  to
164       ber_put_seq() or  ber_put_set(), respectively.
165
166
167       The  ber_first_element() function is used to return the tag and  length
168       of the first element in a set or sequence.  It also returns in cookie a
169       magic cookie parameter that should be passed  to  subsequent  calls  to
170       ber_next_element(), which returns similar information.
171

EXAMPLES

173       Example  1  Assuming  the following variable declarations, and that the
174       variables have been assigned appropriately, an BER encoding of the fol‐
175       lowing ASN.1 object:
176
177               AlmostASearchRequest := SEQUENCE {
178                   baseObject      DistinguishedName,
179                   scope           ENUMERATED {
180                       baseObject    (0),
181                       singleLevel   (1),
182                       wholeSubtree  (2)
183                   },
184                   derefAliases    ENUMERATED {
185                       neverDerefaliases   (0),
186                       derefInSearching    (1),
187                       derefFindingBaseObj (2),
188                       alwaysDerefAliases  (3N)
189                   },
190                   sizelimit       INTEGER (0 .. 65535),
191                   timelimit       INTEGER (0 .. 65535),
192                   attrsOnly       BOOLEAN,
193                   attributes      SEQUENCE OF AttributeType
194               }
195
196
197
198       can be achieved like so:
199
200               int    scope, ali, size, time, attrsonly;
201               char   *dn, **attrs;
202
203               /* ... fill in values ... */
204               if ( (ber = ber_alloc()) == NULLBER )
205               /* error */
206
207               if ( ber_printf( ber, "{siiiib{v}}", dn, scope, ali,
208                   size, time, attrsonly, attrs ) == -1 )
209                       /* error */
210               else
211                       /* success */
212
213

RETURN VALUES

215       If  an  error  occurs  during encoding, ber_alloc() returns NULL; other
216       functions generally return −1.
217

ATTRIBUTES

219       See attributes(5) for a description of the following attributes:
220
221
222
223
224       ┌─────────────────────────────┬─────────────────────────────┐
225       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
226       ├─────────────────────────────┼─────────────────────────────┤
227       │Availability                 │SUNWcsl (32-bit)             │
228       ├─────────────────────────────┼─────────────────────────────┤
229       │                             │SUNWcslx (64-bit)            │
230       ├─────────────────────────────┼─────────────────────────────┤
231       │Interface Stability          │Committed                    │
232       └─────────────────────────────┴─────────────────────────────┘
233

SEE ALSO

235       ber_decode(3LDAP), attributes(5)
236
237
238       Yeong, W., Howes, T., and Hardcastle-Kille, S., "Lightweight  Directory
239       Access Protocol", OSI-DS-26, April 1992.
240
241
242       Information Processing - Open Systems Interconnection - Model and Nota‐
243       tion - Service Definition - Specification of Basic Encoding  Rules  for
244       Abstract  Syntax Notation One, International Organization for Standard‐
245       ization, International Standard 8825.
246

NOTES

248       The return values for all of these functions are declared in <lber.h>.
249
250
251
252SunOS 5.11                        6 Oct 2008                 ber_encode(3LDAP)
Impressum