home *** CD-ROM | disk | FTP | other *** search
- package sun.security.util;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Date;
- import java.util.Vector;
-
- public class DerInputStream {
- DerInputBuffer buffer;
-
- public DerInputStream(byte[] var1) {
- this.buffer = new DerInputBuffer(var1);
- this.buffer.mark(Integer.MAX_VALUE);
- }
-
- public DerInputStream(byte[] var1, int var2, int var3) {
- this.buffer = new DerInputBuffer(var1, var2, var3);
- this.buffer.mark(Integer.MAX_VALUE);
- }
-
- DerInputStream(DerInputBuffer var1) {
- this.buffer = var1;
- this.buffer.mark(Integer.MAX_VALUE);
- }
-
- public DerInputStream subStream(int var1, boolean var2) throws IOException {
- DerInputBuffer var3 = this.buffer.dup();
- var3.truncate(var1);
- if (var2) {
- this.buffer.skip((long)var1);
- }
-
- return new DerInputStream(var3);
- }
-
- public BigInt getInteger() throws IOException {
- if (this.buffer.read() != 2) {
- throw new IOException("DER input, Integer tag error");
- } else {
- return this.buffer.getUnsigned(getLength(this.buffer));
- }
- }
-
- public byte[] getBitString() throws IOException {
- if (this.buffer.read() != 3) {
- throw new IOException("DER input not an bit string");
- } else {
- int var2 = getLength(this.buffer);
- if (this.buffer.read() != 0) {
- return null;
- } else {
- --var2;
- byte[] var1 = new byte[var2];
- if (this.buffer.read(var1) != var2) {
- throw new IOException("short read of DER bit string");
- } else {
- return var1;
- }
- }
- }
- }
-
- public byte[] getOctetString() throws IOException {
- if (this.buffer.read() != 4) {
- throw new IOException("DER input not an octet string");
- } else {
- int var2 = getLength(this.buffer);
- byte[] var1 = new byte[var2];
- if (this.buffer.read(var1) != var2) {
- throw new IOException("short read of DER octet string");
- } else {
- return var1;
- }
- }
- }
-
- public void getNull() throws IOException {
- if (this.buffer.read() != 5 || this.buffer.read() != 0) {
- throw new IOException("getNull, bad data");
- }
- }
-
- public ObjectIdentifier getOID() throws IOException {
- return new ObjectIdentifier(this);
- }
-
- public DerValue[] getSequence(int var1) throws IOException {
- if (this.buffer.read() != 48) {
- throw new IOException("Sequence tag error");
- } else {
- return this.readVector(var1);
- }
- }
-
- public DerValue[] getSet(int var1) throws IOException {
- if (this.buffer.read() != 49) {
- throw new IOException("Set tag error");
- } else {
- return this.readVector(var1);
- }
- }
-
- protected DerValue[] readVector(int var1) throws IOException {
- int var2 = getLength(this.buffer);
- if (var2 == 0) {
- return null;
- } else {
- DerInputStream var3;
- if (this.buffer.available() == var2) {
- var3 = this;
- } else {
- var3 = this.subStream(var2, true);
- }
-
- Vector var4 = new Vector(var1, 5);
-
- do {
- DerValue var5 = new DerValue(var3.buffer);
- var4.addElement(var5);
- } while(var3.available() > 0);
-
- if (var3.available() != 0) {
- throw new IOException("extra data at end of vector");
- } else {
- int var7 = var4.size();
- DerValue[] var8 = new DerValue[var7];
-
- for(int var6 = 0; var6 < var7; ++var6) {
- var8[var6] = (DerValue)var4.elementAt(var6);
- }
-
- return var8;
- }
- }
- }
-
- public DerValue getDerValue() throws IOException {
- return new DerValue(this.buffer);
- }
-
- public Date getUTCTime() throws IOException {
- if (this.buffer.read() != 23) {
- throw new IOException("DER input, UTCtime tag invalid ");
- } else if (this.buffer.available() < 12) {
- throw new IOException("DER input, UTCtime short input");
- } else {
- int var1 = getLength(this.buffer);
- if (var1 >= 11 && var1 <= 17) {
- int var2 = 10 * Character.digit((char)this.buffer.read(), 10);
- var2 += Character.digit((char)this.buffer.read(), 10);
- if (var2 < 80) {
- var2 += 100;
- }
-
- int var3 = 10 * Character.digit((char)this.buffer.read(), 10);
- var3 += Character.digit((char)this.buffer.read(), 10);
- --var3;
- int var4 = 10 * Character.digit((char)this.buffer.read(), 10);
- var4 += Character.digit((char)this.buffer.read(), 10);
- int var5 = 10 * Character.digit((char)this.buffer.read(), 10);
- var5 += Character.digit((char)this.buffer.read(), 10);
- int var6 = 10 * Character.digit((char)this.buffer.read(), 10);
- var6 += Character.digit((char)this.buffer.read(), 10);
- var1 -= 10;
- int var19;
- if (var1 != 3 && var1 != 7) {
- var19 = 0;
- } else {
- var19 = 10 * Character.digit((char)this.buffer.read(), 10);
- var19 += Character.digit((char)this.buffer.read(), 10);
- var1 -= 2;
- }
-
- if (var3 >= 0 && var4 > 0 && var3 <= 11 && var4 <= 31 && var5 < 24 && var6 < 60 && var19 < 60) {
- long var8 = Date.UTC(var2, var3, var4, var5, var6, var19);
- if (var1 != 1 && var1 != 5) {
- throw new IOException("Parse UTC time, invalid offset");
- } else {
- switch (this.buffer.read()) {
- case 43:
- int var21 = 10 * Character.digit((char)this.buffer.read(), 10);
- var21 += Character.digit((char)this.buffer.read(), 10);
- int var24 = 10 * Character.digit((char)this.buffer.read(), 10);
- var24 += Character.digit((char)this.buffer.read(), 10);
- if (var21 >= 24 || var24 >= 60) {
- throw new IOException("Parse UTCtime, +hhmm");
- }
-
- var8 += (long)((var21 * 60 + var24) * 60 * 1000);
- break;
- case 45:
- int var10 = 10 * Character.digit((char)this.buffer.read(), 10);
- var10 += Character.digit((char)this.buffer.read(), 10);
- int var11 = 10 * Character.digit((char)this.buffer.read(), 10);
- var11 += Character.digit((char)this.buffer.read(), 10);
- if (var10 >= 24 || var11 >= 60) {
- throw new IOException("Parse UTCtime, -hhmm");
- }
-
- var8 -= (long)((var10 * 60 + var11) * 60 * 1000);
- case 90:
- break;
- default:
- throw new IOException("Parse UTCtime, garbage offset");
- }
-
- return new Date(var8);
- }
- } else {
- throw new IOException("Parse UTC time, invalid format");
- }
- } else {
- throw new IOException("DER getUTCTime length error");
- }
- }
- }
-
- int getByte() throws IOException {
- return 255 & this.buffer.read();
- }
-
- int peekByte() throws IOException {
- return this.buffer.peek();
- }
-
- int getLength() throws IOException {
- return getLength(this.buffer);
- }
-
- static int getLength(InputStream var0) throws IOException {
- int var2 = var0.read();
- int var1;
- if ((var2 & 128) == 0) {
- var1 = var2;
- } else {
- var2 &= 127;
- if (var2 <= 0 || var2 > 4) {
- throw new IOException("DerInput.getLength(): lengthTag=" + var2 + ", " + (var2 == 0 ? "Indefinite length encoding not supported or incorrect DER encoding." : "too big."));
- }
-
- for(var1 = 0; var2 > 0; --var2) {
- var1 <<= 8;
- var1 += 255 & var0.read();
- }
- }
-
- return var1;
- }
-
- public void mark(int var1) {
- this.buffer.mark(var1);
- }
-
- public void reset() {
- this.buffer.reset();
- }
-
- public int available() {
- return this.buffer.available();
- }
- }
-