mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 23:59:54 +01:00
Don't create copies of erasable keys.
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
package net.sf.briar.crypto;
|
package net.sf.briar.crypto;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import net.sf.briar.api.crypto.ErasableKey;
|
import net.sf.briar.api.crypto.ErasableKey;
|
||||||
import net.sf.briar.util.ByteUtils;
|
import net.sf.briar.util.ByteUtils;
|
||||||
|
|
||||||
@@ -13,7 +10,6 @@ class ErasableKeyImpl implements ErasableKey {
|
|||||||
private final byte[] key;
|
private final byte[] key;
|
||||||
private final String algorithm;
|
private final String algorithm;
|
||||||
|
|
||||||
private Collection<byte[]> copies = null; // Locking: this
|
|
||||||
private boolean erased = false; // Locking: this
|
private boolean erased = false; // Locking: this
|
||||||
|
|
||||||
ErasableKeyImpl(byte[] key, String algorithm) {
|
ErasableKeyImpl(byte[] key, String algorithm) {
|
||||||
@@ -27,11 +23,7 @@ class ErasableKeyImpl implements ErasableKey {
|
|||||||
|
|
||||||
public synchronized byte[] getEncoded() {
|
public synchronized byte[] getEncoded() {
|
||||||
if(erased) throw new IllegalStateException();
|
if(erased) throw new IllegalStateException();
|
||||||
byte[] b = new byte[key.length];
|
return key;
|
||||||
System.arraycopy(key, 0, b, 0, key.length);
|
|
||||||
if(copies == null) copies = new ArrayList<byte[]>();
|
|
||||||
copies.add(b);
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFormat() {
|
public String getFormat() {
|
||||||
@@ -45,7 +37,6 @@ class ErasableKeyImpl implements ErasableKey {
|
|||||||
public synchronized void erase() {
|
public synchronized void erase() {
|
||||||
if(erased) throw new IllegalStateException();
|
if(erased) throw new IllegalStateException();
|
||||||
ByteUtils.erase(key);
|
ByteUtils.erase(key);
|
||||||
if(copies != null) for(byte[] b : copies) ByteUtils.erase(b);
|
|
||||||
erased = true;
|
erased = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user