Package org.apache.wss4j.common.crypto
Class DERDecoder
java.lang.Object
org.apache.wss4j.common.crypto.DERDecoder
- Direct Known Subclasses:
X509SubjectPublicKeyInfo
Provides the means to navigate through a DER-encoded byte array, to help
in decoding the contents.
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);
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteDER type identifier for a bit string valuestatic final byteDER type identifier for a octet string valuestatic final byteDER type identifier for a sequence value -
Constructor Summary
ConstructorsConstructorDescriptionDERDecoder(byte[] derEncoded) Construct a DERDecoder for the given byte array. -
Method Summary
Modifier and TypeMethodDescriptionvoidexpect(byte val) Confirm that the byte at the current position matches the given value.voidexpect(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.intGet the DER length at the current position.voidreset()Reset the current position to the start of the array.voidskip(int length) Advance the current position by the given number of bytes.booleantest(byte val) Test if the byte at the current position matches the given value.
-
Field Details
-
TYPE_BIT_STRING
public static final byte TYPE_BIT_STRINGDER type identifier for a bit string value- See Also:
-
TYPE_OCTET_STRING
public static final byte TYPE_OCTET_STRINGDER type identifier for a octet string value- See Also:
-
TYPE_SEQUENCE
public static final byte TYPE_SEQUENCEDER type identifier for a sequence value- See Also:
-
-
Constructor Details
-
DERDecoder
Construct a DERDecoder for the given byte array.- Parameters:
derEncoded- the DER-encoded array to decode.- Throws:
WSSecurityException- if the given array is null.
-
-
Method Details
-
reset
public void reset()Reset the current position to the start of the array. -
skip
Advance the current position by the given number of bytes.- Parameters:
length- the number of bytes to skip.- Throws:
WSSecurityException- if length is negative.
-
expect
Confirm that the byte at the current position matches the given value.- Parameters:
val- the expected next byte.- Throws:
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.
-
expect
Confirm that the byte at the current position matches the given value.- Parameters:
val- the expected next byte.- Throws:
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.
-
test
Test if the byte at the current position matches the given value.- Parameters:
val- the value to test for a match with the current byte.- Returns:
- true if the byte at the current position matches the given value.
- Throws:
WSSecurityException- if the current position is at the end of the array.
-
getLength
Get the DER length at the current position.DER length is encoded as
- If the first byte is 0x00 to 0x7F, it describes the actual length.
- If the first byte is 0x80 + n with 0<n<0x7F, the actual length is described in the following 'n' bytes.
- The length value 0x80, used only in constructed types, is defined as "indefinite length".
- Returns:
- the length, -1 for indefinite length.
- Throws:
WSSecurityException- if the current position is at the end of the array or there is an incomplete length specification.
-
getBytes
Return an array of bytes from the current position.- Parameters:
length- the number of bytes to return.- Returns:
- an array of the requested number of bytes from the current position.
- Throws:
WSSecurityException- if the current position is at the end of the array, or the length is negative.
-