use of org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2.SEQUENCE in project OpenAM by OpenRock.
the class SecureLogHelperJSSImpl method createBagAttrs.
/**
* Creates bag attributes.
* @param nickName The nickname of the key / signature
* @param localKeyId A hash of the entry to uniquely identify the given
* key / signature
* @throws Exception if it fails to generate key identifier
*/
private SET createBagAttrs(String nickName, byte[] localKeyId) throws Exception {
try {
SET attrs = new SET();
SEQUENCE nickNameAttr = new SEQUENCE();
nickNameAttr.addElement(SafeBag.FRIENDLY_NAME);
SET nickNameSet = new SET();
nickNameSet.addElement(new BMPString(nickName));
nickNameAttr.addElement(nickNameSet);
attrs.addElement(nickNameAttr);
SEQUENCE localKeyAttr = new SEQUENCE();
localKeyAttr.addElement(SafeBag.LOCAL_KEY_ID);
SET localKeySet = new SET();
localKeySet.addElement(new OCTET_STRING(localKeyId));
localKeyAttr.addElement(localKeySet);
attrs.addElement(localKeyAttr);
return attrs;
} catch (Exception e) {
Debug.error("SecureLogHelper.createBagAttrs() : " + " Exception : ", e);
throw new Exception("Failed to create Key Bag - " + e.toString());
}
}
use of org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2.SEQUENCE in project jasn1 by openmuc.
the class TaggingTest method explicitlyTaggedSequenceTest.
@Test
public void explicitlyTaggedSequenceTest() throws Exception {
ExplicitlyTaggedSequence sequence = new ExplicitlyTaggedSequence();
sequence.setMyInteger(new BerInteger(1));
sequence.setMyBoolean(new BerBoolean(true));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
sequence.encode(os);
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF210830060201010101FF"), os.getArray());
sequence = new ExplicitlyTaggedSequence();
sequence.decode(new ByteArrayInputStream(os.getArray()));
Assert.assertNotNull(sequence.getMyInteger());
Assert.assertNotNull(sequence.getMyBoolean());
}
use of org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2.SEQUENCE in project jasn1 by openmuc.
the class AuthenticateResponseOk method decode.
public int decode(InputStream is, boolean withTag) throws IOException {
int codeLength = 0;
int subCodeLength = 0;
BerTag berTag = new BerTag();
if (withTag) {
codeLength += tag.decodeAndCheck(is);
}
BerLength length = new BerLength();
codeLength += length.decode(is);
int totalLength = length.val;
if (totalLength == -1) {
subCodeLength += berTag.decode(is);
if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
int nextByte = is.read();
if (nextByte != 0) {
if (nextByte == -1) {
throw new EOFException("Unexpected end of input stream.");
}
throw new IOException("Decoded sequence has wrong end of contents octets");
}
codeLength += subCodeLength + 1;
return codeLength;
}
if (berTag.equals(EuiccSigned1.tag)) {
euiccSigned1 = new EuiccSigned1();
subCodeLength += euiccSigned1.decode(is, false);
subCodeLength += berTag.decode(is);
}
if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
int nextByte = is.read();
if (nextByte != 0) {
if (nextByte == -1) {
throw new EOFException("Unexpected end of input stream.");
}
throw new IOException("Decoded sequence has wrong end of contents octets");
}
codeLength += subCodeLength + 1;
return codeLength;
}
if (berTag.equals(BerTag.APPLICATION_CLASS, BerTag.PRIMITIVE, 55)) {
euiccSignature1 = new BerOctetString();
subCodeLength += euiccSignature1.decode(is, false);
subCodeLength += berTag.decode(is);
}
if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
int nextByte = is.read();
if (nextByte != 0) {
if (nextByte == -1) {
throw new EOFException("Unexpected end of input stream.");
}
throw new IOException("Decoded sequence has wrong end of contents octets");
}
codeLength += subCodeLength + 1;
return codeLength;
}
if (berTag.equals(Certificate.tag)) {
euiccCertificate = new Certificate();
subCodeLength += euiccCertificate.decode(is, false);
subCodeLength += berTag.decode(is);
}
if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
int nextByte = is.read();
if (nextByte != 0) {
if (nextByte == -1) {
throw new EOFException("Unexpected end of input stream.");
}
throw new IOException("Decoded sequence has wrong end of contents octets");
}
codeLength += subCodeLength + 1;
return codeLength;
}
if (berTag.equals(Certificate.tag)) {
eumCertificate = new Certificate();
subCodeLength += eumCertificate.decode(is, false);
subCodeLength += berTag.decode(is);
}
int nextByte = is.read();
if (berTag.tagNumber != 0 || berTag.tagClass != 0 || berTag.primitive != 0 || nextByte != 0) {
if (nextByte == -1) {
throw new EOFException("Unexpected end of input stream.");
}
throw new IOException("Decoded sequence has wrong end of contents octets");
}
codeLength += subCodeLength + 1;
return codeLength;
}
codeLength += totalLength;
subCodeLength += berTag.decode(is);
if (berTag.equals(EuiccSigned1.tag)) {
euiccSigned1 = new EuiccSigned1();
subCodeLength += euiccSigned1.decode(is, false);
subCodeLength += berTag.decode(is);
} else {
throw new IOException("Tag does not match the mandatory sequence element tag.");
}
if (berTag.equals(BerTag.APPLICATION_CLASS, BerTag.PRIMITIVE, 55)) {
euiccSignature1 = new BerOctetString();
subCodeLength += euiccSignature1.decode(is, false);
subCodeLength += berTag.decode(is);
} else {
throw new IOException("Tag does not match the mandatory sequence element tag.");
}
if (berTag.equals(Certificate.tag)) {
euiccCertificate = new Certificate();
subCodeLength += euiccCertificate.decode(is, false);
subCodeLength += berTag.decode(is);
} else {
throw new IOException("Tag does not match the mandatory sequence element tag.");
}
if (berTag.equals(Certificate.tag)) {
eumCertificate = new Certificate();
subCodeLength += eumCertificate.decode(is, false);
if (subCodeLength == totalLength) {
return codeLength;
}
}
throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
}
use of org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2.SEQUENCE in project jasn1 by openmuc.
the class LoadCRLRequest method decode.
public int decode(InputStream is, boolean withTag) throws IOException {
int codeLength = 0;
int subCodeLength = 0;
BerTag berTag = new BerTag();
if (withTag) {
codeLength += tag.decodeAndCheck(is);
}
BerLength length = new BerLength();
codeLength += length.decode(is);
int totalLength = length.val;
if (totalLength == -1) {
subCodeLength += berTag.decode(is);
if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
int nextByte = is.read();
if (nextByte != 0) {
if (nextByte == -1) {
throw new EOFException("Unexpected end of input stream.");
}
throw new IOException("Decoded sequence has wrong end of contents octets");
}
codeLength += subCodeLength + 1;
return codeLength;
}
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
crl = new CertificateList();
subCodeLength += crl.decode(is, false);
subCodeLength += berTag.decode(is);
}
int nextByte = is.read();
if (berTag.tagNumber != 0 || berTag.tagClass != 0 || berTag.primitive != 0 || nextByte != 0) {
if (nextByte == -1) {
throw new EOFException("Unexpected end of input stream.");
}
throw new IOException("Decoded sequence has wrong end of contents octets");
}
codeLength += subCodeLength + 1;
return codeLength;
}
codeLength += totalLength;
subCodeLength += berTag.decode(is);
if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
crl = new CertificateList();
subCodeLength += crl.decode(is, false);
if (subCodeLength == totalLength) {
return codeLength;
}
}
throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
}
use of org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2.SEQUENCE in project jasn1 by openmuc.
the class BerClassWriter method writeSequenceDecodeIndefiniteLenghtPart.
private void writeSequenceDecodeIndefiniteLenghtPart(List<AsnElementType> componentTypes) throws IOException {
write("if (totalLength == -1) {");
write("subCodeLength += berTag.decode(is);\n");
String initChoiceDecodeLength = "int ";
for (AsnElementType componentType : componentTypes) {
Tag componentTag = getTag(componentType);
write("if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {");
write("int nextByte = is.read();");
write("if (nextByte != 0) {");
write("if (nextByte == -1) {");
write("throw new EOFException(\"Unexpected end of input stream.\");");
write("}");
write("throw new IOException(\"Decoded sequence has wrong end of contents octets\");");
write("}");
write("codeLength += subCodeLength + 1;");
write("return codeLength;");
write("}");
String explicitEncoding;
if (isDirectAnyOrChoice(componentType)) {
if (isExplicit(componentTag)) {
write("if (berTag.equals(" + getBerTagParametersString(componentTag) + ")) {");
write("subCodeLength += length.decode(is);");
explicitEncoding = "null";
} else {
explicitEncoding = "berTag";
}
write(getName(componentType) + " = new " + getClassNameOfComponent(componentType) + "();");
write(initChoiceDecodeLength + "choiceDecodeLength = " + getName(componentType) + ".decode(is, " + explicitEncoding + ");");
if (!isExplicit(componentTag)) {
initChoiceDecodeLength = "";
}
write("if (choiceDecodeLength != 0) {");
write("subCodeLength += choiceDecodeLength;");
write("subCodeLength += berTag.decode(is);");
write("}");
write("else {");
write(getName(componentType) + " = null;");
write("}\n");
if (isExplicit(componentTag)) {
write("}");
}
} else {
explicitEncoding = ", false";
if (componentTag != null) {
write("if (berTag.equals(" + getBerTagParametersString(componentTag) + ")) {");
if (isExplicit(componentTag)) {
write("codeLength += length.decode(is);");
explicitEncoding = ", true";
}
} else {
write("if (berTag.equals(" + getClassNameOfComponent(componentType) + ".tag)) {");
}
write(getName(componentType) + " = new " + getClassNameOfComponent(componentType) + "();");
write("subCodeLength += " + getName(componentType) + ".decode(is" + explicitEncoding + ");");
write("subCodeLength += berTag.decode(is);");
write("}");
}
}
write("int nextByte = is.read();");
write("if (berTag.tagNumber != 0 || berTag.tagClass != 0 || berTag.primitive != 0");
write("|| nextByte != 0) {");
write("if (nextByte == -1) {");
write("throw new EOFException(\"Unexpected end of input stream.\");");
write("}");
write("throw new IOException(\"Decoded sequence has wrong end of contents octets\");");
write("}");
write("codeLength += subCodeLength + 1;");
write("return codeLength;");
write("}\n");
}
Aggregations