mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Don't create copies of erasable keys.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user