@Override Data getMmsDataObj() { Data data = new Data(); data.setOctetString(new BerOctetString(value)); return data; }
public InitiateResponseBuilder setAuthenticationValue(byte[] serverToClientChallenge) { this.serverToClientChallenge = new AuthenticationValue(); this.serverToClientChallenge.setCharstring(new BerOctetString(serverToClientChallenge)); return this; }
private static Fcp createFcp(short fileId, String fileDescriptor, byte arrReference, Short efFileSize, String pinStatusTemplateDo, Short shortEfId, String linkPath) { return new Fcp(new BerOctetString(DatatypeConverter.parseHexBinary(fileDescriptor)), new BerOctetString(unsignedShortToByteArray(fileId)), null, null, new BerOctetString(new byte[] { arrReference }), efFileSize != null ? new BerOctetString(unsignedShortToByteArray(efFileSize)) : null, pinStatusTemplateDo != null ? new BerOctetString(DatatypeConverter.parseHexBinary(pinStatusTemplateDo)) : null, shortEfId != null ? new BerOctetString(new byte[] { shortEfId.byteValue() }) : null, null, linkPath != null ? new BerOctetString(DatatypeConverter.parseHexBinary(linkPath)) : null); } }
@Override Data getMmsDataObj() { Data data = new Data(); data.setOctetString(new BerOctetString(value)); return data; }
private static void setupAarqAuthentication(AARQApdu aarq, byte[] clientToServerChallenge) { aarq.setSenderAcseRequirements(new ACSERequirements(new byte[] { (byte) 0x80 }, 2)); AuthenticationValue authenticationValue = new AuthenticationValue(); authenticationValue.setCharstring(new BerOctetString(clientToServerChallenge)); aarq.setCallingAuthenticationValue(authenticationValue); }
@Test public void explicitDecoding() throws IOException { byte[] byteCode = new byte[] { 0x04, 0x00 }; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerOctetString asn1OctetString = new BerOctetString(); asn1OctetString.decode(berInputStream, true); Assert.assertEquals(0, asn1OctetString.value.length); }
private static List<FileManagement.CHOICE> createEf(short fileId, String fileDescriptor, byte arrReference, Short efFileSize, Short shortEfId, String linkPath, String fillFileContent, Integer fillFileOffset) { List<FileManagement.CHOICE> fileManagementSubChoices = new ArrayList<>(); fileManagementSubChoices.add(new FileManagement.CHOICE(null, createFcp(fileId, fileDescriptor, arrReference, efFileSize, null, shortEfId, linkPath), null, null)); if (fillFileOffset != null) { fileManagementSubChoices.add(new FileManagement.CHOICE(null, null, new UInt16(fillFileOffset), null)); } if (fillFileContent != null) { fileManagementSubChoices.add(new FileManagement.CHOICE(null, null, null, new BerOctetString(HexConverter.fromShortHexString(fillFileContent)))); } return fileManagementSubChoices; }
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.PRIMITIVE, 0)) { charstring = new BerOctetString(); codeLength += charstring.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { bitstring = new BerBitString(); codeLength += bitstring.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
private static List<FileManagement.CHOICE> createEf(short fileId, String fileDescriptor, byte arrReference, Short efFileSize, Short shortEfId, List<FileRecordContent> fillFileRecordContents) { final List<FileManagement.CHOICE> fileManagementChoices = createEf(fileId, fileDescriptor, arrReference, efFileSize, shortEfId); if (fillFileRecordContents != null) { for (FileRecordContent fileRecordContent : fillFileRecordContents) { if (fileRecordContent.fillFileOffset != null) { fileManagementChoices.add( new FileManagement.CHOICE(null, null, new UInt16(fileRecordContent.fillFileOffset), null)); } fileManagementChoices.add(new FileManagement.CHOICE(null, null, null, new BerOctetString(DatatypeConverter.parseHexBinary(fileRecordContent.fillFileContent)))); } } return fileManagementChoices; }
private static PUKConfiguration createPUK(byte pukReference, String pukValue, Byte maxNumOfAttempts, Byte retryNumLeft) { return new PUKConfiguration(new PUKKeyReferenceValue(pukReference & 0xff), new BerOctetString(DatatypeConverter.parseHexBinary(pukValue)), maxNumOfAttempts != null && retryNumLeft != null ? new UInt8((maxNumOfAttempts << 4) | retryNumLeft) : null); }
@Test public void toStringTest() { BerOctetString octetString = new BerOctetString(new byte[] { 1, 2, (byte) 0xa0 }); Assert.assertEquals("0102A0", octetString.toString()); }
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)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
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)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
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)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
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)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
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)) { BerLength length = new BerLength(); codeLength += length.decode(is); singleASN1Type = new BerAnyNoDecode(); codeLength += singleASN1Type.decode(is, length.val); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding BerChoice: Tag matched to no item."); }
@Test public void explicitEncoding() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); byte[] byteArray = new byte[] { 0x01, 0x02, 0x03 }; BerOctetString asn1OctetString = new BerOctetString(byteArray); int length = asn1OctetString.encode(berStream, true); Assert.assertEquals(5, length); byte[] expectedBytes = new byte[] { 0x04, 0x03, 0x01, 0x02, 0x03 }; Assert.assertArrayEquals(expectedBytes, berStream.getArray()); }
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)) { pinconfig = new Pinconfig(); codeLength += pinconfig.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { filePath = new BerOctetString(); codeLength += filePath.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
@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)); }
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)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }