* Fix typo in EXTERNAL type definition ('arbitary' -> 'arbitrary').
* Modify comments in some file.
*
* <p>
* If an {@code @ASN1Alternative} annotation is present on a field, the field is
- * treated as an alternative of a sub-class of {@code SelectiveType}. A field
- * annotated as {@code @ASN1Alternative} must be declared as {@code public}
- * non-{@code final} non-{@code static}, and the type shall be a sub-class of
- * {@code ASN1Type}. The {@code value} parameter represents an order of
- * appearance of a field in an ASN.1 type definition and is used for automatic
- * tagging.
+ * treated as an alternative element of a sub-class of {@code SelectiveType}. A
+ * field annotated as {@code @ASN1Alternative} must be declared as
+ * {@code public} non- {@code final} non-{@code static}, and the type shall be a
+ * sub-class of {@code ASN1Type}. The {@code value} parameter represents an
+ * order of appearance of a field in an ASN.1 type definition and is used for
+ * automatic tagging. If automatic tagging is not used, {@code value} parameter
+ * can be omitted.
* </p>
* <p>
* For example, following ASN.1 definition :
*
* @return Order of this element.
*/
- public int value() default 0;
+ public int value() default -1;
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ASN1BuiltIn {
-
}
* {@code @ASN1Element} must be declared as {@code public} non-{@code final}
* non-{@code static}, and the type shall be a sub-class of {@code ASN1Type}.
* The {@code value} parameter represents an order of appearance of a field in
- * an ASN.1 type definition. The {@code value} parameter must be set even if a
- * container type is a {@code SET} type. It will be used by the automatic
- * tagging process.
+ * an ASN.1 type definition. If automatic tagging is used, the {@code value}
+ * parameter must be set even if a container type is a {@code SET} type.
+ * Otherwise, the {@code value} parameter for element of {@code SET} type can be
+ * omitted.
* </p>
* <p>
* For example, following ASN.1 definition :
*
* @return Order of this element.
*/
- public int value();
+ public int value() default -1;
/**
- * Indicates that the element is optional or not.
+ * Indicates that the element is optional or not. The default value of
+ * {@code optional} is {@code false}.
*
* @return {@code true} if the element is optional.
*/
public boolean optional() default false;
/**
- * Indicates that the element has default value or not.
+ * Indicates that the element has default value or not. The default value of
+ * {@code hasDefault} is {@code false}.
*
* @return {@code true} if the element has default value.
*/
* For example, following ASN.1 definition :
*
* <pre>
- * Signed-Number ::= SEQUENCE { -- '-' can't be used for identifier.
+ * Signed-Number ::= SEQUENCE { -- '-' can't be used for Java identifier.
* int INTEGER -- 'int' is a reserved word.
* }
* </pre>
* @author WATANABE, Jun. <jwat at bitmeister.jp>
*
* @see ASN1Module
+ * @see ASN1TagDefault
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ASN1ModuleTags {
/**
- * Indicates 'TagDefault' specification.
+ * Indicates 'TagDefault' specification. The default value of {@code value}
+ * is {@code ASN1TagDefault.EXPLICIT_TAGS}.
*
* @return The default tagging mode.
*/
public int value();
/**
- * Indicates tag class of this tag.
+ * Indicates tag class of this tag. The default value of {@code tagClass} is
+ * {@code ASN1TagClass.CONTEXT_SPECIFIC}.
*
* @return Tag class.
*/
public ASN1TagClass tagClass() default ASN1TagClass.CONTEXT_SPECIFIC;
/**
- * Indicates the tagging mode of this tag.
+ * Indicates the tagging mode of this tag. The default value of
+ * {@code tagMode} is {@code ASN1TagMode.DEFAULT}.
*
* @return The tagging mode.
*/
* <p>
* {@code BerDecoder} is an implementation of {@code ASN1Decoder}. It reads a
* number of bytes from an {@code InputStream} that is specified when a decoder
- * is instantiated, and decodes them to an ASN.1 data with Basic Encoding Rules
+ * is instantiated, and decodes them to an ASN.1 data using Basic Encoding Rules
* (BER).
* </p>
*
public void process() throws ASN1DecodingException {
@SuppressWarnings("unchecked")
- T component = (T) ASN1Type.instantiate(data.getClass());
+ T component = (T) ASN1Type.instantiate(data.getClass());
data.concatenate(decodeImpl(component));
}
*
* <p>
* {@code BerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
- * ASN.1 data to an array of {@code byte} with Basic Encoding Rules(BER) and
+ * ASN.1 data to an array of {@code byte} using Basic Encoding Rules(BER) and
* writes the result to {@code OutputStream} that is specified when the encoder
* was instantiated. BER encoding process is light-weight compared with
* Distinguished Encoding Rules (DER) encoding because some restrictions on DER
*
* <p>
* {@code DerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
- * ASN.1 data to an array of {@code byte} with Distinguished Encoding Rules(DER) and
- * writes the result to {@code OutputStream} that is specified when the encoder
- * was instantiated.
+ * ASN.1 data to an array of {@code byte} using Distinguished Encoding
+ * Rules(DER) and writes the result to {@code OutputStream} that is specified
+ * when the encoder was instantiated.
* </p>
* <p>
* DER applies some restrictions on Basic Encoding Rules(BER). The result octets
* can be decoded by any BER decoder because DER is a sub-set of BER and
* compatible with it.
* </p>
+ *
* @author WATANABE, Jun. <jwat at bitmeister.jp>
*
* @see ASN1Encoder
* <p>
* {@code XerDecoder} is an implementation of {@code ASN1Decoder}. It reads a
* number of bytes from an {@code InputStream} that is specified when a decoder
- * is instantiated, and decodes them to an ASN.1 data with XML Encoding Rules
+ * is instantiated, and decodes them to an ASN.1 data using XML Encoding Rules
* (XER).
* </p>
*
*
* <p>
* {@code XerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
- * ASN.1 data to an XML document with XML Encoding Rules(XER) and writes the
+ * ASN.1 data to an XML document using XML Encoding Rules(XER) and writes the
* result to {@code OutputStream} that is specified when the encoder was
* instantiated. XER encoding process is light-weight compared with Canonical
* XML Encoding Rules (CXER) encoding because some restrictions on CXER are not
@ASN1Tag(value = 1, tagMode = ASN1TagMode.IMPLICIT)
public Information arrival;
- @ASN1Element(value = 3, hasDefault = true)
- @ASN1Tag(2)
- public Status status = new Status(ASN1TagClass.CONTEXT_SPECIFIC, 0, new NULL());
+ @ASN1Element(value = 3,hasDefault = true)
+ public Status status = new Status(new NULL());
public FrightStatus() {}
import jp.bitmeister.asn1.sample.FrightStatusTypes.FrightNumber;
import jp.bitmeister.asn1.sample.FrightStatusTypes.Information;
import jp.bitmeister.asn1.sample.FrightStatusTypes.Status;
-import jp.bitmeister.asn1.type.ASN1TagClass;
import jp.bitmeister.asn1.type.ASN1Type;
import jp.bitmeister.asn1.type.builtin.INTEGER;
import jp.bitmeister.asn1.type.useful.UTCTime;
new UTCTime("110627093000"),
null
),
- new Status(ASN1TagClass.CONTEXT_SPECIFIC, 1, new INTEGER(10))
+ new Status(new INTEGER(10))
)
);
public static class Information extends AbstractSequence {
- @ASN1Element(value = 0)
+ @ASN1Element(0)
public Airport airport;
@ASN1Element(1)
&& tag.tagClass() != ASN1TagClass.PRIVATE) {
ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
ex.setMessage(
- "Only context-specific or private tagging is allowed to an elements of structured type.",
+ "Only context-specific or private tagging is allowed to elements of structured type.",
null, namedType.enclosingType(), namedType.identifier(),
null);
throw ex;
throw ex;
} catch (IllegalAccessException e) {
ASN1RuntimeException ex = new ASN1IllegalDefinition();
- ex.setMessage("Default constructor might be not accessable.", e,
+ ex.setMessage("Default constructor might be not accessible.", e,
type, null, null);
throw ex;
}
* The visitor.
* @return Result.
* @throws E
- * When an error occured in the {@code visit} method of the
+ * When an error occurred in the {@code visit} method of the
* visitor.
*/
public abstract <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor)
GeneralizedTime.class, // UNIVERSAL 24
GraphicString.class, // UNIVERSAL 25
VisibleString.class, // UNIVERSAL 26
- GeneralString.class, // UNIVERSAL27
+ GeneralString.class, // UNIVERSAL 27
UniversalString.class, // UNIVERSAL 28
CHARACTER_STRING.class, // UNIVERSAL 29
BMPString.class // UNIVERSAL 30
if (ELEMENTS_MAP.containsKey(type)) {
return ELEMENTS_MAP.get(type);
}
+ Class<? extends ConstructiveType> parent = type.getSuperclass().asSubclass(ConstructiveType.class);
List<ElementSpecification> elements = new ArrayList<ElementSpecification>();
for (Field f : type.getDeclaredFields()) {
if (f.isAnnotationPresent(ASN1Element.class)) {
- elements.add(new ElementSpecification(f
- .getAnnotation(ASN1Element.class), f));
+ ASN1Element element = f.getAnnotation(ASN1Element.class);
+ if (element.value() < 0 && SEQUENCE.class.isAssignableFrom(type)) {
+ ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
+ ex.setMessage(
+ "Order of appearance of fields of a SEQUENCE type must be defined by @ASN1Element annotation.",
+ null, type, f.getName(), null);
+ throw ex;
+ }
+ elements.add(new ElementSpecification(element, f));
}
}
- Class<? extends ConstructiveType> parent = type.getSuperclass().asSubclass(ConstructiveType.class);
ElementSpecification[] array;
if (parent == SET.class || parent == SEQUENCE.class
|| parent.isAnnotationPresent(ASN1Extendable.class)) {
if (TypeSpecification.getSpecification(type).tagDefault() == ASN1TagDefault.AUTOMATIC_TAGS) {
generateAutomaticTags(array);
}
- if (parent == SET.class) {
+ if (SET.class.isAssignableFrom(type)) {
new UnorderedElementsChecker(type).check(array);
} else {
new OrderedElementsChecker(type).check(array);
* The appearing order of this element in the type definition.
*/
void generateAutomaticTag(int order) {
+ if (this.order < 0) {
+ ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
+ ex.setMessage(
+ "Order of appearance of the field must be specified by @ASN1Element"
+ + " or @ASN1Alternative annotation for automatic tagging process.",
+ null, enclosingType(), identifier, null);
+ throw ex;
+ }
tag = new ASN1TagValue(order, type());
}
*
* <p>
* This class provides common methods and a value field for classes which
- * represents simple, unconstructive ASN.1 types.
+ * represent simple, unconstructive ASN.1 types.
* </p>
*
* @author WATANABE, Jun. <jwat at bitmeister.jp>
* Indexes of bits to be set true.
*/
public void set(int ...indexes) {
- Arrays.sort(indexes);
- expand(indexes[indexes.length - 1]);
+ int max = -1;
+ for (int e: indexes) {
+ max = Math.max(max, e);
+ }
+ expand(max);
for (int e: indexes) {
value()[e] = true;
}
* Indexes of bits to be set false.
*/
public void unset(int ...indexes) {
- Arrays.sort(indexes);
- expand(indexes[indexes.length - 1]);
+ int max = -1;
+ for (int e: indexes) {
+ max = Math.max(max, e);
+ }
+ expand(max);
for (int e: indexes) {
value()[e] = false;
}
}
/**
- * Returns the indentifier of the bit specified by the index number.
+ * Returns the identifier of the bit specified by the index number.
*
* @param index
* The index number of a bit.
* encoding CHOICE {
* single-ASN1-type [0] ANY,
* octet-aligned [1] IMPLICIT OCTET STRING,
- * arbitary [2] IMPLICIT BIT STRING } }
+ * arbitrary [2] IMPLICIT BIT STRING } }
* </pre>
*
* </p>
public OCTET_STRING octet_aligned;
/**
- * 'arbitary' field.
+ * 'arbitrary' field.
*/
@ASN1Alternative
@ASN1Tag(2)
- public BIT_STRING arbitary;
+ public BIT_STRING arbitrary;
public Encoding() {
super();
}
/**
- * Instanciate an empty {@code ExternalType}.
+ * Instantiate an empty {@code ExternalType}.
*/
public EXTERNAL() {
}
/**
* Returns the string value of this bString.
*
- * @return The hexadecimal string.
+ * @return The binary string that consists of '0's and '1's.
*/
public String string() {
return string;