mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
21.47.2013 d13f4bb71bcd9e903cd87e6f2625a9f8dc1b5ed6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.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]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2012 Forgerock AS
 */
package org.opends.server.protocols.asn1;
 
 
 
import java.io.Closeable;
import java.io.IOException;
 
import org.opends.server.types.ByteString;
import org.opends.server.types.ByteStringBuilder;
 
 
/**
 * An interface for decoding ASN.1 elements from a data source.
 * <p>
 * Methods for creating {@link ASN1Reader}s are provided in the
 * {@link ASN1} class.
 */
public interface ASN1Reader extends Closeable
{
 
  /**
   * Closes this ASN.1 reader.
   *
   * @throws IOException if an I/O error occurs
   */
  void close() throws IOException;
 
 
 
  /**
   * Determines if a complete ASN.1 element is waiting to be read.
   *
   * @return <code>true</code> if another complete element is available or
   *         <code>false</code> otherwise.
   * @throws ASN1Exception If an error occurs while trying to decode
   *                       an ASN1 element.
   */
  public boolean elementAvailable() throws ASN1Exception;
 
 
 
  /**
   * Determines if at least one ASN.1 element is waiting to be read.
   *
   * @return <code>true</code> if another element is available or
   *         <code>false</code> if the EOF is reached.
   * @throws ASN1Exception
   *           If an error occurs while trying to decode an ASN1
   *           element.
   */
  boolean hasNextElement() throws ASN1Exception;
 
 
 
  /**
   * Gets the data length of the next element without actually reading
   * the element and advancing the cursor.
   *
   * @return The data length of the next element or -1 if the EOF is
   *         encountered.
   * @throws ASN1Exception
   *           If an error occurs while determining the length.
   */
  int peekLength() throws ASN1Exception;
 
 
 
  /**
   * Gets the BER type of the next element without actually reading
   * the element and advancing the cursor.
   *
   * @return The BER type of the next element or -1 if the EOF is
   *         encountered.
   * @throws ASN1Exception
   *           If an error occurs while determining the BER type.
   */
  byte peekType() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as a boolean and advance the cursor.
   *
   * @return The decoded boolean value.
   * @throws ASN1Exception
   *           If the element cannot be decoded as a boolean.
   */
  boolean readBoolean() throws ASN1Exception;
 
 
 
  /**
   * Finishes reading an explicit tag. Any elements not read in the
   * explicit tag will be discarded.
   *
   * @throws ASN1Exception
   *           If an error occurs while advancing to the end of the
   *           explicit tag.
   */
  void readEndExplicitTag() throws ASN1Exception;
 
 
 
  /**
   * Finishes reading a sequence. Any elements not read in the
   * sequence will be discarded.
   *
   * @throws ASN1Exception
   *           If an error occurs while advancing to the end of the
   *           sequence.
   */
  void readEndSequence() throws ASN1Exception;
 
 
 
  /**
   * Finishes reading a set. Any elements not read in the set will be
   * discarded.
   *
   * @throws ASN1Exception
   *           If an error occurs while advancing to the end of the set.
   */
  void readEndSet() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as an enumerated value and advances
   * the cursor.
   *
   * @return The decoded enumerated value.
   * @throws ASN1Exception
   *           If the element cannot be decoded as an enumerated value.
   */
  int readEnumerated() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as an integer and advances the
   * cursor.
   *
   * @return The decoded integer value.
   * @throws ASN1Exception
   *           If the element cannot be decoded as a integer.
   */
  long readInteger() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as a null element and advances the
   * cursor.
   *
   * @throws ASN1Exception
   *           If the element cannot be decoded as an null element.
   */
  void readNull() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as an octet string and advances the
   * cursor.
   *
   * @return The decoded octet string value represented using a
   *         {@link ByteString}.
   * @throws ASN1Exception
   *           If the element cannot be decoded as an octet string.
   */
  ByteString readOctetString() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as an octet string and advances the
   * cursor. The data will be appended to the provided
   * {@link ByteStringBuilder}.
   *
   * @param buffer
   *          The {@link ByteStringBuilder} to append the data to.
   * @throws ASN1Exception
   *           If the element cannot be decoded as an octet string.
   */
  void readOctetString(ByteStringBuilder buffer) throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as an octet string and advances the
   * cursor. The data will be decoded to a UTF-8 string. This method
   * is equivalent to:
   *
   * <pre>
   * readOctetStringAsString(&quot;UTF-8&quot;);
   * </pre>
   *
   * @return The string representation of the octet string data.
   * @throws ASN1Exception
   *           If the element cannot be decoded as an octet string.
   */
  String readOctetStringAsString() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as an octet string and advances the
   * cursor. The data will be decoded to a string using the provided
   * character set.
   *
   * @param charSet
   *          The character set to use in order to decode the data
   *          into a string.
   * @return The string representation of the octet string data.
   * @throws ASN1Exception
   *           If the element cannot be decoded as an octet string.
   */
  String readOctetStringAsString(String charSet) throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as an explicit tag. All further
   * reads will read the elements in the explicit tag until
   * {@link #readEndExplicitTag()} is called.
   *
   * @throws ASN1Exception
   *           If the next element is not an explicit tag.
   */
  void readStartExplicitTag() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as a sequence. All further reads
   * will read the elements in the sequence until
   * {@link #readEndSequence()} is called.
   *
   * @throws ASN1Exception
   *           If the next element is not a sequence.
   */
  void readStartSequence() throws ASN1Exception;
 
 
 
  /**
   * Reads the next ASN.1 element as a set. All further reads will read
   * the elements in the sequence until {@link #readEndSet()} is called.
   *
   * @throws ASN1Exception
   *           If the next element is not a set.
   */
  void readStartSet() throws ASN1Exception;
 
 
 
  /**
   * Advances this ASN.1 reader beyond the next ASN.1 element without
   * decoding it.
   *
   * @throws ASN1Exception
   *           If the next ASN.1 element could not be skipped.
   */
  void skipElement() throws ASN1Exception;
}