-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into GH-314.redaction
# Conflicts: # core/core-awt/src/main/java/org/icepdf/core/pobjects/HexStringObject.java # core/core-awt/src/main/java/org/icepdf/core/pobjects/LiteralStringObject.java # core/core-awt/src/main/java/org/icepdf/core/pobjects/StringObject.java # core/core-awt/src/main/java/org/icepdf/core/util/updater/writeables/BaseWriter.java # core/core-awt/src/main/java/org/icepdf/core/util/updater/writeables/StreamWriter.java
- Loading branch information
Showing
35 changed files
with
287 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
core/core-awt/src/main/java/org/icepdf/core/pobjects/AbstractStringObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.icepdf.core.pobjects; | ||
|
||
import org.icepdf.core.pobjects.security.SecurityManager; | ||
import org.icepdf.core.util.Utils; | ||
|
||
public abstract class AbstractStringObject implements StringObject { | ||
|
||
// Reference is need for standard encryption | ||
protected Reference reference; | ||
// if isModified, string is always unencrypted, otherwise is the raw string data which can be | ||
// encrypted or not. | ||
protected StringBuilder stringData; | ||
|
||
// modified string need to be encrypted when writing to file. | ||
protected boolean isModified; | ||
|
||
/** | ||
* Gets the decrypted stringData value of the data using the key provided by the | ||
* security manager. | ||
* | ||
* @param securityManager security manager associated with parent document. | ||
*/ | ||
public String getDecryptedLiteralString(SecurityManager securityManager) { | ||
if (!isModified) { | ||
return encryption(getLiteralString(), reference, securityManager); | ||
} else { | ||
return getLiteralString(); | ||
} | ||
} | ||
|
||
/** | ||
* Decrypts or encrypts a string. | ||
* | ||
* @param string string to encrypt or decrypt | ||
* @param securityManager security manager for document. | ||
* @return encrypted or decrypted string, depends on value of decrypt param. | ||
*/ | ||
public String encryption(String string, Reference reference, SecurityManager securityManager) { | ||
// get the security manager instance | ||
if (securityManager != null && reference != null) { | ||
// get the key | ||
byte[] key = securityManager.getDecryptionKey(); | ||
|
||
// convert string to bytes. | ||
byte[] textBytes = Utils.convertByteCharSequenceToByteArray(string); | ||
|
||
// Decrypt/encrypt String | ||
textBytes = securityManager.decrypt(reference, key, textBytes); | ||
|
||
// convert back to a string | ||
return Utils.convertByteArrayToByteString(textBytes); | ||
} | ||
return string; | ||
} | ||
|
||
/** | ||
* Sets the parent PDF object's reference. | ||
* | ||
* @param reference parent object reference. | ||
*/ | ||
public void setReference(Reference reference) { | ||
this.reference = reference; | ||
} | ||
|
||
/** | ||
* Indicates a string has been modified. | ||
* | ||
* @return string has been modified and may no longer be encrypted. | ||
*/ | ||
@Override | ||
public boolean isModified() { | ||
return isModified; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.