class CPLCUtils {

	public static CPLC parse(byte[] raw) {
		CPLC ret = null;
		if (raw != null) {
			byte[] cplc = null;
			// try to interpret as raw data (not TLV)
			if (raw.length == CPLC.SIZE + 2) {
				cplc = raw;
			}
			// or maybe it's prepended with CPLC tag:
			else if (raw.length == CPLC.SIZE + 5) {
				cplc = TlvUtil.getValue(raw, CPLC_TAG);
			} else {
				LOGGER.error("CPLC data not valid");
				return null;
			}
			ret = new CPLC();
			ret.parse(cplc,null);
		}
		return ret;
	}

}

class CPLCUtilsTest {

	@Test
	public void testPrependedCPLC(){

		// prepended with CPLC tag
		CPLC cplc = CPLCUtils.parse(BytesUtils.fromString("9F 7F 2A 47 90 50 40 47 91 81 02 31 00 83 58 00 11 68 91 45 81 48 12 83 65 00 00 00 00 01 2F 31 30 31 31 36 38 00 00 00 00 00 00 00 00 90 00"));		
		Assertions.assertThat(cplc).isNotNull();
		Assertions.assertThat(cplc.getIcFabricator()).isEqualTo(0x4790);
		Assertions.assertThat(cplc.getIcType()).isEqualTo(0x5040);
		Assertions.assertThat(cplc.getOs()).isEqualTo(0x4791);
		Assertions.assertThat(cplc.getOsReleaseLevel()).isEqualTo(0x3100);
		Assertions.assertThat(cplc.getIcSerialNumber()).isEqualTo(0x00116891);
		Assertions.assertThat(cplc.getIcBatchId()).isEqualTo(0x4581);
		Assertions.assertThat(cplc.getIcModuleFabricator()).isEqualTo(0x4812);
		Assertions.assertThat(cplc.getIccManufacturer()).isEqualTo(0x0000);
		Assertions.assertThat(cplc.getIcEmbeddingDate()).isNull();
		Assertions.assertThat(cplc.getPrepersoId()).isEqualTo(0x012F);
		Assertions.assertThat(cplc.getPrepersoEquipment()).isEqualTo(0x31313638);
		Assertions.assertThat(cplc.getPersoId()).isEqualTo(0x0000);
		Assertions.assertThat(cplc.getPersoEquipment()).isEqualTo(0x0000);
	}

}