Don't create copies of erasable keys.

This commit is contained in:
akwizgran
2011-11-29 11:03:57 +00:00
parent 7bf2ee64a8
commit a3067dbff8

View File

@@ -1,8 +1,5 @@
package net.sf.briar.crypto;
import java.util.ArrayList;
import java.util.Collection;
import net.sf.briar.api.crypto.ErasableKey;
import net.sf.briar.util.ByteUtils;
@@ -13,7 +10,6 @@ class ErasableKeyImpl implements ErasableKey {
private final byte[] key;
private final String algorithm;
private Collection<byte[]> copies = null; // Locking: this
private boolean erased = false; // Locking: this
ErasableKeyImpl(byte[] key, String algorithm) {
@@ -27,11 +23,7 @@ class ErasableKeyImpl implements ErasableKey {
public synchronized byte[] getEncoded() {
if(erased) throw new IllegalStateException();
byte[] b = new byte[key.length];
System.arraycopy(key, 0, b, 0, key.length);
if(copies == null) copies = new ArrayList<byte[]>();
copies.add(b);
return b;
return key;
}
public String getFormat() {
@@ -45,7 +37,6 @@ class ErasableKeyImpl implements ErasableKey {
public synchronized void erase() {
if(erased) throw new IllegalStateException();
ByteUtils.erase(key);
if(copies != null) for(byte[] b : copies) ByteUtils.erase(b);
erased = true;
}
}