0N/A * Copyright (c) 1999, 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 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/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. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @author Jagane Sundar 0N/A * @author Scott Seligman 0N/A // When buf is full, expand its size by the following factor. 0N/A * Creates a BER buffer for encoding. 0N/A * Creates a BER buffer of a specified size for encoding. 0N/A * Specify the initial bufsize. Buffer will be expanded as needed. 0N/A * @param bufsize The number of bytes for the buffer. 0N/A * Resets encoder to state when newly constructed. Zeros out 0N/A * internal data structures. 0N/A// ------------------ Accessor methods ------------ 0N/A * Gets the number of encoded bytes in this BER buffer. 0N/A * Gets the buffer that contains the BER encoding. Throws an 0N/A * exception if unmatched beginSeq() and endSeq() pairs were 0N/A * encountered. Not entire buffer contains encoded bytes. 0N/A * Use getDataLen() to determine number of encoded bytes. 0N/A * Use getBuffer(true) to get rid of excess bytes in array. 0N/A * @throws IllegalStateException If buffer contains unbalanced sequence. 0N/A * Gets the buffer that contains the BER encoding, trimming unused bytes. 0N/A * @throws IllegalStateException If buffer contains unbalanced sequence. 0N/A// -------------- encoding methods ------------- 0N/A * Begin encoding a sequence with a tag. 0N/A // Double the size of the SEQUENCE array if it overflows 0N/A // Save space for sequence length. 0N/A // %%% Currently we save enough space for sequences up to 64k. 0N/A // For larger sequences we'll need to shift the data to the right 0N/A // in endSeq(). If we could instead pad the length field with 0N/A // zeros, it would be a big win. * Terminate a BER sequence. }
else if (
len <=
0xff) {
}
else if (
len <=
0xffff) {
}
else if (
len <=
0xffffff) {
* Shifts contents of buf in the range [start,start+len) a specified amount. * Positive shift value means shift to the right. private void deleteByte() { * BER integer ::= 0x02 berlength byte {byte}* * Encodes an int and a tag. * BER integer w tag ::= tag berlength byte {byte}* // encodes an int using numbytes for the actual encoding. // integer ::= 0x02 asnlength byte {byte}* * BER boolean ::= 0x01 0x01 {0xff|0x00} * Encodes a boolean and a tag * BER boolean w TAG ::= tag 0x01 {0xff|0x00} buf[
offset++] = b ? (
byte)
0xff : (
byte)
0x00;
* BER string ::= 0x04 strlen byte1 byte2... * The string is converted into bytes using UTF-8 or ISO-Latin-1. * Encodes a string and a tag. * BER string w TAG ::= tag strlen byte1 byte2... * Encodes a portion of an octet string and a tag. * Encodes an octet string and a tag. }
else if (
len <=
0xff) {
}
else if (
len <=
0xffff) {
}
else if (
len <=
0xffffff) {
* Encodes an array of strings. private void encodeNull() { * Ensures that there are at least "len" unused bytes in "buf". * When more space is needed "buf" is expanded by a factor of * BUF_GROWTH_FACTOR, then "len" bytes are added if "buf" still // Only copy bytes in the range [0, offset)