Skip to content

Commit e5a294d

Browse files
committed
PDFBOX-6072: remove unused, remove public, refactor
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1928621 13f79535-47bb-0310-9956-ffa450edef68
1 parent fd19233 commit e5a294d

File tree

1 file changed

+9
-26
lines changed
  • pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption

1 file changed

+9
-26
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/RC4Cipher.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class RC4Cipher
4444
*
4545
* @param key The RC4 key used during encryption.
4646
*/
47-
public void setKey( byte[] key )
47+
void setKey( byte[] key )
4848
{
4949
b = 0;
5050
c = 0;
@@ -95,26 +95,13 @@ private static void swap( int[] data, int firstIndex, int secondIndex )
9595
data[ secondIndex ] = tmp;
9696
}
9797

98-
private int encrypt(byte aByte)
98+
private byte encrypt(byte aByte)
9999
{
100100
b = (b + 1) % 256;
101101
c = (salt[b] + c) % 256;
102102
swap(salt, b, c);
103103
int saltIndex = (salt[b] + salt[c]) % 256;
104-
return aByte ^ (byte) salt[saltIndex];
105-
}
106-
107-
/**
108-
* This will encrypt and write the next byte.
109-
*
110-
* @param aByte The byte to encrypt.
111-
* @param output The stream to write to.
112-
*
113-
* @throws IOException If there is an error writing to the output stream.
114-
*/
115-
public void write( byte aByte, OutputStream output ) throws IOException
116-
{
117-
output.write(encrypt(aByte));
104+
return (byte) (aByte ^ (byte) salt[saltIndex]);
118105
}
119106

120107
/**
@@ -125,9 +112,9 @@ public void write( byte aByte, OutputStream output ) throws IOException
125112
*
126113
* @throws IOException If there is an error writing to the output stream.
127114
*/
128-
public void write( byte[] data, OutputStream output ) throws IOException
115+
void write(byte[] data, OutputStream output) throws IOException
129116
{
130-
write(data, 0, data.length, output);
117+
write(data, 0, data.length, output, new byte[data.length]);
131118
}
132119

133120
/**
@@ -138,7 +125,7 @@ public void write( byte[] data, OutputStream output ) throws IOException
138125
*
139126
* @throws IOException If there is an error writing to the output stream.
140127
*/
141-
public void write( InputStream data, OutputStream output ) throws IOException
128+
void write(InputStream data, OutputStream output) throws IOException
142129
{
143130
byte[] buffer = new byte[1024];
144131
int amountRead;
@@ -151,23 +138,19 @@ public void write( InputStream data, OutputStream output ) throws IOException
151138
/**
152139
* This will encrypt and write the data.
153140
*
154-
* @param data The data to encrypt.
141+
* @param data The data to encrypt, may be overwritten.
155142
* @param offset The offset into the array to start reading data from.
156143
* @param len The number of bytes to attempt to read.
157144
* @param output The stream to write to.
145+
* @param buffer The buffer to use, it can be altered and be identical to the data to encrypt.
158146
*
159147
* @throws IOException If there is an error writing to the output stream.
160148
*/
161-
public void write( byte[] data, int offset, int len, OutputStream output) throws IOException
162-
{
163-
write(data, offset, len, output, new byte[len]);
164-
}
165-
166149
private void write(byte[] data, int offset, int len, OutputStream output, byte[] buffer) throws IOException
167150
{
168151
for (int i = 0, j = offset; i < len; ++i, ++j)
169152
{
170-
buffer[i] = (byte) encrypt(data[j]);
153+
buffer[i] = encrypt(data[j]);
171154
}
172155

173156
output.write(buffer, 0, len);

0 commit comments

Comments
 (0)