diff --git a/src/java/org/apache/poi/poifs/crypt/CipherAlgorithm.java b/src/java/org/apache/poi/poifs/crypt/CipherAlgorithm.java index 68682f496c..cee49d2bee 100644 --- a/src/java/org/apache/poi/poifs/crypt/CipherAlgorithm.java +++ b/src/java/org/apache/poi/poifs/crypt/CipherAlgorithm.java @@ -64,7 +64,7 @@ public enum CipherAlgorithm { for (CipherAlgorithm ca : CipherAlgorithm.values()) { if (ca.ecmaId == ecmaId) return ca; } - throw new EncryptedDocumentException("cipher algorithm not found"); + throw new EncryptedDocumentException("cipher algorithm " + ecmaId + " not found"); } public static CipherAlgorithm fromXmlId(String xmlId, int keySize) { @@ -74,8 +74,6 @@ public enum CipherAlgorithm { if (ks == keySize) return ca; } } - throw new EncryptedDocumentException("cipher algorithm not found"); + throw new EncryptedDocumentException("cipher algorithm " + xmlId + "/" + keySize + " not found"); } - - } \ No newline at end of file diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestCipherAlgorithm.java b/src/testcases/org/apache/poi/poifs/crypt/TestCipherAlgorithm.java new file mode 100644 index 0000000000..814620b829 --- /dev/null +++ b/src/testcases/org/apache/poi/poifs/crypt/TestCipherAlgorithm.java @@ -0,0 +1,42 @@ +package org.apache.poi.poifs.crypt; + +import static org.junit.Assert.*; + +import org.apache.poi.EncryptedDocumentException; +import org.junit.Test; + +public class TestCipherAlgorithm { + @Test + public void test() { + assertEquals(128, CipherAlgorithm.aes128.defaultKeySize); + + for(CipherAlgorithm alg : CipherAlgorithm.values()) { + assertEquals(alg, CipherAlgorithm.valueOf(alg.toString())); + } + + assertEquals(CipherAlgorithm.aes128, CipherAlgorithm.fromEcmaId(0x660E)); + assertEquals(CipherAlgorithm.aes192, CipherAlgorithm.fromXmlId("AES", 192)); + + try { + CipherAlgorithm.fromEcmaId(0); + fail("Should throw exception"); + } catch (EncryptedDocumentException e) { + // expected + } + + try { + CipherAlgorithm.fromXmlId("AES", 1); + fail("Should throw exception"); + } catch (EncryptedDocumentException e) { + // expected + } + + try { + CipherAlgorithm.fromXmlId("RC1", 0x40); + fail("Should throw exception"); + } catch (EncryptedDocumentException e) { + // expected + } + } + +}