Esempio n. 1
0
  @Test
  public void testZeroize() {
    for (int i = 0; i < 10; i++) {
      final HeaderData hd = new HeaderData("test_data", new MemoryResource(new byte[128], i, 128));
      StringElement e1 = new StringElement(null, "test string1", hd, 0, 0, 8 * 10 - 1);
      StringElement e2 = new StringElement(null, "test string2", hd, 10, 0, 8 * 10 - 1);
      StringElement e3 = new StringElement(null, "test string3", hd, 20, 0, 8 * 10 - 1);

      String s1 = "aaaa bb  c";
      String s2 = "zeroizing2";
      String s3 = "1234567890";

      e1.setValue(s1);
      e2.setValue(s2);
      e3.setValue(s3);

      check(e1, s1);
      check(e2, s2);
      check(e3, s3);

      e2.zeroize();
      checkEmpty(e2);

      check(e1, s1);
      check(e2, "");
      check(e3, s3);

      e2.setValue(s2);
      e1.zeroize();
      checkEmpty(e1);

      check(e1, "");
      check(e2, s2);
      check(e3, s3);

      e1.setValue(s1);
      e3.zeroize();

      check(e1, s1);
      check(e2, s2);
      check(e3, "");
    }
  }
Esempio n. 2
0
  @Test
  public void testStringsTooSmall() {
    for (int i = 0; i < 10; i++) {
      final HeaderData hd = new HeaderData("test_data", new MemoryResource(new byte[128], i, 128));
      StringElement e1 = new StringElement(null, "test string1", hd, 0, 0, 8 * 10 - 1);
      StringElement e2 = new StringElement(null, "test string2", hd, 10, 0, 8 * 10 - 1);
      StringElement e3 = new StringElement(null, "test string3", hd, 20, 0, 8 * 10 - 1);
      String ss1 = "aaaa bb  c";
      String ss2 = "zeroizing2";
      String ss3 = "1234567890";
      for (int j = 1; j <= 10; j++) {
        String s1 = ss1.substring(0, j);
        String s2 = ss2.substring(0, j);
        String s3 = ss3.substring(0, j);
        e1.setValue(s1);
        e2.setValue(s2);
        e3.setValue(s3);

        check(e1, s1);
        check(e2, s2);
        check(e3, s3);

        e3.setValue(s3);
        e2.setValue(s2);
        e1.setValue(s1);

        check(e1, s1);
        check(e2, s2);
        check(e3, s3);
      }
    }
  }