org.apache.ws.security.components.crypto
Class DERDecoder

java.lang.Object
  extended by org.apache.ws.security.components.crypto.DERDecoder
Direct Known Subclasses:
X509SubjectPublicKeyInfo

public class DERDecoder
extends Object

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
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 Summary
DERDecoder(byte[] derEncoded)
          Construct a DERDecoder for the given byte array.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_BIT_STRING

public static final byte TYPE_BIT_STRING
DER type identifier for a bit string value

See Also:
Constant Field Values

TYPE_OCTET_STRING

public static final byte TYPE_OCTET_STRING
DER type identifier for a octet string value

See Also:
Constant Field Values

TYPE_SEQUENCE

public static final byte TYPE_SEQUENCE
DER type identifier for a sequence value

See Also:
Constant Field Values
Constructor Detail

DERDecoder

public DERDecoder(byte[] derEncoded)
           throws WSSecurityException
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 Detail

reset

public void reset()
Reset the current position to the start of the array.


skip

public void skip(int length)
          throws WSSecurityException
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

public void expect(int val)
            throws WSSecurityException
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

public void expect(byte val)
            throws WSSecurityException
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

public boolean test(byte val)
             throws WSSecurityException
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

public int getLength()
              throws WSSecurityException
Get the DER length at the current position.

DER length is encoded as

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

public byte[] getBytes(int length)
                throws WSSecurityException
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.


Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.