/** * Creates a new abstract der type. * * @param tag to encode for this type */ public AbstractDERType(final DERTag tag) { derTag = tag.getTagByte(); }
/** * Creates a new octet string type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public OctetStringType(final DERTag tag, final byte[] item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = item; }
@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)))); } });
/** * 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: * * <pre>size = 2^n</pre> * * <p>where n is the path length.</p> * * @param tag to add to path. * @param index of tag relative to parent. */ private void addTag(final DERTag tag, final int index) { if (permutations.isEmpty()) { permutations.add(new DERPath().pushNode(tag.name())); permutations.add(new DERPath().pushNode(tag.name(), index)); } else { final Collection<DERPath> generation = new ArrayDeque<>(permutations.size()); for (DERPath p : permutations) { generation.add(new DERPath(p).pushNode(tag.name())); p.pushNode(tag.name(), index); } permutations.addAll(generation); } }
/** * 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()]); }
/** * 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: * * <pre>size = 2^n</pre> * * <p>where n is the path length.</p> * * @param tag to add to path. * @param index of tag relative to parent. */ private void addTag(final DERTag tag, final int index) { if (permutations.isEmpty()) { permutations.add(new DERPath().pushNode(tag.name())); permutations.add(new DERPath().pushNode(tag.name(), index)); } else { final Collection<DERPath> generation = new ArrayDeque<>(permutations.size()); for (DERPath p : permutations) { generation.add(new DERPath(p).pushNode(tag.name())); p.pushNode(tag.name(), index); } permutations.addAll(generation); } }
/** * Creates a new octet string type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public OctetStringType(final DERTag tag, final byte[] item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = item; }
/** * Creates a new abstract der type. * * @param tag to encode for this type */ public AbstractDERType(final DERTag tag) { derTag = tag.getTagByte(); }
/** * 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()]); }
/** * 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: * * <pre>size = 2^n</pre> * * <p>where n is the path length.</p> * * @param tag to add to path. * @param index of tag relative to parent. */ private void addTag(final DERTag tag, final int index) { if (permutations.isEmpty()) { permutations.add(new DERPath().pushNode(tag.name())); permutations.add(new DERPath().pushNode(tag.name(), index)); } else { final Collection<DERPath> generation = new ArrayDeque<>(permutations.size()); for (DERPath p : permutations) { generation.add(new DERPath(p).pushNode(tag.name())); p.pushNode(tag.name(), index); } permutations.addAll(generation); } }
/** * Creates a new octet string type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public OctetStringType(final DERTag tag, final byte[] item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = item; }
/** * Creates a new abstract der type. * * @param tag to encode for this type */ public AbstractDERType(final DERTag tag) { derTag = tag.getTagByte(); }
/** * Creates a new integer type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public IntegerType(final DERTag tag, final BigInteger item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = item.toByteArray(); }
/** * Creates a new sequence encoder. * * @param tag der tag associated with this type * @param encoders to encode in this sequence */ public ConstructedDEREncoder(final DERTag tag, final DEREncoder... encoders) { super(tag); if (!tag.isConstructed()) { throw new IllegalArgumentException("DER tag must be constructed"); } if (encoders == null || encoders.length == 0) { throw new IllegalArgumentException("Encoders cannot be null or empty"); } derEncoders = encoders; }
/** * Creates a new sequence encoder. * * @param tag der tag associated with this type * @param encoders to encode in this sequence */ public ConstructedDEREncoder(final DERTag tag, final DEREncoder... encoders) { super(tag); if (!tag.isConstructed()) { throw new IllegalArgumentException("DER tag must be constructed"); } if (encoders == null || encoders.length == 0) { throw new IllegalArgumentException("Encoders cannot be null or empty"); } derEncoders = encoders; }
/** * Creates a new integer type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public IntegerType(final DERTag tag, final BigInteger item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = item.toByteArray(); }
/** * Creates a new integer type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public IntegerType(final DERTag tag, final BigInteger item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = item.toByteArray(); }
/** * Creates a new integer type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public IntegerType(final DERTag tag, final int item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = BigInteger.valueOf(item).toByteArray(); }
/** * Creates a new integer type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public IntegerType(final DERTag tag, final int item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = BigInteger.valueOf(item).toByteArray(); }
/** * Creates a new integer type. * * @param tag der tag associated with this type * @param item to DER encode * * @throws IllegalArgumentException if the der tag is constructed */ public IntegerType(final DERTag tag, final int item) { super(tag); if (tag.isConstructed()) { throw new IllegalArgumentException("DER tag must not be constructed"); } derItem = BigInteger.valueOf(item).toByteArray(); }