Path: blob/master/src/java.naming/share/classes/com/sun/jndi/ldap/Ber.java
41161 views
/*1* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jndi.ldap;2627import java.io.OutputStream;28import java.io.IOException;29import java.io.ByteArrayInputStream;3031import sun.security.util.HexDumpEncoder;3233/**34* Base class that defines common fields, constants, and debug method.35*36* @author Jagane Sundar37*/38public abstract class Ber {3940protected byte buf[];41protected int offset;42protected int bufsize;4344protected Ber() {45}4647public static void dumpBER(OutputStream outStream, String tag, byte[] bytes,48int from, int to) {4950try {51outStream.write('\n');52outStream.write(tag.getBytes("UTF8"));5354new HexDumpEncoder().encodeBuffer(55new ByteArrayInputStream(bytes, from, to),56outStream);5758outStream.write('\n');59} catch (IOException e) {60try {61outStream.write(62"Ber.dumpBER(): error encountered\n".getBytes("UTF8"));63} catch (IOException e2) {64// ignore65}66}67}6869////////////////////////////////////////////////////////////////////////////70//71// some ASN defines72//73////////////////////////////////////////////////////////////////////////////7475public static final int ASN_BOOLEAN = 0x01;76public static final int ASN_INTEGER = 0x02;77public static final int ASN_BIT_STRING = 0x03;78public static final int ASN_SIMPLE_STRING = 0x04;79public static final int ASN_OCTET_STR = 0x04;80public static final int ASN_NULL = 0x05;81public static final int ASN_OBJECT_ID = 0x06;82public static final int ASN_SEQUENCE = 0x10;83public static final int ASN_SET = 0x11;848586public static final int ASN_PRIMITIVE = 0x00;87public static final int ASN_UNIVERSAL = 0x00;88public static final int ASN_CONSTRUCTOR = 0x20;89public static final int ASN_APPLICATION = 0x40;90public static final int ASN_CONTEXT = 0x80;91public static final int ASN_PRIVATE = 0xC0;9293public static final int ASN_ENUMERATED = 0x0a;9495static final class EncodeException extends IOException {96private static final long serialVersionUID = -5247359637775781768L;97EncodeException(String msg) {98super(msg);99}100}101102static final class DecodeException extends IOException {103private static final long serialVersionUID = 8735036969244425583L;104DecodeException(String msg) {105super(msg);106}107}108}109110111