blob: 0c3560a5eed2d9f71305baabeb4dbd9935ad2dfb [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.jndi.ldap;
27
28import java.io.OutputStream;
29import java.io.IOException;
30import java.io.ByteArrayInputStream;
31
32import sun.misc.HexDumpEncoder;
33
34/**
35 * Base class that defines common fields, constants, and debug method.
36 *
37 * @author Jagane Sundar
38 */
39public abstract class Ber {
40
41 protected byte buf[];
42 protected int offset;
43 protected int bufsize;
44
45 protected Ber() {
46 }
47
48 public static void dumpBER(OutputStream outStream, String tag, byte[] bytes,
49 int from, int to) {
50
51 try {
52 outStream.write('\n');
53 outStream.write(tag.getBytes("UTF8"));
54
55 new HexDumpEncoder().encodeBuffer(
56 new ByteArrayInputStream(bytes, from, to),
57 outStream);
58
59 outStream.write('\n');
60 } catch (IOException e) {
61 try {
62 outStream.write(
63 "Ber.dumpBER(): error encountered\n".getBytes("UTF8"));
64 } catch (IOException e2) {
65 // ignore
66 }
67 }
68 }
69
70 ////////////////////////////////////////////////////////////////////////////
71 //
72 // some ASN defines
73 //
74 ////////////////////////////////////////////////////////////////////////////
75
76 public static final int ASN_BOOLEAN = 0x01;
77 public static final int ASN_INTEGER = 0x02;
78 public static final int ASN_BIT_STRING = 0x03;
79 public static final int ASN_SIMPLE_STRING = 0x04;
80 public static final int ASN_OCTET_STR = 0x04;
81 public static final int ASN_NULL = 0x05;
82 public static final int ASN_OBJECT_ID = 0x06;
83 public static final int ASN_SEQUENCE = 0x10;
84 public static final int ASN_SET = 0x11;
85
86
87 public static final int ASN_PRIMITIVE = 0x00;
88 public static final int ASN_UNIVERSAL = 0x00;
89 public static final int ASN_CONSTRUCTOR = 0x20;
90 public static final int ASN_APPLICATION = 0x40;
91 public static final int ASN_CONTEXT = 0x80;
92 public static final int ASN_PRIVATE = 0xC0;
93
94 public static final int ASN_ENUMERATED = 0x0a;
95
96 final static class EncodeException extends IOException {
97 EncodeException(String msg) {
98 super(msg);
99 }
100 }
101
102 final static class DecodeException extends IOException {
103 DecodeException(String msg) {
104 super(msg);
105 }
106 }
107}