Skip to content

Commit

Permalink
Showing 6 changed files with 21 additions and 13 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/com/keepassdroid/database/BinaryPool.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
*/
package com.keepassdroid.database;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -49,6 +50,14 @@ public ProtectedBinary put(int key, ProtectedBinary value) {
public Set<Entry<Integer, ProtectedBinary>> entrySet() {
return pool.entrySet();
}

public void clear() {
pool.clear();
}

public Collection<ProtectedBinary> binaries() {
return pool.values();
}

private class AddBinaries extends EntryHandler<PwEntryV4> {

@@ -72,7 +81,7 @@ private void poolAdd(Map<String, ProtectedBinary> dict) {

}

private void poolAdd(ProtectedBinary pb) {
public void poolAdd(ProtectedBinary pb) {
assert(pb != null);

if (poolFind(pb) != -1) return;
Original file line number Diff line number Diff line change
@@ -104,7 +104,8 @@ public class PwDatabaseV4 extends PwDatabase {
public Map<String, String> customData = new HashMap<String, String>();
public KdfParameters kdfParameters = KdfFactory.getDefaultParameters();
public VariantDictionary publicCustomData = new VariantDictionary();

public BinaryPool binPool = new BinaryPool();

public String localizedAppName = "KeePassDroid";

public class MemoryProtectionConfig {
Original file line number Diff line number Diff line change
@@ -95,7 +95,6 @@ public HeaderAndHash (byte[] header, byte[] hash) {
public byte[] streamStartBytes = new byte[32];
public CrsAlgorithm innerRandomStream;
public long version;
public List<ProtectedBinary> binaries = new ArrayList<ProtectedBinary>();

public PwDbHeaderV4(PwDatabaseV4 d) {
db = d;
Original file line number Diff line number Diff line change
@@ -78,11 +78,11 @@ public class ImporterV4 extends Importer {

private StreamCipher randomStream;
private PwDatabaseV4 db;
private BinaryPool binPool = new BinaryPool();

private byte[] hashOfHeader = null;
private byte[] pbHeader = null;
private long version;
private int binNum = 0;
Calendar utcCal;

public ImporterV4() {
@@ -109,7 +109,7 @@ public PwDatabaseV4 openDatabase(InputStream inStream, String password,
db = createDB();

PwDbHeaderV4 header = new PwDbHeaderV4(db);
header.binaries.clear();
db.binPool.clear();

PwDbHeaderV4.HeaderAndHash hh = header.loadFromFile(inStream);
version = header.version;
@@ -253,6 +253,7 @@ private boolean ReadInnerHeader(LEDataInputStream lis, PwDbHeaderV4 header) thro
byte[] bin = new byte[data.length - 1];
System.arraycopy(data, 1, bin, 0, data.length-1);
ProtectedBinary pb = new ProtectedBinary(prot, bin);
db.binPool.poolAdd(pb);

if (prot) {
Arrays.fill(data, (byte)0);
@@ -511,7 +512,7 @@ private KdbContext ReadXmlElement(KdbContext ctx, XmlPullParser xpp) throws XmlP
if ( key != null ) {
ProtectedBinary pbData = ReadProtectedBinary(xpp);
int id = Integer.parseInt(key);
binPool.put(id, pbData);
db.binPool.put(id, pbData);
} else {
ReadUnknown(xpp);
}
@@ -1061,7 +1062,7 @@ private ProtectedBinary ReadProtectedBinary(XmlPullParser xpp) throws XmlPullPar
xpp.next(); // Consume end tag

int id = Integer.parseInt(ref);
return binPool.get(id);
return db.binPool.get(id);
}

boolean compressed = false;
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public void output() throws IOException {
los.writeInt(streamKeySize);
los.write(header.innerRandomStreamKey);

for (ProtectedBinary bin : header.binaries) {
for (ProtectedBinary bin : db.binPool.binaries()) {
byte flag = KdbxBinaryFlags.None;
if (bin.isProtected()) {
flag |= KdbxBinaryFlags.Protected;
Original file line number Diff line number Diff line change
@@ -82,7 +82,6 @@ public class PwDbV4Output extends PwDbOutput {

PwDatabaseV4 mPM;
private StreamCipher randomStream;
private BinaryPool binPool;
private XmlSerializer xml;
private PwDbHeaderV4 header;
private byte[] hashOfHeader;
@@ -201,8 +200,7 @@ public boolean operate(PwEntry e) {
}

private void outputDatabase(OutputStream os) throws IllegalArgumentException, IllegalStateException, IOException {
binPool = new BinaryPool((PwGroupV4)mPM.rootGroup);


xml = Xml.newSerializer();

xml.setOutput(os, "UTF-8");
@@ -420,7 +418,7 @@ private void writeObject(String key, ProtectedBinary value, boolean allowRef) th
xml.startTag(null, ElemValue);
String strRef = null;
if (allowRef) {
int ref = binPool.poolFind(value);
int ref = mPM.binPool.poolFind(value);
strRef = Integer.toString(ref);
}

@@ -720,7 +718,7 @@ private void writeCustomIconList() throws IllegalArgumentException, IllegalState
private void writeBinPool() throws IllegalArgumentException, IllegalStateException, IOException {
xml.startTag(null, ElemBinaries);

for (Entry<Integer, ProtectedBinary> pair : binPool.entrySet()) {
for (Entry<Integer, ProtectedBinary> pair : mPM.binPool.entrySet()) {
xml.startTag(null, ElemBinary);
xml.attribute(null, AttrId, Integer.toString(pair.getKey()));

0 comments on commit c686ff7

Please sign in to comment.