for (CipherAlgorithm ca : CipherAlgorithm.values()) {\r
if (ca.ecmaId == ecmaId) return ca;\r
}\r
- throw new EncryptedDocumentException("cipher algorithm not found");\r
+ throw new EncryptedDocumentException("cipher algorithm " + ecmaId + " not found");\r
}\r
\r
public static CipherAlgorithm fromXmlId(String xmlId, int keySize) {\r
if (ks == keySize) return ca;\r
}\r
}\r
- throw new EncryptedDocumentException("cipher algorithm not found");\r
+ throw new EncryptedDocumentException("cipher algorithm " + xmlId + "/" + keySize + " not found");\r
}\r
- \r
-\r
}
\ No newline at end of file
--- /dev/null
+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
+ }
+ }
+
+}