@Test(expected = Asn1EncodingException.class) public void testChoiceWithMultipleFieldsSet() throws Exception { encode(new Choice(123, "1.3.6.1.4.1.311.21.20")); }
public static byte[] encode(Object container) throws Asn1EncodingException { Class<?> containerClass = container.getClass(); Asn1Class containerAnnotation = containerClass.getDeclaredAnnotation(Asn1Class.class); if (containerAnnotation == null) { throw new Asn1EncodingException( containerClass.getName() + " not annotated with " + Asn1Class.class.getName()); } Asn1Type containerType = containerAnnotation.type(); switch (containerType) { case CHOICE: return toChoice(container); case SEQUENCE: return toSequence(container); case UNENCODED_CONTAINER: return toSequence(container, true); default: throw new Asn1EncodingException("Unsupported container type: " + containerType); } }
Asn1DerEncoder { public static byte[] encode(Object container) throws Asn1EncodingException { Class<?> containerClass = container.getClass(); Asn1Class containerAnnotation = containerClass.getDeclaredAnnotation(Asn1Class.class); if (containerAnnotation == null) { throw new Asn1EncodingException( containerClass.getName() + " not annotated with " + Asn1Class.class.getName()); } Asn1Type containerType = containerAnnotation.type(); switch (containerType) { case CHOICE: return toChoice(container); case SEQUENCE: return toSequence(container); case UNENCODED_CONTAINER: return toSequence(container, true); default: throw new Asn1EncodingException("Unsupported container type: " + containerType); } } }
Asn1DerEncoder { public static byte[] encode(Object container) throws Asn1EncodingException { Class<?> containerClass = container.getClass(); Asn1Class containerAnnotation = containerClass.getDeclaredAnnotation(Asn1Class.class); if (containerAnnotation == null) { throw new Asn1EncodingException( containerClass.getName() + " not annotated with " + Asn1Class.class.getName()); } Asn1Type containerType = containerAnnotation.type(); switch (containerType) { case CHOICE: return toChoice(container); case SEQUENCE: return toSequence(container); case UNENCODED_CONTAINER: return toSequence(container, true); default: throw new Asn1EncodingException("Unsupported container type: " + containerType); } } private  Asn1DerEncoder(); }
Asn1DerEncoder { public static byte[] encode(Object container) throws Asn1EncodingException { Class<?> containerClass = container.getClass(); Asn1Class containerAnnotation = containerClass.getDeclaredAnnotation(Asn1Class.class); if (containerAnnotation == null) { throw new Asn1EncodingException( containerClass.getName() + " not annotated with " + Asn1Class.class.getName()); } Asn1Type containerType = containerAnnotation.type(); switch (containerType) { case CHOICE: return toChoice(container); case SEQUENCE: return toSequence(container); case UNENCODED_CONTAINER: return toSequence(container, true); default: throw new Asn1EncodingException("Unsupported container type: " + containerType); } } private  Asn1DerEncoder(); static byte[] encode(Object container); }
Asn1DerEncoder { public static byte[] encode(Object container) throws Asn1EncodingException { Class<?> containerClass = container.getClass(); Asn1Class containerAnnotation = containerClass.getDeclaredAnnotation(Asn1Class.class); if (containerAnnotation == null) { throw new Asn1EncodingException( containerClass.getName() + " not annotated with " + Asn1Class.class.getName()); } Asn1Type containerType = containerAnnotation.type(); switch (containerType) { case CHOICE: return toChoice(container); case SEQUENCE: return toSequence(container); case UNENCODED_CONTAINER: return toSequence(container, true); default: throw new Asn1EncodingException("Unsupported container type: " + containerType); } } private  Asn1DerEncoder(); static byte[] encode(Object container);  }