use of org.openmuc.jasn1.ber.types.BerObjectIdentifier in project jasn1 by openmuc.
the class BerClassWriter method writeOidValues.
private void writeOidValues(AsnModule module) throws IOException {
boolean first = true;
List<String> values = new ArrayList<>(module.asnValueAssignmentsByName.keySet());
Collections.sort(values);
for (String valueName : values) {
if (module.asnValueAssignmentsByName.get(valueName).type instanceof AsnObjectIdentifier) {
BerObjectIdentifier oid;
try {
oid = parseObjectIdentfierValue(valueName, module);
} catch (IllegalStateException e) {
System.out.println("Warning: could not parse object identifier value: " + e.getMessage());
continue;
}
StringBuilder sb = new StringBuilder("public static final BerObjectIdentifier " + cleanUpName(valueName) + " = new BerObjectIdentifier(new int[]{");
if (first == true) {
first = false;
writeClassHeader("OidValues", module);
write("public final class OidValues {");
}
boolean firstOidComponent = true;
for (int i : oid.value) {
if (firstOidComponent) {
firstOidComponent = false;
} else {
sb.append(", ");
}
sb.append(i);
}
sb.append("});");
write(sb.toString());
}
}
if (first == false) {
write("}");
out.close();
}
}
use of org.openmuc.jasn1.ber.types.BerObjectIdentifier in project jasn1 by openmuc.
the class GeneralName method decode.
public int decode(InputStream is, BerTag berTag) throws IOException {
int codeLength = 0;
BerTag passedTag = berTag;
if (berTag == null) {
berTag = new BerTag();
codeLength += berTag.decode(is);
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
otherName = new AnotherName();
codeLength += otherName.decode(is, false);
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
rfc822Name = new BerIA5String();
codeLength += rfc822Name.decode(is, false);
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
dNSName = new BerIA5String();
codeLength += dNSName.decode(is, false);
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
x400Address = new ORAddress();
codeLength += x400Address.decode(is, false);
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
codeLength += BerLength.skip(is);
directoryName = new Name();
codeLength += directoryName.decode(is, null);
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) {
ediPartyName = new EDIPartyName();
codeLength += ediPartyName.decode(is, false);
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
uniformResourceIdentifier = new BerIA5String();
codeLength += uniformResourceIdentifier.decode(is, false);
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) {
iPAddress = new BerOctetString();
codeLength += iPAddress.decode(is, false);
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) {
registeredID = new BerObjectIdentifier();
codeLength += registeredID.decode(is, false);
return codeLength;
}
if (passedTag != null) {
return 0;
}
throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item.");
}
use of org.openmuc.jasn1.ber.types.BerObjectIdentifier in project jasn1 by openmuc.
the class BerObjectIdentifierTest method explicitEncoding.
@Test
public void explicitEncoding() throws IOException {
ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
BerObjectIdentifier oi = new BerObjectIdentifier(objectIdentifierComponents);
int length = oi.encode(berBAOStream, true);
Assert.assertEquals(7, length);
Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
use of org.openmuc.jasn1.ber.types.BerObjectIdentifier in project jasn1 by openmuc.
the class MobileTest method header.
@Test
public void header() throws Exception {
ProfileElement headerProfileElement = new ProfileElement();
ServicesList servicesList = new ServicesList();
ProfileHeader.EUICCMandatoryGFSTEList GFSTEList = new ProfileHeader.EUICCMandatoryGFSTEList();
GFSTEList.seqOf = Arrays.asList(new BerObjectIdentifier(new int[] { 2, 23, 143, 1, 2, 1 }), new BerObjectIdentifier(new int[] { 2, 23, 143, 1, 2, 4 }));
servicesList.usim = new BerNull();
servicesList.milenage = new BerNull();
servicesList.javacard = new BerNull();
headerProfileElement.header = new ProfileHeader(new UInt8(2), new UInt8(0), new BerUTF8String("SIMalliance Sample Profile"), new BerOctetString(DatatypeConverter.parseHexBinary("89019990001234567893")), null, servicesList, GFSTEList, null);
ReverseByteArrayOutputStream reverseByteArrayOutputStream = new ReverseByteArrayOutputStream(2048, true);
headerProfileElement.encode(reverseByteArrayOutputStream);
byte[] code = reverseByteArrayOutputStream.getArray();
ProfileElement rereadProfileElement = new ProfileElement();
rereadProfileElement.decode(new ByteArrayInputStream(code), null);
ReverseByteArrayOutputStream reverseOutputStream2 = new ReverseByteArrayOutputStream(2048, true);
rereadProfileElement.encode(reverseOutputStream2);
byte[] code2 = reverseOutputStream2.getArray();
Assert.assertArrayEquals(code, code2);
String expected = "A0 48 80 01 02 81 01 00 82 1A 53494D616C6C69616E63652053616D706C652050726F66696C65 83 0A 89019990001234567893 A5 06 81 00 84 00 8B 00 A6 10 06 06 67810F010201 06 06 67810F010204".replaceAll("\\s", "");
Assert.assertEquals(expected, DatatypeConverter.printHexBinary(code));
}
use of org.openmuc.jasn1.ber.types.BerObjectIdentifier in project jasn1 by openmuc.
the class BerClassWriter method parseObjectIdentfierValue.
private BerObjectIdentifier parseObjectIdentfierValue(String name, AsnModule module) throws IOException {
AsnValueAssignment valueAssignment = module.asnValueAssignmentsByName.get(name);
if (valueAssignment == null || !(valueAssignment.type instanceof AsnObjectIdentifier)) {
return null;
// throw new IOException(
// "no object identifier named \"" + name + "\" in module \"" + module.moduleIdentifier.name);
}
if (!valueAssignment.value.isValueInBraces) {
throw new IllegalStateException("value of object identifier \"" + valueAssignment.name + "\" is not defined in braces.");
}
List<Integer> oidComponents = new ArrayList<>();
List<String> tokens = valueAssignment.value.valueInBracesTokens;
for (int i = 0; i < tokens.size(); i++) {
String token = tokens.get(i);
if (Character.isDigit(token.charAt(0))) {
oidComponents.add(Integer.parseInt(token));
} else if (Character.isLetter(token.charAt(0))) {
if ((tokens.size() == i + 1) || !tokens.get(i + 1).equals("(")) {
// this is either a value reference of another object identifier or a registered name
if (!parseRegisteredOidComponentName(oidComponents, token)) {
BerObjectIdentifier oid = parseObjectIdentfierValue(token, module);
if (oid == null) {
for (SymbolsFromModule symbolsFromModule : module.importSymbolFromModuleList) {
for (String importedTypeName : symbolsFromModule.symbolList) {
if (token.equals(importedTypeName)) {
oid = parseObjectIdentfierValue(token, modulesByName.get(symbolsFromModule.modref));
}
}
}
}
if (oid == null) {
throw new IllegalStateException("AsnValueAssigment \"" + token + "\" was not found in module \"" + module.moduleIdentifier.name + "\"");
}
for (int element : oid.value) {
oidComponents.add(element);
}
}
}
}
}
return new BerObjectIdentifier(toIntArray(oidComponents));
}
Aggregations