Skip to content

Commit

Permalink
Merge pull request #12 from kullanici0606/master
Browse files Browse the repository at this point in the history
Add ber tag factory to parser to allow custom tag creation.
  • Loading branch information
evsinev authored Oct 4, 2019
2 parents fe10490 + 1b24e35 commit 1c8d392
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/payneteasy/tlv/BerTagFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.payneteasy.tlv;

public interface BerTagFactory {
BerTag createTag(byte[] aBuf, int aOffset, int aLength);
}
20 changes: 16 additions & 4 deletions src/main/java/com/payneteasy/tlv/BerTlvParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@
*/
public class BerTlvParser {

private static final BerTagFactory DEFAULT_TAG_FACTORY = new DefaultBerTagFactory();

private final BerTagFactory tagFactory;
private final IBerTlvLogger log;

public BerTlvParser() {
this(EMPTY_LOGGER);
this(DEFAULT_TAG_FACTORY, EMPTY_LOGGER);
}

public BerTlvParser(IBerTlvLogger aLogger) {
log = aLogger;
this(DEFAULT_TAG_FACTORY, aLogger);
}


public BerTlvParser(BerTagFactory aTagFactory) {
this(aTagFactory, EMPTY_LOGGER);
}

public BerTlvParser(BerTagFactory aTagFactory, IBerTlvLogger aLogger) {
tagFactory = aTagFactory;
log = aLogger;
}

public BerTlv parseConstructed(byte[] aBuf) {
return parseConstructed(aBuf, 0, aBuf.length);
}
Expand Down Expand Up @@ -164,7 +176,7 @@ private BerTag createTag(String aLevelPadding, byte[] aBuf, int aOffset, int aLe
if(log.isDebugEnabled()) {
log.debug("{}Creating tag {}...", aLevelPadding, HexUtil.toFormattedHexString(aBuf, aOffset, aLength));
}
return new BerTag(aBuf, aOffset, aLength);
return tagFactory.createTag(aBuf, aOffset, aLength);
}

private int getTagBytesCount(byte[] aBuf, int aOffset) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/payneteasy/tlv/DefaultBerTagFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.payneteasy.tlv;

public class DefaultBerTagFactory implements BerTagFactory {

@Override
public BerTag createTag(byte[] aBuf, int aOffset, int aLength) {
return new BerTag(aBuf, aOffset, aLength);
}

}

0 comments on commit 1c8d392

Please sign in to comment.