forgot cryptoapi encryption flags

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/hssf_cryptoapi@1755541 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-08-08 21:00:10 +00:00
parent 680683cf77
commit 5a486ec7c8

View File

@ -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) <p>
@ -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,6 +78,7 @@ public final class FilePassRecord extends StandardRecord implements Cloneable {
}
}
@Override
public void serialize(LittleEndianOutput out) {
out.writeShort(encryptionType);
@ -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());
}
@Override
@SuppressWarnings("resource")
protected int getDataSize() {
return dataLength;
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,6 +133,7 @@ public final class FilePassRecord extends StandardRecord implements Cloneable {
return new FilePassRecord(this);
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();