diff --git a/src/main/resources/com/adobe/epubcheck/schema/30/ocf-encryption-30.rnc b/src/main/resources/com/adobe/epubcheck/schema/30/ocf-encryption-30.rnc index dc02511fb..e0894b265 100644 --- a/src/main/resources/com/adobe/epubcheck/schema/30/ocf-encryption-30.rnc +++ b/src/main/resources/com/adobe/epubcheck/schema/30/ocf-encryption-30.rnc @@ -1,12 +1,30 @@ - default namespace = "urn:oasis:names:tc:opendocument:xmlns:container" - start = element encryption { - grammar { - include "mod/security/Lenient-Encryption11-ghc.rnc" { - start = xenc_EncryptedData | xenc_EncryptedKey - } - xenc_EncryptionMethodOtherParams |= - attribute Algorithm { xsd:anyURI "http://www.idpf.org/2008/embedding" } - xenc_EncryptionAlgorithms |= - xsd:anyURI "http://www.idpf.org/2008/embedding" - }+ - } +default namespace = "urn:oasis:names:tc:opendocument:xmlns:container" +namespace epub_xenc_compress = "http://www.idpf.org/2016/encryption#compression" +namespace xenc = "http://www.w3.org/2001/04/xmlenc#" + +start = + element encryption { + grammar { + include "mod/security/Lenient-Encryption11-ghc.rnc" { + start = xenc_EncryptedData | xenc_EncryptedKey + xenc_EncryptionPropertyType = + mixed { + attribute Target { xsd:anyURI }?, + attribute Id { xenc_IdType }?, + attribute xml:* { text }*, + xenc_EncryptionPropertyContent + } + xenc_anyForeignElement = + element * - (xenc:* | epub_xenc_compress:*) { + mixed { security_anyAttribute*, security_anyElement* } + } + } + xenc_EncryptionMethodOtherParams |= attribute Algorithm { xsd:anyURI "http://www.idpf.org/2008/embedding" } + xenc_EncryptionAlgorithms |= xsd:anyURI "http://www.idpf.org/2008/embedding" + xenc_EncryptionPropertyContent = (epub_xenc_Compression & xenc_anyForeignElement*) | xenc_anyForeignElement+ + epub_xenc_Compression = element epub_xenc_compress:Compression { epub_xenc_CompressionType } + epub_xenc_CompressionType = + attribute Method { "0" | "8" }, + attribute OriginalLength { xsd:nonNegativeInteger } + }+ + } diff --git a/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java b/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java index e7e1e5725..176305b6c 100644 --- a/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java @@ -305,6 +305,20 @@ public void testLoremMultipleRenditions30() assertTrue(testReport.hasInfoMessage("[EPUB renditions count] 2")); } + @Test + public void testValidCompression() + { + ValidationReport testReport = testOcfPackage("/30/expanded/valid/ocf-compression/", + EPUBVersion.VERSION_3); + + if (0 != testReport.getErrorCount() || 0 != testReport.getWarningCount()) + { + outWriter.println(testReport); + } + assertEquals(0, testReport.getErrorCount()); + assertEquals(0, testReport.getWarningCount()); + } + @Test public void testInvalidLoremForeign30() { @@ -384,4 +398,27 @@ public void testInvalidLoremSCH30() assertTrue(testReport.hasInfoMessage(VERSION_STRING)); } + + @Test + public void testInvalidCompressionMethod() + { + ValidationReport testReport = testOcfPackage("/30/expanded/invalid/ocf-compression/", + EPUBVersion.VERSION_3); + + if (2 != testReport.getErrorCount() || 0 != testReport.getWarningCount()) + { + outWriter.println(testReport); + } + List errors = new ArrayList(); + Collections.addAll(errors, MessageId.RSC_005, MessageId.RSC_005); + assertEquals(errors, testReport.getErrorIds()); + assertEquals(0, testReport.getWarningCount()); + if (testReport.errorList.size() >= 2) + { + assertTrue(testReport.errorList.get(0).message + .contains("value of attribute \"Method\" is invalid; must be equal to \"0\" or \"8\"")); + assertTrue(testReport.errorList.get(1).message + .contains("value of attribute \"OriginalLength\" is invalid; must be an integer")); + } + } } diff --git a/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/content_001.xhtml b/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/content_001.xhtml new file mode 100644 index 000000000..2f8492a6f --- /dev/null +++ b/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/nav.xhtml b/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/nav.xhtml new file mode 100644 index 000000000..fb044b8c6 --- /dev/null +++ b/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/nav.xhtml @@ -0,0 +1,19 @@ + + + + + Minimal Nav + + + + + + diff --git a/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/package.opf b/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/package.opf new file mode 100644 index 000000000..0d1eec6e9 --- /dev/null +++ b/src/test/resources/30/expanded/invalid/ocf-compression/EPUB/package.opf @@ -0,0 +1,16 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/30/expanded/invalid/ocf-compression/META-INF/container.xml b/src/test/resources/30/expanded/invalid/ocf-compression/META-INF/container.xml new file mode 100644 index 000000000..8da9fbae4 --- /dev/null +++ b/src/test/resources/30/expanded/invalid/ocf-compression/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/30/expanded/invalid/ocf-compression/META-INF/encryption.xml b/src/test/resources/30/expanded/invalid/ocf-compression/META-INF/encryption.xml new file mode 100644 index 000000000..50b3f33bb --- /dev/null +++ b/src/test/resources/30/expanded/invalid/ocf-compression/META-INF/encryption.xml @@ -0,0 +1,23 @@ + + + + + + John Smith + + + d2hhdCBkaWQgeW91IHRoaW5rIHlvdSdkIGZpbmQ/ + + + + + + + + + + + + + diff --git a/src/test/resources/30/expanded/invalid/ocf-compression/mimetype b/src/test/resources/30/expanded/invalid/ocf-compression/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/30/expanded/invalid/ocf-compression/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/30/expanded/valid/ocf-compression/EPUB/content_001.xhtml b/src/test/resources/30/expanded/valid/ocf-compression/EPUB/content_001.xhtml new file mode 100644 index 000000000..2f8492a6f --- /dev/null +++ b/src/test/resources/30/expanded/valid/ocf-compression/EPUB/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/30/expanded/valid/ocf-compression/EPUB/nav.xhtml b/src/test/resources/30/expanded/valid/ocf-compression/EPUB/nav.xhtml new file mode 100644 index 000000000..fb044b8c6 --- /dev/null +++ b/src/test/resources/30/expanded/valid/ocf-compression/EPUB/nav.xhtml @@ -0,0 +1,19 @@ + + + + + Minimal Nav + + + + + + diff --git a/src/test/resources/30/expanded/valid/ocf-compression/EPUB/package.opf b/src/test/resources/30/expanded/valid/ocf-compression/EPUB/package.opf new file mode 100644 index 000000000..0d1eec6e9 --- /dev/null +++ b/src/test/resources/30/expanded/valid/ocf-compression/EPUB/package.opf @@ -0,0 +1,16 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/30/expanded/valid/ocf-compression/META-INF/container.xml b/src/test/resources/30/expanded/valid/ocf-compression/META-INF/container.xml new file mode 100644 index 000000000..8da9fbae4 --- /dev/null +++ b/src/test/resources/30/expanded/valid/ocf-compression/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/30/expanded/valid/ocf-compression/META-INF/encryption.xml b/src/test/resources/30/expanded/valid/ocf-compression/META-INF/encryption.xml new file mode 100644 index 000000000..e8d257e07 --- /dev/null +++ b/src/test/resources/30/expanded/valid/ocf-compression/META-INF/encryption.xml @@ -0,0 +1,23 @@ + + + + + + John Smith + + + d2hhdCBkaWQgeW91IHRoaW5rIHlvdSdkIGZpbmQ/ + + + + + + + + + + + + + diff --git a/src/test/resources/30/expanded/valid/ocf-compression/mimetype b/src/test/resources/30/expanded/valid/ocf-compression/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/30/expanded/valid/ocf-compression/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file