From: Andreas Beeker Date: Mon, 8 Aug 2016 21:00:10 +0000 (+0000) Subject: forgot cryptoapi encryption flags X-Git-Tag: REL_3_16_BETA1~142^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=753a03eef713b321a7b0692f2e1922f28c5c925e;p=poi.git forgot cryptoapi encryption flags git-svn-id: https://svn.apache.org/repos/asf/poi/branches/hssf_cryptoapi@1755541 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/FilePassRecord.java b/src/java/org/apache/poi/hssf/record/FilePassRecord.java index 9f43b94ef9..344096e597 100644 --- a/src/java/org/apache/poi/hssf/record/FilePassRecord.java +++ b/src/java/org/apache/poi/hssf/record/FilePassRecord.java @@ -17,6 +17,7 @@ package org.apache.poi.hssf.record; +import java.io.ByteArrayOutputStream; import java.io.IOException; import org.apache.poi.EncryptedDocumentException; @@ -31,6 +32,7 @@ import org.apache.poi.poifs.crypt.xor.XOREncryptionVerifier; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianByteArrayOutputStream; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.LittleEndianOutputStream; /** * Title: File Pass Record (0x002F)

@@ -42,12 +44,10 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { private static final int ENCRYPTION_XOR = 0; private static final int ENCRYPTION_OTHER = 1; - private int encryptionType; + private final int encryptionType; private EncryptionInfo encryptionInfo; - private int dataLength; private FilePassRecord(FilePassRecord other) { - dataLength = other.dataLength; encryptionType = other.encryptionType; try { encryptionInfo = other.encryptionInfo.clone(); @@ -57,7 +57,6 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { } public FilePassRecord(RecordInputStream in) { - dataLength = in.remaining(); encryptionType = in.readUShort(); EncryptionMode preferredMode; @@ -79,7 +78,8 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { } } - public void serialize(LittleEndianOutput out) { + @Override + public void serialize(LittleEndianOutput out) { out.writeShort(encryptionType); byte data[] = new byte[1024]; @@ -99,6 +99,7 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { case cryptoAPI: out.writeShort(encryptionInfo.getVersionMajor()); out.writeShort(encryptionInfo.getVersionMinor()); + out.writeInt(encryptionInfo.getEncryptionFlags()); ((CryptoAPIEncryptionHeader)encryptionInfo.getHeader()).write(bos); ((CryptoAPIEncryptionVerifier)encryptionInfo.getVerifier()).write(bos); break; @@ -109,14 +110,20 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { out.write(data, 0, bos.getWriteIndex()); } - protected int getDataSize() { - return dataLength; + @Override + @SuppressWarnings("resource") + protected int getDataSize() { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + LittleEndianOutputStream leos = new LittleEndianOutputStream(bos); + serialize(leos); + return bos.size(); } public EncryptionInfo getEncryptionInfo() { return encryptionInfo; } + @Override public short getSid() { return sid; } @@ -126,7 +133,8 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { return new FilePassRecord(this); } - public String toString() { + @Override + public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[FILEPASS]\n");