Skip to content

Commit

Permalink
#429 [refactor] make class PDFEncryption immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Oct 29, 2024
1 parent 6d9adeb commit 1b2835d
Showing 1 changed file with 8 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,20 @@
import com.lowagie.text.pdf.PdfWriter;
import org.xhtmlrenderer.util.ArrayUtil;

public class PDFEncryption {
private byte[] _userPassword;
private byte[] _ownerPassword;
private int _allowedPrivileges = PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_FILL_IN;
private int _encryptionType = PdfWriter.STANDARD_ENCRYPTION_128;
import static com.lowagie.text.pdf.PdfWriter.STANDARD_ENCRYPTION_128;

public PDFEncryption() {
}
public class PDFEncryption {
private final byte[] _userPassword;
private final byte[] _ownerPassword;
private final int _allowedPrivileges;
private final int _encryptionType;

public PDFEncryption(byte[] userPassword, byte[] ownerPassword) {
_userPassword = ArrayUtil.cloneOrEmpty(userPassword);
_ownerPassword = ArrayUtil.cloneOrEmpty(ownerPassword);
this(userPassword, ownerPassword, PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_FILL_IN);
}

public PDFEncryption(byte[] userPassword, byte[] ownerPassword, int allowedPrivileges) {
_userPassword = ArrayUtil.cloneOrEmpty(userPassword);
_ownerPassword = ArrayUtil.cloneOrEmpty(ownerPassword);
_allowedPrivileges = allowedPrivileges;
this(userPassword, ownerPassword, allowedPrivileges, STANDARD_ENCRYPTION_128);
}

public PDFEncryption(byte[] userPassword, byte[] ownerPassword, int allowedPrivileges, int encryptionType) {
Expand All @@ -53,34 +49,17 @@ public byte[] getUserPassword() {
return ArrayUtil.cloneOrEmpty(_userPassword);
}

public void setUserPassword(byte[] userPassword) {
_userPassword = ArrayUtil.cloneOrEmpty(userPassword);
}

public byte[] getOwnerPassword() {
return ArrayUtil.cloneOrEmpty(_ownerPassword);
}

public void setOwnerPassword(byte[] ownerPassword) {
_ownerPassword = ArrayUtil.cloneOrEmpty(ownerPassword);
}

public int getAllowedPrivileges() {
return _allowedPrivileges;
}

public void setAllowedPrivileges(int allowedPrivileges) {
_allowedPrivileges = allowedPrivileges;
}

public int getEncryptionType() {
return _encryptionType;
}

public void setEncryptionType(int encryptionType ) {
_encryptionType = encryptionType;
}

}


Expand Down

0 comments on commit 1b2835d

Please sign in to comment.