@Override public void decode(final byte[] encoded) { final DERParser parser = new DERParser(); parser.registerHandler(GenPasswdHandler.PATH, new GenPasswdHandler(this)); parser.parse(ByteBuffer.wrap(encoded)); }
/** * Reads the supplied DER encoded bytes and invokes handlers as configured paths are encountered. * * @param encoded to parse */ private void parseTags(final ByteBuffer encoded) { int index = 0; while (encoded.position() < encoded.limit()) { final DERTag tag = readTag(encoded); if (tag != null) { addTag(tag, index++); parseTag(tag, encoded); removeTag(); } } }
/** * Parse a DER-encoded data structure by calling registered handlers when points of interest are encountered in the * parse tree. * * @param encoded DER-encoded bytes. */ public void parse(final ByteBuffer encoded) { parseTags(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()]); }
/** * 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()); }
@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)))); } });
/** * See {@link #registerHandler(DERPath, ParseHandler)}. * * @param path to register * @param handler to associate with the path */ public void registerHandler(final String path, final ParseHandler handler) { registerHandler(new DERPath(path), handler); }
/** * 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()]); }
/** * 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); }
/** * See {@link #registerHandler(DERPath, ParseHandler)}. * * @param path to register * @param handler to associate with the path */ public void registerHandler(final String path, final ParseHandler handler) { registerHandler(new DERPath(path), handler); }
@Override public void decode(final byte[] encoded) { final DERParser parser = new DERParser(); parser.registerHandler(GenPasswdHandler.PATH, new GenPasswdHandler(this)); parser.parse(ByteBuffer.wrap(encoded)); }
/** * Reads the supplied DER encoded bytes and invokes handlers as configured paths are encountered. * * @param encoded to parse */ private void parseTags(final ByteBuffer encoded) { int index = 0; while (encoded.position() < encoded.limit()) { final DERTag tag = readTag(encoded); if (tag != null) { addTag(tag, index++); parseTag(tag, encoded); removeTag(); } } }
/** * 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); }
/** * See {@link #registerHandler(DERPath, ParseHandler)}. * * @param path to register * @param handler to associate with the path */ public void registerHandler(final String path, final ParseHandler handler) { registerHandler(new DERPath(path), handler); }
/** * Parse a DER-encoded data structure by calling registered handlers when points of interest are encountered in the * parse tree. * * @param encoded DER-encoded bytes. */ public void parse(final ByteBuffer encoded) { parseTags(encoded); }
@Override public void decode(final byte[] encoded) { final DERParser parser = new DERParser(); parser.registerHandler(GenPasswdHandler.PATH, new GenPasswdHandler(this)); parser.parse(ByteBuffer.wrap(encoded)); }
/** * Reads the supplied DER encoded bytes and invokes handlers as configured paths are encountered. * * @param encoded to parse */ private void parseTags(final ByteBuffer encoded) { int index = 0; while (encoded.position() < encoded.limit()) { final DERTag tag = readTag(encoded); if (tag != null) { addTag(tag, index++); parseTag(tag, encoded); removeTag(); } } }
/** * Parse a DER-encoded data structure by calling registered handlers when points of interest are encountered in the * parse tree. * * @param encoded DER-encoded bytes. */ public void parse(final ByteBuffer encoded) { parseTags(encoded); }
@Override public void decode(final byte[] berValue) { logger.trace("decoding control: {}", LdapUtils.base64Encode(berValue)); final DERParser parser = new DERParser(); parser.registerHandler(SizeHandler.PATH, new SizeHandler(this)); parser.registerHandler(CookieHandler.PATH, new CookieHandler(this)); parser.parse(ByteBuffer.wrap(berValue)); }
/** * Converts bytes in the buffer to RDNs 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 RDN and the * limit is set beyond the last byte of the RDN. * * @return decoded bytes as RDNs */ public static RDN[] decode(final ByteBuffer encoded) { final List<RDN> rdns = new ArrayList<>(); final DERParser parser = new DERParser(); parser.registerHandler( "/SEQ/SET", new ParseHandler() { @Override public void handle(final DERParser parser, final ByteBuffer encoded) { rdns.add(new RDN(AttributeValueAssertion.decode(encoded.slice()))); encoded.position(encoded.limit()); } }); parser.parse(encoded); return rdns.toArray(new RDN[rdns.size()]); }