public class DERDecoder extends Object
It maintains a "current position" in the array that advances with each operation, providing a simple means to handle the type-length-value encoding of DER. For example
decoder.expect(TYPE); int length = decoder.getLength(); byte[] value = decoder.getBytes(len);
Modifier and Type | Field and Description |
---|---|
static byte |
TYPE_BIT_STRING
DER type identifier for a bit string value
|
static byte |
TYPE_OCTET_STRING
DER type identifier for a octet string value
|
static byte |
TYPE_SEQUENCE
DER type identifier for a sequence value
|
Constructor and Description |
---|
DERDecoder(byte[] derEncoded)
Construct a DERDecoder for the given byte array.
|
Modifier and Type | Method and Description |
---|---|
void |
expect(byte val)
Confirm that the byte at the current position matches the given value.
|
void |
expect(int val)
Confirm that the byte at the current position matches the given value.
|
byte[] |
getBytes(int length)
Return an array of bytes from the current position.
|
int |
getLength()
Get the DER length at the current position.
|
void |
reset()
Reset the current position to the start of the array.
|
void |
skip(int length)
Advance the current position by the given number of bytes.
|
boolean |
test(byte val)
Test if the byte at the current position matches the given value.
|
public static final byte TYPE_BIT_STRING
public static final byte TYPE_OCTET_STRING
public static final byte TYPE_SEQUENCE
public DERDecoder(byte[] derEncoded) throws WSSecurityException
derEncoded
- the DER-encoded array to decode.WSSecurityException
- if the given array is null.public void reset()
public void skip(int length) throws WSSecurityException
length
- the number of bytes to skip.WSSecurityException
- if length is negative.public void expect(int val) throws WSSecurityException
val
- the expected next byte.WSSecurityException
- if the current position is at the end of the array, or if the
byte at the current position doesn't match the expected value.public void expect(byte val) throws WSSecurityException
val
- the expected next byte.WSSecurityException
- if the current position is at the end of the array, or if the
byte at the current position doesn't match the expected value.public boolean test(byte val) throws WSSecurityException
val
- the value to test for a match with the current byte.WSSecurityException
- if the current position is at the end of
the array.public int getLength() throws WSSecurityException
DER length is encoded as
WSSecurityException
- if the current position is at the end of the array or there is
an incomplete length specification.public byte[] getBytes(int length) throws WSSecurityException
length
- the number of bytes to return.WSSecurityException
- if the current position is at the end of the array, or the
length is negative.Copyright © 2017 JBoss by Red Hat. All rights reserved.