/** * Invokes the parse handler for the current path and advances to the next position in the encoded bytes. * * @param tag to inspect for internal tags * @param encoded to parse */ private void parseTag(final DERTag tag, final ByteBuffer encoded) { final int end = readLength(encoded) + encoded.position(); final int start = encoded.position(); // Invoke handlers for all permutations of current path ParseHandler handler; for (DERPath p : permutations) { handler = handlerMap.get(p); if (handler != null) { encoded.position(start).limit(end); handler.handle(this, encoded); } } if (tag.isConstructed()) { parseTags(encoded); } encoded.position(end).limit(encoded.capacity()); }
/** * Invokes the parse handler for the current path and advances to the next position in the encoded bytes. * * @param tag to inspect for internal tags * @param encoded to parse */ private void parseTag(final DERTag tag, final ByteBuffer encoded) { final int limit = encoded.limit(); final int end = readLength(encoded) + encoded.position(); final int start = encoded.position(); // Invoke handlers for all permutations of current path ParseHandler handler; for (DERPath p : permutations) { handler = handlerMap.get(p); if (handler != null) { encoded.position(start).limit(end); handler.handle(this, encoded); } } if (tag.isConstructed()) { parseTags(encoded); } encoded.limit(limit).position(end); }
/** * Invokes the parse handler for the current path and advances to the next position in the encoded bytes. * * @param tag to inspect for internal tags * @param encoded to parse */ private void parseTag(final DERTag tag, final ByteBuffer encoded) { final int limit = encoded.limit(); final int end = readLength(encoded) + encoded.position(); final int start = encoded.position(); // Invoke handlers for all permutations of current path ParseHandler handler; for (DERPath p : permutations) { handler = handlerMap.get(p); if (handler != null) { encoded.position(start).limit(end); handler.handle(this, encoded); } } if (tag.isConstructed()) { parseTags(encoded); } encoded.limit(limit).position(end); }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { if (UniversalDERTag.OID.getTagNo() != parser.readTag(encoded).getTagNo()) { throw new IllegalArgumentException("Expected OID tag"); } final int seqLimit = encoded.limit(); final int oidLength = parser.readLength(encoded); encoded.limit(encoded.position() + oidLength); final String oid = OidType.decode(encoded); encoded.limit(seqLimit); final DERTag tag = parser.readTag(encoded); parser.readLength(encoded); assertions.add(new AttributeValueAssertion(oid, new Value(tag, readBuffer(encoded)))); } });
/** * Converts bytes in the buffer to attribute value assertions by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the oid and the * limit is set beyond the last byte of attribute value data. * * @return decoded bytes as attribute value assertions */ public static AttributeValueAssertion[] decode(final ByteBuffer encoded) { final List<AttributeValueAssertion> assertions = new ArrayList<>(); final DERParser parser = new DERParser(); parser.registerHandler( "/SEQ", (parser1, encoded1) -> { if (UniversalDERTag.OID.getTagNo() != parser1.readTag(encoded1).getTagNo()) { throw new IllegalArgumentException("Expected OID tag"); } final int seqLimit = encoded1.limit(); final int oidLength = parser1.readLength(encoded1); encoded1.limit(encoded1.position() + oidLength); final String oid = OidType.decode(encoded1); encoded1.limit(seqLimit); final DERTag tag = parser1.readTag(encoded1); parser1.readLength(encoded1); assertions.add(new AttributeValueAssertion(oid, new Value(tag, readBuffer(encoded1)))); }); parser.parse(encoded); return assertions.toArray(new AttributeValueAssertion[assertions.size()]); }
/** * Converts bytes in the buffer to attribute value assertions by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the oid and the * limit is set beyond the last byte of attribute value data. * * @return decoded bytes as attribute value assertions */ public static AttributeValueAssertion[] decode(final ByteBuffer encoded) { final List<AttributeValueAssertion> assertions = new ArrayList<>(); final DERParser parser = new DERParser(); parser.registerHandler( "/SEQ", (parser1, encoded1) -> { if (UniversalDERTag.OID.getTagNo() != parser1.readTag(encoded1).getTagNo()) { throw new IllegalArgumentException("Expected OID tag"); } final int seqLimit = encoded1.limit(); final int oidLength = parser1.readLength(encoded1); encoded1.limit(encoded1.position() + oidLength); final String oid = OidType.decode(encoded1); encoded1.limit(seqLimit); final DERTag tag = parser1.readTag(encoded1); parser1.readLength(encoded1); assertions.add(new AttributeValueAssertion(oid, new Value(tag, readBuffer(encoded1)))); }); parser.parse(encoded); return assertions.toArray(new AttributeValueAssertion[assertions.size()]); }