2362N/A * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The <CODE>BerEncoder</CODE> class is used for encoding data using BER. 0N/A * A <CODE>BerEncoder</CODE> needs to be set up with a byte buffer. The encoded 0N/A * data are stored in this byte buffer. 0N/A * NOTE : the buffer is filled from end to start. This means the caller 0N/A * needs to encode its data in the reverse order. 0N/A * <p><b>This API is a Sun Microsystems internal API and is subject 0N/A * to change without notice.</b></p> 0N/A * Constructs a new encoder and attaches it to the specified byte string. 0N/A * @param b The byte string containing the encoded data. 0N/A * Trim the encoding data and returns the length of the encoding. 0N/A * The encoder does backward encoding : so the bytes buffer is 0N/A * filled from end to start. The encoded data must be shift before 0N/A * the buffer can be used. This is the purpose of the <CODE>trim</CODE> method. 0N/A * After a call to the <CODE>trim</CODE> method, the encoder is reinitialized and <CODE>putXXX</CODE> 0N/A * overwrite any existing encoded data. 0N/A * @return The length of the encoded data. 0N/A // for (int i = start ; i < bytes.length ; i++) { 0N/A // bytes[i-start] = bytes[i] ; 0N/A * @param v The integer to encode. 0N/A * Put an integer with the specified tag. 0N/A * @param v The integer to encode. 0N/A * @param tag The tag to encode. 0N/A * Put an integer expressed as a long. 0N/A * @param v The long to encode. 0N/A * Put an integer expressed as a long with the specified tag. 0N/A * @param v The long to encode 0N/A * @param tag The tag to encode. 0N/A * Put an octet string. 0N/A * @param s The bytes to encode 0N/A * Put an octet string with a specified tag. 0N/A * @param s The bytes to encode 0N/A * @param tag The tag to encode. 0N/A * Put an object identifier. 0N/A * @param s The oid to encode. 0N/A * Put an object identifier with a specified tag. 0N/A * @param s The integer to encode. 0N/A * @param tag The tag to encode. 0N/A * Put a <CODE>NULL</CODE> value. 0N/A * Put a <CODE>NULL</CODE> value with a specified tag. 0N/A * @param tag The tag to encode. 0N/A * Put an <CODE>ANY</CODE> value. In fact, this method does not encode anything. 0N/A * It simply copies the specified bytes into the encoding. 0N/A * @param s The encoding of the <CODE>ANY</CODE> value. 0N/A * Put an <CODE>ANY</CODE> value. Only the first <CODE>byteCount</CODE> are considered. 0N/A * @param s The encoding of the <CODE>ANY</CODE> value. 0N/A * @param byteCount The number of bytes of the encoding. 0N/A // for (int i = byteCount - 1 ; i >= 0 ; i--) { 0N/A // bytes[--start] = s[i] ; 0N/A * The encoder push the current position on its stack. 0N/A * The decode pull the stack to know the end of the current sequence. 0N/A * Close a sequence with the specified tag. 0N/A // Some standard tags 0N/A ////////////////////////// PROTECTED /////////////////////////////// 0N/A * Put a tag and move the current position backward. 0N/A * @param tag The tag to encode. 0N/A * Put a length and move the current position backward. 0N/A * @param length The length to encode. 0N/A * Put an integer value and move the current position backward. 0N/A * @param v The integer to encode. 0N/A * Put an integer value expressed as a long. 0N/A * @param v The integer to encode. 0N/A * Put a byte string and move the current position backward. 0N/A * @param s The byte string to encode. 0N/A // for (int i = s.length - 1 ; i >= 0 ; i--) { 0N/A // bytes[--start] = s[i] ; 0N/A * Put an oid and move the current position backward. 0N/A * @param s The oid to encode. 0N/A // bugId 4641746: 0, 1, and 2 are legal values. 0N/A if ((
slength <
2) || (s[
0] >
2) || (s[
1] >=
40)) {
0N/A // This is the byte array containing the encoding. 0N/A // This is the index of the first byte of the encoding. 0N/A // It is initialized to <CODE>bytes.length</CODE> and decrease each time 0N/A // an value is put in the encoder. 0N/A // This is the stack where end of sequences are kept. 0N/A // A value is computed and pushed in it each time the <CODE>openSequence</CODE> method 0N/A // A value is pulled and checked each time the <CODE>closeSequence</CODE> method is called.