001: /*
002: * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.jndi.ldap;
027:
028: import java.io.OutputStream;
029: import java.io.IOException;
030: import java.io.ByteArrayInputStream;
031:
032: import sun.misc.HexDumpEncoder;
033:
034: /**
035: * Base class that defines common fields, constants, and debug method.
036: *
037: * @author Jagane Sundar
038: */
039: public abstract class Ber {
040:
041: protected byte buf[];
042: protected int offset;
043: protected int bufsize;
044:
045: protected Ber() {
046: }
047:
048: public static void dumpBER(OutputStream outStream, String tag,
049: byte[] bytes, int from, int to) {
050:
051: try {
052: outStream.write('\n');
053: outStream.write(tag.getBytes("UTF8"));
054:
055: new HexDumpEncoder().encodeBuffer(new ByteArrayInputStream(
056: bytes, from, to), outStream);
057:
058: outStream.write('\n');
059: } catch (IOException e) {
060: try {
061: outStream.write("Ber.dumpBER(): error encountered\n"
062: .getBytes("UTF8"));
063: } catch (IOException e2) {
064: // ignore
065: }
066: }
067: }
068:
069: ////////////////////////////////////////////////////////////////////////////
070: //
071: // some ASN defines
072: //
073: ////////////////////////////////////////////////////////////////////////////
074:
075: public static final int ASN_BOOLEAN = 0x01;
076: public static final int ASN_INTEGER = 0x02;
077: public static final int ASN_BIT_STRING = 0x03;
078: public static final int ASN_SIMPLE_STRING = 0x04;
079: public static final int ASN_OCTET_STR = 0x04;
080: public static final int ASN_NULL = 0x05;
081: public static final int ASN_OBJECT_ID = 0x06;
082: public static final int ASN_SEQUENCE = 0x10;
083: public static final int ASN_SET = 0x11;
084:
085: public static final int ASN_PRIMITIVE = 0x00;
086: public static final int ASN_UNIVERSAL = 0x00;
087: public static final int ASN_CONSTRUCTOR = 0x20;
088: public static final int ASN_APPLICATION = 0x40;
089: public static final int ASN_CONTEXT = 0x80;
090: public static final int ASN_PRIVATE = 0xC0;
091:
092: public static final int ASN_ENUMERATED = 0x0a;
093:
094: final static class EncodeException extends IOException {
095: EncodeException(String msg) {
096: super (msg);
097: }
098: }
099:
100: final static class DecodeException extends IOException {
101: DecodeException(String msg) {
102: super(msg);
103: }
104: }
105: }
|