You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by mw...@apache.org on 2008/12/18 14:06:12 UTC
svn commit: r727716 -
/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/storage/CipherStorageProvider.java
Author: mwiederkehr
Date: Thu Dec 18 05:06:12 2008
New Revision: 727716
URL: http://svn.apache.org/viewvc?rev=727716&view=rev
Log:
Minor refactoring to make the inner classes static.
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/storage/CipherStorageProvider.java
Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/storage/CipherStorageProvider.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/storage/CipherStorageProvider.java?rev=727716&r1=727715&r2=727716&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/storage/CipherStorageProvider.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/storage/CipherStorageProvider.java Thu Dec 18 05:06:12 2008
@@ -85,22 +85,30 @@
}
public StorageOutputStream createStorageOutputStream() throws IOException {
+ SecretKeySpec skeySpec = getSecretKeySpec();
+
return new CipherStorageOutputStream(backend
- .createStorageOutputStream());
+ .createStorageOutputStream(), algorithm, skeySpec);
+ }
+
+ private SecretKeySpec getSecretKeySpec() {
+ byte[] raw = keygen.generateKey().getEncoded();
+ return new SecretKeySpec(raw, algorithm);
}
- private final class CipherStorageOutputStream extends StorageOutputStream {
+ private static final class CipherStorageOutputStream extends
+ StorageOutputStream {
private final StorageOutputStream storageOut;
+ private final String algorithm;
private final SecretKeySpec skeySpec;
private final CipherOutputStream cipherOut;
- public CipherStorageOutputStream(StorageOutputStream out)
- throws IOException {
+ public CipherStorageOutputStream(StorageOutputStream out,
+ String algorithm, SecretKeySpec skeySpec) throws IOException {
try {
this.storageOut = out;
-
- byte[] raw = keygen.generateKey().getEncoded();
- skeySpec = new SecretKeySpec(raw, algorithm);
+ this.algorithm = algorithm;
+ this.skeySpec = skeySpec;
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
@@ -127,16 +135,19 @@
protected Storage toStorage0() throws IOException {
// cipherOut has already been closed because toStorage calls close
Storage encrypted = storageOut.toStorage();
- return new CipherStorage(encrypted, skeySpec);
+ return new CipherStorage(encrypted, algorithm, skeySpec);
}
}
- private final class CipherStorage implements Storage {
+ private static final class CipherStorage implements Storage {
private Storage encrypted;
+ private final String algorithm;
private final SecretKeySpec skeySpec;
- public CipherStorage(Storage encrypted, SecretKeySpec skeySpec) {
+ public CipherStorage(Storage encrypted, String algorithm,
+ SecretKeySpec skeySpec) {
this.encrypted = encrypted;
+ this.algorithm = algorithm;
this.skeySpec = skeySpec;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org