Skip to content

Commit

Permalink
Merge branch 'release/2.10.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Jun 2, 2021
2 parents d560c3e + fe08d03 commit d476574
Show file tree
Hide file tree
Showing 26 changed files with 239 additions and 155 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
KeePassDX(2.10.2)
* Fix search fields references #987
* Fix Auto-Types with same key #997

KeePassDX(2.10.1)
* Fix parcelable with custom data #986

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.kunzisoft.keepass"
minSdkVersion 15
targetSdkVersion 30
versionCode = 78
versionName = "2.10.1"
versionCode = 80
versionName = "2.10.2"
multiDexEnabled true

testApplicationId = "com.kunzisoft.keepass.tests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class EntryCursorKDBX : EntryCursorUUID<EntryKDBX>() {
entry.expires
))

for (element in entry.customFields.entries) {
extraFieldCursor.addExtraField(entryId, element.key, element.value)
entry.doForEachDecodedCustomField { key, value ->
extraFieldCursor.addExtraField(entryId, key, value)
}

entryId++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ExtraFieldCursor : MatrixCursor(arrayOf(
}

fun populateExtraFieldInEntry(pwEntry: EntryKDBX) {
pwEntry.putExtraField(getString(getColumnIndex(COLUMN_LABEL)),
pwEntry.putField(getString(getColumnIndex(COLUMN_LABEL)),
ProtectedString(getInt(getColumnIndex(COLUMN_PROTECTION)) > 0,
getString(getColumnIndex(COLUMN_VALUE))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ class Entry : Node, EntryVersionedInterface<Group> {
fun getExtraFields(): List<Field> {
val extraFields = ArrayList<Field>()
entryKDBX?.let {
for (field in it.customFields) {
extraFields.add(Field(field.key, field.value))
it.doForEachDecodedCustomField { key, value ->
extraFields.add(Field(key, value))
}
}
return extraFields
Expand All @@ -294,7 +294,7 @@ class Entry : Node, EntryVersionedInterface<Group> {
* Update or add an extra field to the list (standard or custom)
*/
fun putExtraField(field: Field) {
entryKDBX?.putExtraField(field.name, field.protectedValue)
entryKDBX?.putField(field.name, field.protectedValue)
}

private fun addExtraFields(fields: List<Field>) {
Expand All @@ -310,7 +310,7 @@ class Entry : Node, EntryVersionedInterface<Group> {
fun getOtpElement(): OtpElement? {
entryKDBX?.let {
return OtpEntryFields.parseFields { key ->
it.customFields[key]?.toString()
it.getField(key)?.toString()
}
}
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,40 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
return this.iconsManager.getIcon(iconUuid)
}

/**
* To perform a search in entry custom data
/*
* Search methods
*/

fun getEntryByTitle(title: String, recursionLevel: Int): EntryKDBX? {
return this.entryIndexes.values.find { entry ->
entry.decodeTitleKey(recursionLevel).equals(title, true)
}
}

fun getEntryByUsername(username: String, recursionLevel: Int): EntryKDBX? {
return this.entryIndexes.values.find { entry ->
entry.decodeUsernameKey(recursionLevel).equals(username, true)
}
}

fun getEntryByURL(url: String, recursionLevel: Int): EntryKDBX? {
return this.entryIndexes.values.find { entry ->
entry.decodeUrlKey(recursionLevel).equals(url, true)
}
}

fun getEntryByPassword(password: String, recursionLevel: Int): EntryKDBX? {
return this.entryIndexes.values.find { entry ->
entry.decodePasswordKey(recursionLevel).equals(password, true)
}
}

fun getEntryByNotes(notes: String, recursionLevel: Int): EntryKDBX? {
return this.entryIndexes.values.find { entry ->
entry.decodeNotesKey(recursionLevel).equals(notes, true)
}
}

fun getEntryByCustomData(customDataValue: String): EntryKDBX? {
return entryIndexes.values.find { entry ->
entry.customData.containsItemWithValue(customDataValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,26 +271,6 @@ abstract class DatabaseVersioned<
return this.entryIndexes[id]
}

fun getEntryByTitle(title: String): Entry? {
return this.entryIndexes.values.find { entry -> entry.title.equals(title, true) }
}

fun getEntryByUsername(username: String): Entry? {
return this.entryIndexes.values.find { entry -> entry.username.equals(username, true) }
}

fun getEntryByURL(url: String): Entry? {
return this.entryIndexes.values.find { entry -> entry.url.equals(url, true) }
}

fun getEntryByPassword(password: String): Entry? {
return this.entryIndexes.values.find { entry -> entry.password.equals(password, true) }
}

fun getEntryByNotes(notes: String): Entry? {
return this.entryIndexes.values.find { entry -> entry.notes.equals(notes, true) }
}

fun addEntryIndex(entry: Entry) {
val entryId = entry.nodeId
if (entryIndexes.containsKey(entryId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,30 @@ package com.kunzisoft.keepass.database.element.entry

import android.os.Parcel
import android.os.Parcelable

import com.kunzisoft.keepass.utils.ParcelableUtil
import com.kunzisoft.keepass.utils.UnsignedInt

class AutoType : Parcelable {

var enabled = true
var obfuscationOptions = OBF_OPT_NONE
var defaultSequence = ""
private var windowSeqPairs = LinkedHashMap<String, String>()
private var windowSeqPairs = ArrayList<AutoTypeItem>()

constructor()

constructor(autoType: AutoType) {
this.enabled = autoType.enabled
this.obfuscationOptions = autoType.obfuscationOptions
this.defaultSequence = autoType.defaultSequence
for ((key, value) in autoType.windowSeqPairs) {
this.windowSeqPairs[key] = value
}
this.windowSeqPairs.clear()
this.windowSeqPairs.addAll(autoType.windowSeqPairs)
}

constructor(parcel: Parcel) {
this.enabled = parcel.readByte().toInt() != 0
this.obfuscationOptions = UnsignedInt(parcel.readInt())
this.defaultSequence = parcel.readString() ?: defaultSequence
this.windowSeqPairs = ParcelableUtil.readStringParcelableMap(parcel)
parcel.readTypedList(this.windowSeqPairs, AutoTypeItem.CREATOR)
}

override fun describeContents(): Int {
Expand All @@ -58,15 +55,43 @@ class AutoType : Parcelable {
dest.writeByte((if (enabled) 1 else 0).toByte())
dest.writeInt(obfuscationOptions.toKotlinInt())
dest.writeString(defaultSequence)
ParcelableUtil.writeStringParcelableMap(dest, windowSeqPairs)
dest.writeTypedList(windowSeqPairs)
}

fun add(key: String, value: String) {
windowSeqPairs.add(AutoTypeItem(key, value))
}

fun put(key: String, value: String) {
windowSeqPairs[key] = value
fun doForEachAutoTypeItem(action: (key: String, value: String) -> Unit) {
windowSeqPairs.forEach {
action.invoke(it.key, it.value)
}
}

fun entrySet(): Set<MutableMap.MutableEntry<String, String>> {
return windowSeqPairs.entries
private data class AutoTypeItem(var key: String, var value: String): Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString() ?: "",
parcel.readString() ?: "") {
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(key)
parcel.writeString(value)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<AutoTypeItem> {
override fun createFromParcel(parcel: Parcel): AutoTypeItem {
return AutoTypeItem(parcel)
}

override fun newArray(size: Int): Array<AutoTypeItem?> {
return arrayOfNulls(size)
}
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
size += getAttachmentsSize(attachmentPool)

size += autoType.defaultSequence.length.toLong()
for ((key, value) in autoType.entrySet()) {
autoType.doForEachAutoTypeItem { key, value ->
size += key.length.toLong()
size += value.length.toLong()
}
Expand All @@ -265,25 +265,32 @@ class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
|| key == STR_NOTES)
}

var customFields = LinkedHashMap<String, ProtectedString>()
get() {
field.clear()
for ((key, value) in fields) {
if (!isStandardField(key)) {
field[key] = ProtectedString(value.isProtected, decodeRefKey(mDecodeRef, key, 0))
}
fun doForEachDecodedCustomField(action: (key: String, value: ProtectedString) -> Unit) {
val iterator = fields.entries.iterator()
while (iterator.hasNext()) {
val mapEntry = iterator.next()
if (!isStandardField(mapEntry.key)) {
action.invoke(mapEntry.key,
ProtectedString(mapEntry.value.isProtected,
decodeRefKey(mDecodeRef, mapEntry.key, 0)
)
)
}
return field
}
}

fun removeAllFields() {
fields.clear()
fun getField(key: String): ProtectedString? {
return fields[key]
}

fun putExtraField(label: String, value: ProtectedString) {
fun putField(label: String, value: ProtectedString) {
fields[label] = value
}

fun removeAllFields() {
fields.clear()
}

/**
* It's a list because history labels can be defined multiple times
*/
Expand Down
Loading

0 comments on commit d476574

Please sign in to comment.