summaryrefslogtreecommitdiffstats
path: root/pki/base/util/src/netscape/security/util/DerInputBuffer.java
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/util/src/netscape/security/util/DerInputBuffer.java')
-rw-r--r--pki/base/util/src/netscape/security/util/DerInputBuffer.java219
1 files changed, 110 insertions, 109 deletions
diff --git a/pki/base/util/src/netscape/security/util/DerInputBuffer.java b/pki/base/util/src/netscape/security/util/DerInputBuffer.java
index 74ab9f705..7534f3d06 100644
--- a/pki/base/util/src/netscape/security/util/DerInputBuffer.java
+++ b/pki/base/util/src/netscape/security/util/DerInputBuffer.java
@@ -15,57 +15,58 @@
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
-package netscape.security.util ;
+package netscape.security.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
-
/**
* DER input buffer ... this is the main abstraction in the DER library
- * which actively works with the "untyped byte stream" abstraction. It
+ * which actively works with the "untyped byte stream" abstraction. It
* does so with impunity, since it's not intended to be exposed to the
* anyone who could violate the "typed value stream" DER model and hence
* corrupt the input stream of DER values.
- *
+ *
* @version 1.11
* @author David Brownell
*/
class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
- DerInputBuffer(byte[] buf) { super(buf); }
+ DerInputBuffer(byte[] buf) {
+ super(buf);
+ }
DerInputBuffer(byte[] buf, int offset, int len) {
super(buf, offset, len);
}
DerInputBuffer dup() {
- try {
- DerInputBuffer retval = (DerInputBuffer) clone ();
-
- retval.mark (Integer.MAX_VALUE);
- return retval;
- } catch (CloneNotSupportedException e) {
- throw new IllegalArgumentException (e.toString ());
- }
+ try {
+ DerInputBuffer retval = (DerInputBuffer) clone();
+
+ retval.mark(Integer.MAX_VALUE);
+ return retval;
+ } catch (CloneNotSupportedException e) {
+ throw new IllegalArgumentException(e.toString());
+ }
}
byte[] toByteArray() {
- int len = available();
+ int len = available();
if (len <= 0)
return null;
- byte[] retval = new byte[len];
+ byte[] retval = new byte[len];
- System.arraycopy(buf, pos, retval, 0, len);
- return retval;
+ System.arraycopy(buf, pos, retval, 0, len);
+ return retval;
}
int peek() throws IOException {
- if (pos >= count)
- throw new IOException ("out of data");
- else
- return buf [pos];
+ if (pos >= count)
+ throw new IOException("out of data");
+ else
+ return buf[pos];
}
/**
@@ -73,31 +74,31 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
* object.
*/
public boolean equals(Object other) {
- if (other instanceof DerInputBuffer)
- return equals ((DerInputBuffer) other);
- else
- return false;
+ if (other instanceof DerInputBuffer)
+ return equals((DerInputBuffer) other);
+ else
+ return false;
}
boolean equals(DerInputBuffer other) {
- if (this == other)
- return true;
-
- int max = this.available();
- if (other.available() != max)
- return false;
- for (int i = 0; i < max; i++) {
- if (this.buf [this.pos + i] != other.buf [other.pos + i]) {
- return false;
- }
- }
- return true;
+ if (this == other)
+ return true;
+
+ int max = this.available();
+ if (other.available() != max)
+ return false;
+ for (int i = 0; i < max; i++) {
+ if (this.buf[this.pos + i] != other.buf[other.pos + i]) {
+ return false;
+ }
+ }
+ return true;
}
void truncate(int len) throws IOException {
- if (len > available ())
- throw new IOException ("insufficient data");
- count = pos + len;
+ if (len > available())
+ throw new IOException("insufficient data");
+ count = pos + len;
}
/**
@@ -105,81 +106,81 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
* of bytes in this buffer.
*/
BigInt getUnsigned(int len) throws IOException {
- if (len > available ())
- throw new IOException ("short read, getInteger");
-
- /*
- * A prepended zero is used to ensure that the integer is
- * interpreted as unsigned even when the high order bit is
- * zero. We don't support signed BigInts.
- *
- * Fix this here ... BigInts aren't expected to have these,
- * and stuff like signing (sigsize = f(modulus)) misbehaves.
- */
- if (len > 1 && buf [pos] == 0) {
- len--;
- skip (1);
- }
-
- /*
- * Consume the rest of the buffer, returning its value as
- * an unsigned integer.
- */
- byte[] bytes = new byte[len];
-
- System.arraycopy (buf, pos, bytes, 0, len);
- skip (len);
- return new BigInt (bytes);
+ if (len > available())
+ throw new IOException("short read, getInteger");
+
+ /*
+ * A prepended zero is used to ensure that the integer is
+ * interpreted as unsigned even when the high order bit is
+ * zero. We don't support signed BigInts.
+ *
+ * Fix this here ... BigInts aren't expected to have these,
+ * and stuff like signing (sigsize = f(modulus)) misbehaves.
+ */
+ if (len > 1 && buf[pos] == 0) {
+ len--;
+ skip(1);
+ }
+
+ /*
+ * Consume the rest of the buffer, returning its value as
+ * an unsigned integer.
+ */
+ byte[] bytes = new byte[len];
+
+ System.arraycopy(buf, pos, bytes, 0, len);
+ skip(len);
+ return new BigInt(bytes);
}
/**
* Returns the bit string which takes up the rest of this buffer.
* This bit string must be byte-aligned.
- */
+ */
byte[] getBitString() {
- if (pos >= count || buf [pos] != 0)
- return null;
- /*
- * Just copy the data into an aligned, padded octet buffer,
- * and consume the rest of the buffer.
- */
- int len = available ();
- byte[] retval = new byte[len - 1];
-
- System.arraycopy (buf, pos + 1, retval, 0, len - 1);
- pos = count;
- return retval;
+ if (pos >= count || buf[pos] != 0)
+ return null;
+ /*
+ * Just copy the data into an aligned, padded octet buffer,
+ * and consume the rest of the buffer.
+ */
+ int len = available();
+ byte[] retval = new byte[len - 1];
+
+ System.arraycopy(buf, pos + 1, retval, 0, len - 1);
+ pos = count;
+ return retval;
+ }
+
+ /**
+ * Returns the bit string which takes up the rest of this buffer.
+ * The bit string need not be byte-aligned.
+ */
+ BitArray getUnalignedBitString() {
+ if (pos >= count)
+ return null;
+ /*
+ * Just copy the data into an aligned, padded octet buffer,
+ * and consume the rest of the buffer.
+ */
+ int len = available();
+ byte[] bits = new byte[len - 1];
+ int length = bits.length * 8 - buf[pos]; // number of valid bits
+
+ System.arraycopy(buf, pos + 1, bits, 0, len - 1);
+
+ BitArray bitArray = new BitArray(length, bits);
+ pos = count;
+ return bitArray;
+ }
+
+ /**
+ * Package-access method to optimize output operations
+ */
+ void dump(OutputStream out, int length) throws IOException {
+ if (count < mark + length)
+ throw new IOException("short DER value (encode)");
+ out.write(buf, mark, length);
}
- /**
- * Returns the bit string which takes up the rest of this buffer.
- * The bit string need not be byte-aligned.
- */
- BitArray getUnalignedBitString() {
- if (pos >= count)
- return null;
- /*
- * Just copy the data into an aligned, padded octet buffer,
- * and consume the rest of the buffer.
- */
- int len = available();
- byte[] bits = new byte[len - 1];
- int length = bits.length*8 - buf[pos]; // number of valid bits
-
- System.arraycopy(buf, pos + 1, bits, 0, len - 1);
-
- BitArray bitArray = new BitArray(length, bits);
- pos = count;
- return bitArray;
- }
-
- /**
- * Package-access method to optimize output operations
- */
- void dump(OutputStream out, int length) throws IOException {
- if (count < mark + length)
- throw new IOException ("short DER value (encode)");
- out.write(buf,mark,length);
- }
-
}