use of iso.std.iso_iec._24727.tech.schema.DSIWriteResponse in project open-ecard by ecsec.
the class TinySALTest method testDsiWrite.
/**
* Test of dsiWrite method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testDsiWrite() {
System.out.println("dsiWrite");
DSIWrite parameters = new DSIWrite();
DSIWriteResponse result = instance.dsiWrite(parameters);
assertEquals(ECardConstants.Major.ERROR, result.getResult().getResultMajor());
}
use of iso.std.iso_iec._24727.tech.schema.DSIWriteResponse in project open-ecard by ecsec.
the class TinySAL method dsiWrite.
/**
* The DSIWrite function changes the content of a DSI (Data Structure for Interoperability).
* See BSI-TR-03112-4, version 1.1.2, section 3.4.8.
* For clarification this method updates an existing DSI and does not create a new one.
*
* The precondition for this method is that a connection to a card application was established and a data set was
* selected. Furthermore the DSI exists already.
*
* @param request DSIWrite
* @return DSIWriteResponse
*/
@Publish
@Override
public DSIWriteResponse dsiWrite(DSIWrite request) {
DSIWriteResponse response = WSHelper.makeResponse(DSIWriteResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
byte[] applicationID = connectionHandle.getCardApplication();
String dsiName = request.getDSIName();
byte[] updateData = request.getDSIContent();
Assert.assertIncorrectParameter(dsiName, "The parameter DSIName is empty.");
Assert.assertIncorrectParameter(updateData, "The parameter DSIContent is empty.");
CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
DataSetInfoType dataSetInfo = cardInfoWrapper.getDataSetByDsiName(dsiName);
DSIType dsi = cardInfoWrapper.getDSIbyName(dsiName);
Assert.assertNamedEntityNotFound(dataSetInfo, "The given DSIName cannot be found.");
Assert.securityConditionDataSet(cardStateEntry, applicationID, dsiName, NamedDataServiceActionName.DSI_WRITE);
if (cardStateEntry.getFCPOfSelectedEF() == null) {
throw new PrerequisitesNotSatisfiedException("No EF with DSI selected.");
}
if (!Arrays.equals(dataSetInfo.getDataSetPath().getEfIdOrPath(), cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0))) {
String msg = "The currently selected data set does not contain the DSI to be updated.";
throw new PrerequisitesNotSatisfiedException(msg);
}
byte[] slotHandle = connectionHandle.getSlotHandle();
if (cardStateEntry.getFCPOfSelectedEF().getDataElements().isTransparent()) {
// currently assuming that the index encodes the offset
byte[] index = dsi.getDSIPath().getIndex();
UpdateBinary updateBin = new UpdateBinary(index[0], index[1], updateData);
updateBin.transmit(env.getDispatcher(), slotHandle);
} else {
// currently assuming that the index encodes the record number
byte index = dsi.getDSIPath().getIndex()[0];
UpdateRecord updateRec = new UpdateRecord(index, updateData);
updateRec.transmit(env.getDispatcher(), slotHandle);
}
} catch (ECardException e) {
response.setResult(e.getResult());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throwThreadKillException(e);
response.setResult(WSHelper.makeResult(e));
}
return response;
}
Aggregations