@Override public void decode(byte[] content) throws IOException { decode(ByteBuffer.wrap(content)); }
@Override public void taggedEncode(ByteBuffer buffer, TaggingOption taggingOption) throws IOException { Tag taggingTag = taggingOption.getTag(!isPrimitive()); Asn1Util.encodeTag(buffer, taggingTag); int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength() : encodingLength(); Asn1Util.encodeLength(buffer, taggingBodyLen); if (taggingOption.isImplicit()) { encodeBody(buffer); } else { encode(buffer); } }
@Override protected int getHeaderLength() { try { return encodingHeaderLength(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public int encodingLength() { return getHeaderLength() + getBodyLength(); }
@Override public byte[] encode() throws IOException { int len = encodingLength(); ByteBuffer byteBuffer = ByteBuffer.allocate(len); encode(byteBuffer); byteBuffer.flip(); return byteBuffer.array(); }
@Override public void encode(ByteBuffer buffer) throws IOException { Asn1Util.encodeTag(buffer, tag()); int bodyLen = getBodyLength(); Asn1Util.encodeLength(buffer, bodyLen); encodeBody(buffer); }
@Override public void encode(ByteBuffer buffer) throws IOException { Asn1Encodeable theValue = (Asn1Encodeable) getValue(); if (theValue != null) { if (!isBlindlyDecoded) { if (decodeInfo.isTagged()) { TaggingOption taggingOption = decodeInfo.getTaggingOption(); theValue.taggedEncode(buffer, taggingOption); } else { theValue.encode(buffer); } } else { theValue.encode(buffer); } } }
public void taggedDecode(Asn1ParseResult parseResult, TaggingOption taggingOption) throws IOException { Tag expectedTaggingTagFlags = taggingOption.getTag(!isPrimitive()); Asn1ParseResult tmpParseResult = parseResult; if (!expectedTaggingTagFlags.equals(parseResult.tag())) { // Primitive but using constructed encoding if (isPrimitive() && !parseResult.isPrimitive()) { Asn1Container container = (Asn1Container) parseResult; tmpParseResult = new Asn1DerivedItem(tag(), container); } else { throw new IOException("Unexpected tag " + parseResult.tag() + ", expecting " + expectedTaggingTagFlags); } } if (taggingOption.isImplicit()) { decodeBody(tmpParseResult); } else { Asn1Container container = (Asn1Container) parseResult; tmpParseResult = container.getChildren().get(0); decode(tmpParseResult); } } }
@Override protected int encodingBodyLength() throws IOException { int allLen = 0; int fieldLen; for (int i = 0; i < fields.length; ++i) { Asn1Encodeable field = (Asn1Encodeable) fields[i]; if (field != null) { if (fieldInfos[i].isTagged()) { TaggingOption taggingOption = fieldInfos[i].getTaggingOption(); fieldLen = field.taggedEncodingLength(taggingOption); } else { fieldLen = field.encodingLength(); } allLen += fieldLen; } } return allLen; }
public void decode(Asn1ParseResult parseResult) throws IOException { Asn1ParseResult tmpParseResult = parseResult; if (!tag().equals(parseResult.tag())) { // Primitive but using constructed encoding if (isPrimitive() && !parseResult.isPrimitive()) { Asn1Container container = (Asn1Container) parseResult; tmpParseResult = new Asn1DerivedItem(tag(), container); } else { throw new IOException("Unexpected item " + parseResult.simpleInfo() + ", expecting " + tag()); } } decodeBody(tmpParseResult); }
protected int taggedEncodingLength(TaggingOption taggingOption) { int taggingTagNo = taggingOption.getTagNo(); int taggingBodyLen = taggingOption.isImplicit() ? getBodyLength() : encodingLength(); int taggingEncodingLen = Asn1Util.lengthOfTagLength(taggingTagNo) + Asn1Util.lengthOfBodyLength(taggingBodyLen) + taggingBodyLen; return taggingEncodingLen; }
@Override protected int encodingBodyLength() throws IOException { Asn1Encodeable value = (Asn1Encodeable) getValue(); if (isImplicit()) { return value.encodingBodyLength(); } else { return value.encodingLength(); } }
@Override protected void decodeBody(Asn1ParseResult parseResult) throws IOException { Asn1Encodeable value = (Asn1Encodeable) getValue(); if (isImplicit()) { value.decodeBody(parseResult); } else { Asn1Container container = (Asn1Container) parseResult; Asn1ParseResult body = container.getChildren().get(0); value.decode(body); } }
@Override protected void encodeBody(ByteBuffer buffer) throws IOException { Asn1Encodeable value = (Asn1Encodeable) getValue(); if (isImplicit()) { value.encodeBody(buffer); } else { value.encode(buffer); } }
protected int encodingHeaderLength() throws IOException { int headerLen = Asn1Util.lengthOfTagLength(tagNo()); int bodyLen = getBodyLength(); headerLen += Asn1Util.lengthOfBodyLength(bodyLen); return headerLen; }
@Override protected int getBodyLength() { if (bodyLength == -1) { try { bodyLength = encodingBodyLength(); } catch (IOException e) { throw new RuntimeException(e); } if (bodyLength == -1) { throw new RuntimeException("Unexpected body length: -1"); } } return bodyLength; }
@Override public void encode(ByteBuffer buffer) throws IOException { Asn1Encodeable theValue = (Asn1Encodeable) getValue(); if (theValue != null) { if (!isBlindlyDecoded) { if (decodeInfo.isTagged()) { TaggingOption taggingOption = decodeInfo.getTaggingOption(); theValue.taggedEncode(buffer, taggingOption); } else { theValue.encode(buffer); } } else { theValue.encode(buffer); } } }
public void taggedDecode(Asn1ParseResult parseResult, TaggingOption taggingOption) throws IOException { Tag expectedTaggingTagFlags = taggingOption.getTag(!isPrimitive()); Asn1ParseResult tmpParseResult = parseResult; if (!expectedTaggingTagFlags.equals(parseResult.tag())) { // Primitive but using constructed encoding if (isPrimitive() && !parseResult.isPrimitive()) { Asn1Container container = (Asn1Container) parseResult; tmpParseResult = new Asn1DerivedItem(tag(), container); } else { throw new IOException("Unexpected tag " + parseResult.tag() + ", expecting " + expectedTaggingTagFlags); } } if (taggingOption.isImplicit()) { decodeBody(tmpParseResult); } else { Asn1Container container = (Asn1Container) parseResult; tmpParseResult = container.getChildren().get(0); decode(tmpParseResult); } } }
@Override protected int encodingBodyLength() throws IOException { int allLen = 0; int fieldLen; for (int i = 0; i < fields.length; ++i) { Asn1Encodeable field = (Asn1Encodeable) fields[i]; if (field != null) { if (fieldInfos[i].isTagged()) { TaggingOption taggingOption = fieldInfos[i].getTaggingOption(); fieldLen = field.taggedEncodingLength(taggingOption); } else { fieldLen = field.encodingLength(); } allLen += fieldLen; } } return allLen; }
@Override public void encode(ByteBuffer buffer) throws IOException { Asn1Util.encodeTag(buffer, tag()); int bodyLen = getBodyLength(); Asn1Util.encodeLength(buffer, bodyLen); encodeBody(buffer); }