Class DERParser

java.lang.Object
org.ldaptive.asn1.DERParser

public class DERParser extends Object
This class provides a SAX-like parsing facility for DER-encoded data where elements of interest in the parse tree may be registered to handlers via the registerHandler(org.ldaptive.asn1.DERPath, org.ldaptive.asn1.ParseHandler) methods. DERPath strings are used to map handlers to elements of interest.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Map<DERPath,ParseHandler>
    Handlers for DER paths.
    protected final org.slf4j.Logger
    Logger for this class.
    private final Queue<DERPath>
    Permutations of the current path.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    addTag(DERTag tag, int index)
    Add the given tag at the specified index to all permutations of the current parser path and increases the number of permutations as necessary to satisfy the following relation:
    void
    parse(DERBuffer encoded)
    Parse a DER-encoded data structure by calling registered handlers when points of interest are encountered in the parse tree.
    private void
    parseTag(DERTag tag, DERBuffer encoded)
    Invokes the parse handler for the current path and advances to the next position in the encoded bytes.
    private void
    Reads the supplied DER encoded bytes and invokes handlers as configured paths are encountered.
    int
    Reads the length of a DER-encoded value from the given byte buffer.
    readTag(DERBuffer encoded)
    Reads a DER tag from a single byte at the current position of the given buffer.
    void
    Registers the supplied handler to fire when the supplied path is encountered.
    private void
    Removes the tag at the leaf position of all permutations of the current parser path, and reduces the number of permutations as necessary to satisfy the following relation:

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
      Logger for this class.
    • handlerMap

      private final Map<DERPath,ParseHandler> handlerMap
      Handlers for DER paths.
    • permutations

      private final Queue<DERPath> permutations
      Permutations of the current path.
  • Constructor Details

    • DERParser

      public DERParser()
  • Method Details

    • registerHandler

      public void registerHandler(DERPath path, ParseHandler handler)
      Registers the supplied handler to fire when the supplied path is encountered.
      Parameters:
      path - to register
      handler - to associate with the path
    • parse

      public void parse(DERBuffer encoded)
      Parse a DER-encoded data structure by calling registered handlers when points of interest are encountered in the parse tree.
      Parameters:
      encoded - DER-encoded bytes.
    • readTag

      public DERTag readTag(DERBuffer encoded)
      Reads a DER tag from a single byte at the current position of the given buffer. The buffer position is naturally advanced one byte in this operation.
      Parameters:
      encoded - Buffer containing DER-encoded bytes positioned at tag.
      Returns:
      Tag or null if no universal tag or application-specific tag is known that matches the byte read in.
    • readLength

      public int readLength(DERBuffer encoded)
      Reads the length of a DER-encoded value from the given byte buffer. The buffer is expected to be positioned at the byte immediately following the tag byte, which is where the length byte(s) begin(s). Invocation of this method has two generally beneficial side effects:
      1. Buffer is positioned at start of value bytes.
      2. Buffer limit is set to the end of value bytes.
      Parameters:
      encoded - buffer containing DER-encoded bytes positioned at start of length byte(s).
      Returns:
      number of bytes occupied by tag value.
    • parseTags

      private void parseTags(DERBuffer encoded)
      Reads the supplied DER encoded bytes and invokes handlers as configured paths are encountered.
      Parameters:
      encoded - to parse
    • parseTag

      private void parseTag(DERTag tag, DERBuffer encoded)
      Invokes the parse handler for the current path and advances to the next position in the encoded bytes.
      Parameters:
      tag - to inspect for internal tags
      encoded - to parse
    • addTag

      private void addTag(DERTag tag, int index)
      Add the given tag at the specified index to all permutations of the current parser path and increases the number of permutations as necessary to satisfy the following relation:
      size = 2^n

      where n is the path length.

      Parameters:
      tag - to add to path.
      index - of tag relative to parent.
    • removeTag

      private void removeTag()
      Removes the tag at the leaf position of all permutations of the current parser path, and reduces the number of permutations as necessary to satisfy the following relation:
      size = 2^n

      where n is the path length.