CHATVerifier { public static void verfiy(CHAT firstCHAT, CHAT secondCHAT) throws GeneralSecurityException { try { byte[] firstCHATBytes = firstCHAT.toByteArray(); byte[] secondCHATBytes = secondCHAT.toByteArray(); for (int i = 0; i < firstCHATBytes.length * 8; i++) { if (ByteUtils.isBitSet(i, secondCHATBytes) && !ByteUtils.isBitSet(i, firstCHATBytes)) { throw new GeneralSecurityException("The second CHAT is not a subset of the first one"); } } } catch (Exception e) { throw new GeneralSecurityException(e); } }  static void verfiy(CHAT firstCHAT, CHAT secondCHAT);  }
@Test public void testVerfiy() throws Exception { byte[] chatBytes = StringUtils.toByteArray("7f4c12060904007f0007030102025305300301ffb7"); CHAT c1 = new CHAT(chatBytes); c1.setReadAccess(CHAT.DataGroup.DG01, !false); c1.setReadAccess(CHAT.DataGroup.DG02, !false); CHAT c2 = new CHAT(chatBytes); c2.setReadAccess(CHAT.DataGroup.DG01, false); c2.setReadAccess(CHAT.DataGroup.DG02, false); CHATVerifier.verfiy(c1, c2); }
@Test(expectedExceptions = GeneralSecurityException.class) public void testVerfiy2() throws Exception { byte[] chatBytes = StringUtils.toByteArray("7f4c12060904007f0007030102025305300301ffb7"); CHAT c1 = new CHAT(chatBytes); c1.setReadAccess(CHAT.DataGroup.DG01, !false); c1.setReadAccess(CHAT.DataGroup.DG02, !false); CHAT c2 = new CHAT(chatBytes); c2.setReadAccess(CHAT.DataGroup.DG01, false); c2.setReadAccess(CHAT.DataGroup.DG02, false); CHATVerifier.verfiy(c2, c1); }