62 |
* |
* |
63 |
* @author Casey Marshall (csm@gnu.org) |
* @author Casey Marshall (csm@gnu.org) |
64 |
*/ |
*/ |
65 |
public final class DERReader implements DER |
public class DERReader implements DER |
66 |
{ |
{ |
67 |
|
|
68 |
// Fields. |
// Fields. |
69 |
// ------------------------------------------------------------------------ |
// ------------------------------------------------------------------------ |
70 |
|
|
71 |
private InputStream in; |
protected InputStream in; |
72 |
|
|
73 |
private final ByteArrayOutputStream encBuf; |
protected final ByteArrayOutputStream encBuf; |
74 |
|
|
75 |
// Constructor. |
// Constructor. |
76 |
// ------------------------------------------------------------------------ |
// ------------------------------------------------------------------------ |
185 |
return value; |
return value; |
186 |
} |
} |
187 |
|
|
188 |
|
protected int readLength() throws IOException |
189 |
|
{ |
190 |
|
int i = in.read(); |
191 |
|
if (i == -1) |
192 |
|
throw new EOFException(); |
193 |
|
encBuf.write(i); |
194 |
|
if ((i & ~0x7F) == 0) |
195 |
|
{ |
196 |
|
return i; |
197 |
|
} |
198 |
|
else if (i < 0xFF) |
199 |
|
{ |
200 |
|
byte[] octets = new byte[i & 0x7F]; |
201 |
|
in.read(octets); |
202 |
|
encBuf.write(octets); |
203 |
|
return new BigInteger(1, octets).intValue(); |
204 |
|
} |
205 |
|
throw new DEREncodingException(); |
206 |
|
} |
207 |
|
|
208 |
// Own methods. |
// Own methods. |
209 |
// ------------------------------------------------------------------------ |
// ------------------------------------------------------------------------ |
210 |
|
|
256 |
} |
} |
257 |
} |
} |
258 |
|
|
|
private int readLength() throws IOException |
|
|
{ |
|
|
int i = in.read(); |
|
|
if (i == -1) |
|
|
throw new EOFException(); |
|
|
encBuf.write(i); |
|
|
if ((i & ~0x7F) == 0) |
|
|
{ |
|
|
return i; |
|
|
} |
|
|
else if (i < 0xFF) |
|
|
{ |
|
|
byte[] octets = new byte[i & 0x7F]; |
|
|
in.read(octets); |
|
|
encBuf.write(octets); |
|
|
return new BigInteger(1, octets).intValue(); |
|
|
} |
|
|
throw new DEREncodingException(); |
|
|
} |
|
|
|
|
259 |
private static String makeString(int tag, byte[] value) |
private static String makeString(int tag, byte[] value) |
260 |
throws IOException |
throws IOException |
261 |
{ |
{ |