Skip to content

Commit

Permalink
Remove unnecessary EncryptionDocument class
Browse files Browse the repository at this point in the history
  • Loading branch information
plutext committed Jul 15, 2015
1 parent 93b6362 commit f8489c7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
package org.docx4j.org.apache.poi.poifs.crypt.agile;

import org.docx4j.com.microsoft.schemas.office.x2006.encryption.CTDataIntegrity;
import org.docx4j.com.microsoft.schemas.office.x2006.encryption.CTEncryption;
import org.docx4j.com.microsoft.schemas.office.x2006.encryption.CTKeyData;
import org.docx4j.com.microsoft.schemas.office.x2006.encryption.STCipherChaining;
import org.docx4j.org.apache.poi.EncryptedDocumentException;
Expand All @@ -38,10 +39,10 @@ public AgileEncryptionHeader(String descriptor) {
this(AgileEncryptionInfoBuilder.parseDescriptor(descriptor));
}

protected AgileEncryptionHeader(EncryptionDocument ed) {
protected AgileEncryptionHeader(CTEncryption ed) {
CTKeyData keyData;
try {
keyData = ed.getEncryption().getKeyData();
keyData = ed.getKeyData();
if (keyData == null) {
throw new NullPointerException("keyData not set");
}
Expand Down Expand Up @@ -85,7 +86,7 @@ protected AgileEncryptionHeader(EncryptionDocument ed) {
throw new EncryptedDocumentException("Invalid salt length");
}

CTDataIntegrity di = ed.getEncryption().getDataIntegrity();
CTDataIntegrity di = ed.getDataIntegrity();
setEncryptedHmacKey(di.getEncryptedHmacKey());
setEncryptedHmacValue(di.getEncryptedHmacValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class AgileEncryptionInfoBuilder implements EncryptionInfoBuilder {
public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException {
this.info = info;

EncryptionDocument ed = parseDescriptor((InputStream)dis);
CTEncryption ed = parseDescriptor((InputStream)dis);
header = new AgileEncryptionHeader(ed);
verifier = new AgileEncryptionVerifier(ed);
if (info.getVersionMajor() == EncryptionMode.agile.versionMajor
Expand Down Expand Up @@ -128,7 +128,7 @@ protected EncryptionInfo getInfo() {
return info;
}

protected static EncryptionDocument parseDescriptor(String descriptor) {
protected static CTEncryption parseDescriptor(String descriptor) {
// try {
// return EncryptionDocument.Factory.parse(descriptor);
// } catch (XmlException e) {
Expand All @@ -144,13 +144,11 @@ protected static EncryptionDocument parseDescriptor(String descriptor) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EncryptionDocument ed = new EncryptionDocument();
ed.setEncryption(encryption);
return ed;
return encryption;

}

protected static EncryptionDocument parseDescriptor(InputStream descriptor) {
protected static CTEncryption parseDescriptor(InputStream descriptor) {
// try {
// return EncryptionDocument.Factory.parse(descriptor);
// } catch (Exception e) {
Expand All @@ -173,9 +171,7 @@ protected static EncryptionDocument parseDescriptor(InputStream descriptor) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EncryptionDocument ed = new EncryptionDocument();
ed.setEncryption(encryption);
return ed;
return encryption;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import java.util.Iterator;
import java.util.List;

import org.docx4j.com.microsoft.schemas.office.x2006.encryption.CTEncryption;
import org.docx4j.com.microsoft.schemas.office.x2006.encryption.CTKeyEncryptor;
import org.docx4j.com.microsoft.schemas.office.x2006.encryption.STCipherChaining;
import org.docx4j.com.microsoft.schemas.office.x2006.keyEncryptor.certificate.CTCertificateKeyEncryptor;
Expand Down Expand Up @@ -57,8 +58,8 @@ public AgileEncryptionVerifier(String descriptor) {
this(AgileEncryptionInfoBuilder.parseDescriptor(descriptor));
}

protected AgileEncryptionVerifier(EncryptionDocument ed) {
Iterator<CTKeyEncryptor> encList = ed.getEncryption().getKeyEncryptors().getKeyEncryptor().iterator();
protected AgileEncryptionVerifier(CTEncryption ed) {
Iterator<CTKeyEncryptor> encList = ed.getKeyEncryptors().getKeyEncryptor().iterator();
CTPasswordKeyEncryptor keyData;
try {
keyData = encList.next().getEncryptedPasswordKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,11 @@ protected void updateIntegrityHMAC(File tmpFile, int oleStreamSize) throws Gener
private final String certificateUri =
HTTP_SCHEMAS_MICROSOFT_COM_OFFICE_2006_KEY_ENCRYPTOR_CERTIFICATE;

protected EncryptionDocument createEncryptionDocument() {
protected CTEncryption createEncryptionDocument() {
AgileEncryptionVerifier ver = builder.getVerifier();
AgileEncryptionHeader header = builder.getHeader();

EncryptionDocument ed = new EncryptionDocument();
CTEncryption edRoot = ed.addNewEncryption();
CTEncryption edRoot = new CTEncryption();

CTKeyData keyData = new CTKeyData();
edRoot.setKeyData(keyData);
Expand Down Expand Up @@ -387,7 +386,7 @@ protected EncryptionDocument createEncryptionDocument() {
certData.setCertVerifier(ace.certVerifier);
}

return ed;
return edRoot;
}

// protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByteArrayOutputStream os) {
Expand All @@ -414,7 +413,7 @@ protected EncryptionDocument createEncryptionDocument() {
// }
// }

protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByteArrayOutputStream os) {
protected void marshallEncryptionDocument(CTEncryption ed, LittleEndianByteArrayOutputStream os) {

try {
Marshaller marshaller = Context.jcEncryption.createMarshaller();
Expand Down Expand Up @@ -448,7 +447,7 @@ protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByt


ByteArrayOutputStream bos = new ByteArrayOutputStream();
marshaller.marshal(ed.getEncryption(), bos);
marshaller.marshal(ed, bos);

os.write(bos.toByteArray());

Expand Down Expand Up @@ -484,8 +483,7 @@ public void write(LittleEndianByteArrayOutputStream bos) {
// Reserved (4 bytes): A value that MUST be 0x00000040
bos.writeInt(info.getEncryptionFlags());

EncryptionDocument ed = createEncryptionDocument();
marshallEncryptionDocument(ed, bos);
marshallEncryptionDocument(createEncryptionDocument(), bos);
}
};

Expand Down

This file was deleted.

0 comments on commit f8489c7

Please sign in to comment.