use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerBoolean method encodeAndSave.
public void encodeAndSave(int encodingSizeGuess) throws IOException {
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess);
encode(os, false);
code = os.getArray();
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream 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.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class ModulesTest method encodingDecoding.
@Test
public void encodingDecoding() throws IOException {
ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
MyDate1 dateOfHire = new MyDate1();
// MyDate1 dateOfHire = new MyDate1("19710917");
dateOfHire.value = new String("19710917").getBytes();
dateOfHire.encode(berOS, true);
MyInt2 myInt2Encode = new MyInt2(2);
berOS.reset();
myInt2Encode.encode(berOS, true);
MyInt2 myInt2Decode = new MyInt2();
byte[] code = HexConverter.fromShortHexString("a303020102");
InputStream is = new ByteArrayInputStream(code);
myInt2Decode.decode(is, true);
Assert.assertEquals(myInt2Decode.value.intValue(), 2);
PersonnelRecord pr = new PersonnelRecord();
Name name = new Name();
name.setGivenName(new BerVisibleString("givenName".getBytes()));
name.setFamilyName(new BerVisibleString("familyName".getBytes()));
name.setInitial(new BerVisibleString("initial".getBytes()));
pr.setName(name);
pr.setTitle(new BerVisibleString("title".getBytes()));
pr.setNumber(new EmployeeNumberZ(1));
pr.setDateOfHire(new Date("23121981".getBytes()));
pr.setNameOfSpouse(name);
ChildInformation child = new ChildInformation();
child.setName(new Name("child name".getBytes()));
child.setDateOfBirth(new Date("12121912".getBytes()));
PersonnelRecord.Children children = new PersonnelRecord.Children();
List<ChildInformation> childInformation = children.getChildInformation();
childInformation.add(child);
childInformation.add(child);
pr.setTestBitString(new MyBitString(new byte[] { (byte) 0x80, (byte) 0xff }, 10));
pr.setTest(new MyInt(3));
TestChoice testChoice = new TestChoice();
testChoice.setChoiceElement1(child);
pr.setTest2(testChoice);
pr.setTest3(testChoice);
pr.setTest4(testChoice);
pr.setTest5(testChoice);
pr.setTest6(testChoice);
TestSequenceOf testSequenceOf = new TestSequenceOf();
List<BerInteger> berIntegers = testSequenceOf.getBerInteger();
for (int i = 0; i < 10; i++) {
berIntegers.add(new BerInteger(i));
}
pr.setTestSequenceOf(testSequenceOf);
TestSequenceOf2 testSequenceOf2 = new TestSequenceOf2();
List<SEQUENCE> sequences = testSequenceOf2.getSEQUENCE();
for (int i = 0; i < 10; i++) {
SEQUENCE sequence = new SEQUENCE();
sequence.setTest1(new BerInteger(i++));
sequence.setTest2(new BerInteger(i));
sequences.add(sequence);
}
pr.setTestSequenceOf2(testSequenceOf2);
BerEmbeddedPdv berEmbeddedPdv = new BerEmbeddedPdv();
pr.setEmbeddedPdv(berEmbeddedPdv);
System.out.println("PersonnelRecord.toString():\n" + pr);
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerInteger method encodeAndSave.
public void encodeAndSave(int encodingSizeGuess) throws IOException {
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess);
encode(os, false);
code = os.getArray();
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerGeneralizedTimeTest method explicitEncoding.
@Test
public void explicitEncoding() throws IOException {
ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
byte[] byteArray = new byte[] { 0x01, 0x02, 0x03 };
BerGeneralizedTime berGeneralizedTime = new BerGeneralizedTime(byteArray);
int length = berGeneralizedTime.encode(berStream, true);
Assert.assertEquals(5, length);
byte[] expectedBytes = new byte[] { 24, 0x03, 0x01, 0x02, 0x03 };
Assert.assertArrayEquals(expectedBytes, berStream.getArray());
}
Aggregations