You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2015/08/06 14:37:39 UTC

[3/9] cassandra git commit: ninja-fix an assert in CipherFactory, and added tests for it

ninja-fix an assert in CipherFactory, and added tests for it


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f54580d0
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f54580d0
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f54580d0

Branch: refs/heads/trunk
Commit: f54580d0715a9189ba1658ad036e7d19cecdc3c8
Parents: ecb2b4b
Author: Jason Brown <ja...@gmail.com>
Authored: Thu Aug 6 05:14:15 2015 -0700
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Thu Aug 6 14:36:07 2015 +0200

----------------------------------------------------------------------
 .../org/apache/cassandra/security/CipherFactory.java    |  2 +-
 .../apache/cassandra/security/CipherFactoryTest.java    | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f54580d0/src/java/org/apache/cassandra/security/CipherFactory.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/security/CipherFactory.java b/src/java/org/apache/cassandra/security/CipherFactory.java
index 0ff9867..7c1495a 100644
--- a/src/java/org/apache/cassandra/security/CipherFactory.java
+++ b/src/java/org/apache/cassandra/security/CipherFactory.java
@@ -109,7 +109,7 @@ public class CipherFactory
 
     public Cipher getDecryptor(String transformation, String keyAlias, byte[] iv) throws IOException
     {
-        assert iv != null || iv.length > 0 : "trying to decrypt, but the initialization vector is empty";
+        assert iv != null && iv.length > 0 : "trying to decrypt, but the initialization vector is empty";
         return buildCipher(transformation, keyAlias, iv, Cipher.DECRYPT_MODE);
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f54580d0/test/unit/org/apache/cassandra/security/CipherFactoryTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/security/CipherFactoryTest.java b/test/unit/org/apache/cassandra/security/CipherFactoryTest.java
index 4239973..bb6f7ce 100644
--- a/test/unit/org/apache/cassandra/security/CipherFactoryTest.java
+++ b/test/unit/org/apache/cassandra/security/CipherFactoryTest.java
@@ -84,4 +84,16 @@ public class CipherFactoryTest
         Cipher c2 = cipherFactory.buildCipher(encryptionOptions.cipher, EncryptionContextGenerator.KEY_ALIAS_2, nextIV(), Cipher.DECRYPT_MODE);
         Assert.assertFalse(c1 == c2);
     }
+
+    @Test(expected = AssertionError.class)
+    public void getDecryptor_NullIv() throws IOException
+    {
+        cipherFactory.getDecryptor(encryptionOptions.cipher, encryptionOptions.key_alias, null);
+    }
+
+    @Test(expected = AssertionError.class)
+    public void getDecryptor_EmptyIv() throws IOException
+    {
+        cipherFactory.getDecryptor(encryptionOptions.cipher, encryptionOptions.key_alias, new byte[0]);
+    }
 }