public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { informationReport = new InformationReport(); codeLength += informationReport.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
@Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@Override public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; if (withTag) { codeLength += tag.decodeAndCheck(is); } codeLength += super.decode(is, false); return codeLength; }
@Test public void twoByteEncoding() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); BerTag berIdentifier = new BerTag(BerTag.APPLICATION_CLASS, BerTag.PRIMITIVE, 31); int length = berIdentifier.encode(berBAOStream); Assert.assertEquals(2, length); byte[] expectedBytes = new byte[] { 0x5f, 0x1f }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
private void writeEncodeTag(Tag tag) throws IOException { int typeStructure; if (tag.typeStructure == TypeStructure.CONSTRUCTED) { typeStructure = BerTag.CONSTRUCTED; } else { typeStructure = BerTag.PRIMITIVE; } BerTag berTag = new BerTag(getTagClassId(tag.tagClass.toString()), typeStructure, tag.value); write("// write tag: " + tag.tagClass + "_CLASS, " + tag.typeStructure + ", " + tag.value); for (int i = (berTag.tagBytes.length - 1); i >= 0; i--) { write("reverseOS.write(" + HexConverter.toHexString(berTag.tagBytes[i]) + ");"); } write("codeLength += " + berTag.tagBytes.length + ";"); }
public BerTag(int identifierClass, int primitive, int tagNumber) { this.tagClass = identifierClass; this.primitive = primitive; this.tagNumber = tagNumber; code(); }
private void writeEncodeTag(Tag tag) throws IOException { int typeStructure; if (tag.typeStructure == TypeStructure.CONSTRUCTED) { typeStructure = BerTag.CONSTRUCTED; } else { typeStructure = BerTag.PRIMITIVE; } BerTag berTag = new BerTag(getTagClassId(tag.tagClass.toString()), typeStructure, tag.value); write("// write tag: " + tag.tagClass + "_CLASS, " + tag.typeStructure + ", " + tag.value); for (int i = (berTag.tagBytes.length - 1); i >= 0; i--) { write("reverseOS.write(" + HexConverter.toHexString(berTag.tagBytes[i]) + ");"); } write("codeLength += " + berTag.tagBytes.length + ";"); }
public BerTag(int identifierClass, int primitive, int tagNumber) { this.tagClass = identifierClass; this.primitive = primitive; this.tagNumber = tagNumber; code(); }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { aeQualifierForm2 = new AEQualifierForm2(); codeLength += aeQualifierForm2.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding BerChoice: Tag matched to no item."); }
@Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@Override public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; if (withTag) { codeLength += tag.decodeAndCheck(is); } codeLength += super.decode(is, false); return codeLength; }
public BerTag(int identifierClass, int primitive, int tagNumber) { this.tagClass = identifierClass; this.primitive = primitive; this.tagNumber = tagNumber; code(); }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerObjectIdentifier.tag)) { apTitleForm2 = new APTitleForm2(); codeLength += apTitleForm2.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding BerChoice: Tag matched to no item."); }
@Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@Override public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; if (withTag) { codeLength += tag.decodeAndCheck(is); } codeLength += super.decode(is, false); return codeLength; }
public int encode(OutputStream reverseOS) throws IOException { if (tagBytes == null) { code(); } for (int i = (tagBytes.length - 1); i >= 0; i--) { reverseOS.write(tagBytes[i]); } return tagBytes.length; }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerOctetString.tag)) { apTitleForm2 = new APTitleForm2(); codeLength += apTitleForm2.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
@Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@Override public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; if (withTag) { codeLength += tag.decodeAndCheck(is); } codeLength += super.decode(is, false); return codeLength; }
public int encode(OutputStream reverseOS) throws IOException { if (tagBytes == null) { code(); } for (int i = (tagBytes.length - 1); i >= 0; i--) { reverseOS.write(tagBytes[i]); } return tagBytes.length; }