* XerDecoder accepts xml elements include whitespaces.
* Accept SET and SEQUENCE type that has no element.
* HexString accepts String contains space and newline.
*/
@Override
void characters(String characters) {
*/
@Override
void characters(String characters) {
- decoder.characters(characters);
+ if (decoder != null) {
+ decoder.characters(characters);
+ }
* jp.bitmeister.asn1.codec.xer.XerDecoder.XerHandler#initializeData
* (java.lang.String)
*/
* jp.bitmeister.asn1.codec.xer.XerDecoder.XerHandler#initializeData
* (java.lang.String)
*/
- void initializeData(String qName) {
+ void initializeData(String qName) throws SAXException {
data = ASN1ModuleManager.instantiate(module, qName);
data = ASN1ModuleManager.instantiate(module, qName);
+ if (data == null) {
+ throw new SAXException("Unknown data type '" + qName + "'.");
+ }
.getSuperclass();
ElementSpecification[] array;
if (parent == SET.class || parent == SEQUENCE.class) {
.getSuperclass();
ElementSpecification[] array;
if (parent == SET.class || parent == SEQUENCE.class) {
- if (elements.isEmpty()) {
- ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
- ex.setMessage(
- "SET and SEQUENCE type shall have at least one element.",
- null, type, null, null);
- throw ex;
- }
Collections.sort(elements);
array = elements.toArray(new ElementSpecification[0]);
if (TypeSpecification.getSpecification(type).tagDefault() == ASN1TagDefault.AUTOMATIC_TAGS) {
Collections.sort(elements);
array = elements.toArray(new ElementSpecification[0]);
if (TypeSpecification.getSpecification(type).tagDefault() == ASN1TagDefault.AUTOMATIC_TAGS) {
import java.util.HashMap;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
-import java.util.Map.Entry;
import jp.bitmeister.asn1.exception.ASN1IllegalDefinition;
import jp.bitmeister.asn1.exception.ASN1IllegalDefinition;
if (type != null) {
return ASN1Type.instantiate(type);
}
if (type != null) {
return ASN1Type.instantiate(type);
}
- for (Entry<String, Class<? extends ASN1Module>> e : importedModules
- .entrySet()) {
- ModuleSpecification spec = ASN1ModuleManager.specification(e
- .getValue());
+ for (Class<? extends ASN1Module> clazz : importedModules
+ .values()) {
+ ModuleSpecification spec = ASN1ModuleManager.specification(clazz);
ASN1Type data = spec.instantiate(tagClass, tagNumber);
if (data != null) {
return data;
ASN1Type data = spec.instantiate(tagClass, tagNumber);
if (data != null) {
return data;
* hexadecimal characters.
*/
public HexString(String string) {
* hexadecimal characters.
*/
public HexString(String string) {
- if (!string.matches("[0-9A-Fa-f]*")) {
+ if (!string.matches("[0-9A-Fa-f \n]*")) {
ASN1IllegalArgument ex = new ASN1IllegalArgument();
ex.setMessage("Invalid string '" + string
+ "'. hString must consist of hexadecimal string.", null,
null, null, null);
throw ex;
}
ASN1IllegalArgument ex = new ASN1IllegalArgument();
ex.setMessage("Invalid string '" + string
+ "'. hString must consist of hexadecimal string.", null,
null, null, null);
throw ex;
}
- this.string = string.trim().toUpperCase();
+ StringBuilder builder = new StringBuilder();
+ for (char c: string.toCharArray()) {
+ if (Character.digit(c, 16) >= 0) {
+ builder.append(c);
+ }
+ }
+ this.string = builder.toString().trim().toUpperCase();