mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Kotlinized small code
This commit is contained in:
@@ -52,6 +52,6 @@ public class AesEngine extends CipherEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PwEncryptionAlgorithm getPwEncryptionAlgorithm() {
|
public PwEncryptionAlgorithm getPwEncryptionAlgorithm() {
|
||||||
return PwEncryptionAlgorithm.AES_Rijndael;
|
return PwEncryptionAlgorithm.AESRijndael;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ public abstract class PwDatabase<Group extends PwGroup<?, Group, Entry>, Entry e
|
|||||||
public PwEncryptionAlgorithm getEncryptionAlgorithm() {
|
public PwEncryptionAlgorithm getEncryptionAlgorithm() {
|
||||||
if (algorithm != null)
|
if (algorithm != null)
|
||||||
return algorithm;
|
return algorithm;
|
||||||
return PwEncryptionAlgorithm.AES_Rijndael;
|
return PwEncryptionAlgorithm.AESRijndael;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEncryptionAlgorithm(PwEncryptionAlgorithm algorithm) {
|
public void setEncryptionAlgorithm(PwEncryptionAlgorithm algorithm) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
|
|||||||
protected PwGroupV3 rootGroup;
|
protected PwGroupV3 rootGroup;
|
||||||
|
|
||||||
public PwDatabaseV3() {
|
public PwDatabaseV3() {
|
||||||
algorithm = PwEncryptionAlgorithm.AES_Rijndael;
|
algorithm = PwEncryptionAlgorithm.AESRijndael;
|
||||||
numKeyEncRounds = DEFAULT_ENCRYPTION_ROUNDS;
|
numKeyEncRounds = DEFAULT_ENCRYPTION_ROUNDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
|
|||||||
@Override
|
@Override
|
||||||
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
|
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
|
||||||
List<PwEncryptionAlgorithm> list = new ArrayList<>();
|
List<PwEncryptionAlgorithm> list = new ArrayList<>();
|
||||||
list.add(PwEncryptionAlgorithm.AES_Rijndael);
|
list.add(PwEncryptionAlgorithm.AESRijndael);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
|||||||
@Override
|
@Override
|
||||||
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
|
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
|
||||||
List<PwEncryptionAlgorithm> list = new ArrayList<>();
|
List<PwEncryptionAlgorithm> list = new ArrayList<>();
|
||||||
list.add(PwEncryptionAlgorithm.AES_Rijndael);
|
list.add(PwEncryptionAlgorithm.AESRijndael);
|
||||||
list.add(PwEncryptionAlgorithm.Twofish);
|
list.add(PwEncryptionAlgorithm.Twofish);
|
||||||
list.add(PwEncryptionAlgorithm.ChaCha20);
|
list.add(PwEncryptionAlgorithm.ChaCha20);
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.database.element;
|
|
||||||
|
|
||||||
public class PwDbHeaderFactory {
|
|
||||||
public static PwDbHeader getInstance(PwDatabase db) {
|
|
||||||
if (db instanceof PwDatabaseV3) {
|
|
||||||
return new PwDbHeaderV3();
|
|
||||||
} else if (db instanceof PwDatabaseV4) {
|
|
||||||
return new PwDbHeaderV4((PwDatabaseV4)db);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("Not implemented.");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.database.element;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class PwDeletedObject {
|
|
||||||
|
|
||||||
public UUID uuid;
|
|
||||||
private Date deletionTime;
|
|
||||||
|
|
||||||
public PwDeletedObject() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public PwDeletedObject(UUID u) {
|
|
||||||
this(u, new Date());
|
|
||||||
}
|
|
||||||
|
|
||||||
public PwDeletedObject(UUID u, Date d) {
|
|
||||||
uuid = u;
|
|
||||||
deletionTime = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUuid(UUID uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDeletionTime() {
|
|
||||||
if ( deletionTime == null ) {
|
|
||||||
return new Date(System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
return deletionTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeletionTime(Date date) {
|
|
||||||
deletionTime = date;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (o == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (!(o instanceof PwDeletedObject)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PwDeletedObject rhs = (PwDeletedObject) o;
|
|
||||||
|
|
||||||
return uuid.equals(rhs.uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.database.element
|
||||||
|
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
class PwDeletedObject {
|
||||||
|
|
||||||
|
var uuid: UUID = PwDatabase.UUID_ZERO
|
||||||
|
var deletionTime: Date? = null
|
||||||
|
get() = if (field == null) {
|
||||||
|
Date(System.currentTimeMillis())
|
||||||
|
} else field
|
||||||
|
|
||||||
|
constructor()
|
||||||
|
|
||||||
|
@JvmOverloads
|
||||||
|
constructor(uuid: UUID, deletionTime: Date = Date()) {
|
||||||
|
this.uuid = uuid
|
||||||
|
this.deletionTime = deletionTime
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other)
|
||||||
|
return true
|
||||||
|
if (other == null)
|
||||||
|
return false
|
||||||
|
if (other !is PwDeletedObject)
|
||||||
|
return false
|
||||||
|
return uuid == other.uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return uuid.hashCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
|
||||||
*
|
|
||||||
* This file is part of KeePass DX.
|
|
||||||
*
|
|
||||||
* KeePass DX is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* KeePass DX is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.kunzisoft.keepass.database.element;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
|
||||||
import com.kunzisoft.keepass.crypto.engine.AesEngine;
|
|
||||||
import com.kunzisoft.keepass.crypto.engine.ChaCha20Engine;
|
|
||||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
|
|
||||||
import com.kunzisoft.keepass.crypto.engine.TwofishEngine;
|
|
||||||
import com.kunzisoft.keepass.database.ObjectNameResource;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public enum PwEncryptionAlgorithm implements ObjectNameResource {
|
|
||||||
|
|
||||||
AES_Rijndael,
|
|
||||||
Twofish,
|
|
||||||
ChaCha20;
|
|
||||||
|
|
||||||
public String getName(Resources resources) {
|
|
||||||
switch (this) {
|
|
||||||
default:
|
|
||||||
case AES_Rijndael:
|
|
||||||
return resources.getString(R.string.encryption_rijndael);
|
|
||||||
case Twofish:
|
|
||||||
return resources.getString(R.string.encryption_twofish);
|
|
||||||
case ChaCha20:
|
|
||||||
return resources.getString(R.string.encryption_chacha20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CipherEngine getCipherEngine() {
|
|
||||||
switch (this) {
|
|
||||||
default:
|
|
||||||
case AES_Rijndael:
|
|
||||||
return new AesEngine();
|
|
||||||
case Twofish:
|
|
||||||
return new TwofishEngine();
|
|
||||||
case ChaCha20:
|
|
||||||
return new ChaCha20Engine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getDataCipher() {
|
|
||||||
switch (this) {
|
|
||||||
default:
|
|
||||||
case AES_Rijndael:
|
|
||||||
return AesEngine.CIPHER_UUID;
|
|
||||||
case Twofish:
|
|
||||||
return TwofishEngine.CIPHER_UUID;
|
|
||||||
case ChaCha20:
|
|
||||||
return ChaCha20Engine.CIPHER_UUID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.database.element
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.R
|
||||||
|
import com.kunzisoft.keepass.crypto.engine.AesEngine
|
||||||
|
import com.kunzisoft.keepass.crypto.engine.ChaCha20Engine
|
||||||
|
import com.kunzisoft.keepass.crypto.engine.CipherEngine
|
||||||
|
import com.kunzisoft.keepass.crypto.engine.TwofishEngine
|
||||||
|
import com.kunzisoft.keepass.database.ObjectNameResource
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
enum class PwEncryptionAlgorithm : ObjectNameResource {
|
||||||
|
|
||||||
|
AESRijndael,
|
||||||
|
Twofish,
|
||||||
|
ChaCha20;
|
||||||
|
|
||||||
|
val cipherEngine: CipherEngine
|
||||||
|
get() {
|
||||||
|
return when (this) {
|
||||||
|
AESRijndael -> AesEngine()
|
||||||
|
Twofish -> TwofishEngine()
|
||||||
|
ChaCha20 -> ChaCha20Engine()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val dataCipher: UUID
|
||||||
|
get() {
|
||||||
|
return when (this) {
|
||||||
|
AESRijndael -> AesEngine.CIPHER_UUID
|
||||||
|
Twofish -> TwofishEngine.CIPHER_UUID
|
||||||
|
ChaCha20 -> ChaCha20Engine.CIPHER_UUID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getName(resources: Resources): String {
|
||||||
|
return when (this) {
|
||||||
|
AESRijndael -> resources.getString(R.string.encryption_rijndael)
|
||||||
|
Twofish -> resources.getString(R.string.encryption_twofish)
|
||||||
|
ChaCha20 -> resources.getString(R.string.encryption_chacha20)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -110,7 +110,7 @@ public class ImporterV3 extends Importer<PwDatabaseV3> {
|
|||||||
|
|
||||||
// Select algorithm
|
// Select algorithm
|
||||||
if( (hdr.flags & PwDbHeaderV3.FLAG_RIJNDAEL) != 0 ) {
|
if( (hdr.flags & PwDbHeaderV3.FLAG_RIJNDAEL) != 0 ) {
|
||||||
databaseToOpen.setEncryptionAlgorithm(PwEncryptionAlgorithm.AES_Rijndael);
|
databaseToOpen.setEncryptionAlgorithm(PwEncryptionAlgorithm.AESRijndael);
|
||||||
} else if( (hdr.flags & PwDbHeaderV3.FLAG_TWOFISH) != 0 ) {
|
} else if( (hdr.flags & PwDbHeaderV3.FLAG_TWOFISH) != 0 ) {
|
||||||
databaseToOpen.setEncryptionAlgorithm(PwEncryptionAlgorithm.Twofish);
|
databaseToOpen.setEncryptionAlgorithm(PwEncryptionAlgorithm.Twofish);
|
||||||
} else {
|
} else {
|
||||||
@@ -130,7 +130,7 @@ public class ImporterV3 extends Importer<PwDatabaseV3> {
|
|||||||
// Initialize Rijndael algorithm
|
// Initialize Rijndael algorithm
|
||||||
Cipher cipher;
|
Cipher cipher;
|
||||||
try {
|
try {
|
||||||
if ( databaseToOpen.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AES_Rijndael) {
|
if ( databaseToOpen.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AESRijndael) {
|
||||||
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
|
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
|
||||||
} else if ( databaseToOpen.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish ) {
|
} else if ( databaseToOpen.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish ) {
|
||||||
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
|
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
|
|
||||||
Cipher cipher;
|
Cipher cipher;
|
||||||
try {
|
try {
|
||||||
if (mDatabaseV3.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AES_Rijndael) {
|
if (mDatabaseV3.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AESRijndael) {
|
||||||
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
|
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
|
||||||
} else if (mDatabaseV3.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish){
|
} else if (mDatabaseV3.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish){
|
||||||
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
|
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
|
||||||
@@ -112,7 +112,7 @@ public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
|
|||||||
header.signature2 = PwDbHeaderV3.DBSIG_2;
|
header.signature2 = PwDbHeaderV3.DBSIG_2;
|
||||||
header.flags = PwDbHeaderV3.FLAG_SHA2;
|
header.flags = PwDbHeaderV3.FLAG_SHA2;
|
||||||
|
|
||||||
if ( mDatabaseV3.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AES_Rijndael) {
|
if ( mDatabaseV3.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AESRijndael) {
|
||||||
header.flags |= PwDbHeaderV3.FLAG_RIJNDAEL;
|
header.flags |= PwDbHeaderV3.FLAG_RIJNDAEL;
|
||||||
} else if ( mDatabaseV3.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish ) {
|
} else if ( mDatabaseV3.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish ) {
|
||||||
header.flags |= PwDbHeaderV3.FLAG_TWOFISH;
|
header.flags |= PwDbHeaderV3.FLAG_TWOFISH;
|
||||||
|
|||||||
Reference in New Issue
Block a user