@Test public void testFlush() throws Exception { DEREncoder encoder = new DEREncoder(); encoder.startSequence(); encoder.encodeIA5String("test string"); encoder.encodeOctetString(new byte[]{1, 35, 69, 103, -119, -85, -51, -17}); encoder.startSet(); encoder.encodeIA5String("this is a test"); encoder.encodeOctetString(new byte[] {1, 35, 69, 103, -119, -85, -51, -17}); encoder.startSequence(); encoder.encodeIA5String("testing"); encoder.encodeIA5String("again"); encoder.endSequence(); encoder.encodeIA5String("test1@rsa.com"); encoder.flush(); byte[] expected = new byte[] {48, 84, 22, 11, 116, 101, 115, 116, 32, 115, 116, 114, 105, 110, 103, 4, 8, 1, 35, 69, 103, -119, -85, -51, -17, 49, 59, 4, 8, 1, 35, 69, 103, -119, -85, -51, -17, 48, 16, 22, 7, 116, 101, 115, 116, 105, 110, 103, 22, 5, 97, 103, 97, 105, 110, 22, 14, 116, 104, 105, 115, 32, 105, 115, 32, 97, 32, 116, 101, 115, 116, 22, 13, 116, 101, 115, 116, 49, 64, 114, 115, 97, 46, 99, 111, 109}; assertArrayEquals(expected, encoder.getEncoded()); }
@Override public void flush() { while (states.size() != 0) { EncoderState lastState = states.peekLast(); if (lastState.getTag() == SEQUENCE_TYPE) { endSequence(); } else if (lastState.getTag() == SET_TYPE) { endSet(); } } }
DEREncoder implements ASN1Encoder { @Override public void flush() { while (states.size() != 0) { EncoderState lastState = states.peekLast(); if (lastState.getTag() == SEQUENCE_TYPE) { endSequence(); } else if (lastState.getTag() == SET_TYPE) { endSet(); } } } }
DEREncoder implements ASN1Encoder { @Override public void flush() { while (states.size() != 0) { EncoderState lastState = states.peekLast(); if (lastState.getTag() == SEQUENCE_TYPE) { endSequence(); } else if (lastState.getTag() == SET_TYPE) { endSet(); } } } DEREncoder();   DEREncoder(ByteStringBuilder target); }
DEREncoder implements ASN1Encoder { @Override public void flush() { while (states.size() != 0) { EncoderState lastState = states.peekLast(); if (lastState.getTag() == SEQUENCE_TYPE) { endSequence(); } else if (lastState.getTag() == SET_TYPE) { endSet(); } } } DEREncoder();   DEREncoder(ByteStringBuilder target); @Override void startSequence(); @Override void startSet(); @Override void startSetOf(); @Override void startExplicit(int number); @Override void startExplicit(int clazz, int number); @Override void endSequence(); @Override void endExplicit(); @Override void endSet(); @Override void endSetOf(); @Override void encodeOctetString(String str); @Override void encodeOctetString(byte[] str); @Override void encodeIA5String(String str); @Override void encodeIA5String(byte[] str); @Override void encodePrintableString(final byte[] str); @Override void encodePrintableString(final String str); @Override void encodeUTF8String(final String str); @Override void encodeBMPString(final String str); @Override void encodeUniversalString(final String str); @Override void encodeBitString(byte[] str); @Override void encodeBitString(byte[] str, int numUnusedBits); @Override void encodeBitString(final EnumSet<?> enumSet); @Override void encodeBitString(final BitSet bitSet); @Override void encodeBitString(String binaryStr); @Override void encodeBitString(BigInteger integer); @Override void encodeGeneralizedTime(final ZonedDateTime time); @Override void encodeObjectIdentifier(String objectIdentifier); @Override void encodeNull(); @Override void encodeImplicit(int number); @Override void encodeImplicit(int clazz, int number); @Override void encodeBoolean(final boolean value); @Override void encodeInteger(BigInteger integer); @Override void writeEncoded(byte[] encoded); @Override void flush(); @Override byte[] getEncoded(); }
DEREncoder implements ASN1Encoder { @Override public void flush() { while (states.size() != 0) { EncoderState lastState = states.peekLast(); if (lastState.getTag() == SEQUENCE_TYPE) { endSequence(); } else if (lastState.getTag() == SET_TYPE) { endSet(); } } } DEREncoder();   DEREncoder(ByteStringBuilder target); @Override void startSequence(); @Override void startSet(); @Override void startSetOf(); @Override void startExplicit(int number); @Override void startExplicit(int clazz, int number); @Override void endSequence(); @Override void endExplicit(); @Override void endSet(); @Override void endSetOf(); @Override void encodeOctetString(String str); @Override void encodeOctetString(byte[] str); @Override void encodeIA5String(String str); @Override void encodeIA5String(byte[] str); @Override void encodePrintableString(final byte[] str); @Override void encodePrintableString(final String str); @Override void encodeUTF8String(final String str); @Override void encodeBMPString(final String str); @Override void encodeUniversalString(final String str); @Override void encodeBitString(byte[] str); @Override void encodeBitString(byte[] str, int numUnusedBits); @Override void encodeBitString(final EnumSet<?> enumSet); @Override void encodeBitString(final BitSet bitSet); @Override void encodeBitString(String binaryStr); @Override void encodeBitString(BigInteger integer); @Override void encodeGeneralizedTime(final ZonedDateTime time); @Override void encodeObjectIdentifier(String objectIdentifier); @Override void encodeNull(); @Override void encodeImplicit(int number); @Override void encodeImplicit(int clazz, int number); @Override void encodeBoolean(final boolean value); @Override void encodeInteger(BigInteger integer); @Override void writeEncoded(byte[] encoded); @Override void flush(); @Override byte[] getEncoded();  }