@Test public void testEncodeOctetStringNull() { ByteBuffer buf = ByteBuffer.wrap(new byte[2]); buf.position(buf.position() + 2); int len = Asn1Utils.encodeOctetString(null, buf); assertEquals(2, len); assertEquals(0, buf.position()); assertEquals((byte) 4, buf.get(0)); assertEquals((byte) 0, buf.get(1)); }
public static int encodeOctetString(short[] octets, ByteBuffer buf) { if (octets == null) { octets = new short[0]; } int pos = buf.position(); for (int i = octets.length - 1; i >= 0; i--) { pos--; buf.put(pos, (byte) octets[i]); } buf.position(buf.position() - octets.length); int headerLength = DerUtils.encodeIdAndLength(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE, ASN1_OCTET_STRING_TAG_NUM, octets.length, buf); return headerLength + octets.length; }
Asn1Utils { public static int encodeOctetString(short[] octets, ByteBuffer buf) { if (octets == null) { octets = new short[0]; } int pos = buf.position(); for (int i = octets.length - 1; i >= 0; i--) { pos--; buf.put(pos, (byte) octets[i]); } buf.position(buf.position() - octets.length); int headerLength = DerUtils.encodeIdAndLength(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE, ASN1_OCTET_STRING_TAG_NUM, octets.length, buf); return headerLength + octets.length; } }
Asn1Utils { public static int encodeOctetString(short[] octets, ByteBuffer buf) { if (octets == null) { octets = new short[0]; } int pos = buf.position(); for (int i = octets.length - 1; i >= 0; i--) { pos--; buf.put(pos, (byte) octets[i]); } buf.position(buf.position() - octets.length); int headerLength = DerUtils.encodeIdAndLength(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE, ASN1_OCTET_STRING_TAG_NUM, octets.length, buf); return headerLength + octets.length; } private  Asn1Utils(); }
Asn1Utils { public static int encodeOctetString(short[] octets, ByteBuffer buf) { if (octets == null) { octets = new short[0]; } int pos = buf.position(); for (int i = octets.length - 1; i >= 0; i--) { pos--; buf.put(pos, (byte) octets[i]); } buf.position(buf.position() - octets.length); int headerLength = DerUtils.encodeIdAndLength(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE, ASN1_OCTET_STRING_TAG_NUM, octets.length, buf); return headerLength + octets.length; } private  Asn1Utils(); static BitSet decodeBitString(ByteBuffer buf); static Date decodeGeneralizedTime(ByteBuffer buf); static String decodeIA5String(ByteBuffer buf); static int decodeInteger(ByteBuffer buf); static short[] decodeOctetString(ByteBuffer buf); static int decodeSequence(ByteBuffer buf); static int encodeBitString(BitSet value, int nbits, ByteBuffer buf); static int encodeGeneralizedTime(Date date, ByteBuffer buf); static int encodeIA5String(String value, ByteBuffer buf); static int encodeInteger(int value, ByteBuffer buf); static int encodeOctetString(short[] octets, ByteBuffer buf); static int encodeSequence(int contentLength, ByteBuffer buf); static int sizeOfBitString(BitSet value, int nbits); static int sizeOfGeneralizedTime(Date date); static int sizeOfIA5String(String value); static int sizeOfInteger(int value); static int sizeOfOctetString(short[] octets); static int sizeOfSequence(int length); }
Asn1Utils { public static int encodeOctetString(short[] octets, ByteBuffer buf) { if (octets == null) { octets = new short[0]; } int pos = buf.position(); for (int i = octets.length - 1; i >= 0; i--) { pos--; buf.put(pos, (byte) octets[i]); } buf.position(buf.position() - octets.length); int headerLength = DerUtils.encodeIdAndLength(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE, ASN1_OCTET_STRING_TAG_NUM, octets.length, buf); return headerLength + octets.length; } private  Asn1Utils(); static BitSet decodeBitString(ByteBuffer buf); static Date decodeGeneralizedTime(ByteBuffer buf); static String decodeIA5String(ByteBuffer buf); static int decodeInteger(ByteBuffer buf); static short[] decodeOctetString(ByteBuffer buf); static int decodeSequence(ByteBuffer buf); static int encodeBitString(BitSet value, int nbits, ByteBuffer buf); static int encodeGeneralizedTime(Date date, ByteBuffer buf); static int encodeIA5String(String value, ByteBuffer buf); static int encodeInteger(int value, ByteBuffer buf); static int encodeOctetString(short[] octets, ByteBuffer buf); static int encodeSequence(int contentLength, ByteBuffer buf); static int sizeOfBitString(BitSet value, int nbits); static int sizeOfGeneralizedTime(Date date); static int sizeOfIA5String(String value); static int sizeOfInteger(int value); static int sizeOfOctetString(short[] octets); static int sizeOfSequence(int length);  }