mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-24 02:51:34 -08:00
fix: Base64 encoder as external library
This commit is contained in:
1 parent
4d6dbc9e30
commit
13f2003fed
11 files changed
+48
-44
No files matched your search
@@ -21,11 +21,10 @@ package com.kunzisoft.keepass.database.element.binary
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.util.Base64
|
||||
import android.util.Base64InputStream
|
||||
import android.util.Base64OutputStream
|
||||
import com.kunzisoft.keepass.utils.readAllBytes
|
||||
import com.kunzisoft.keepass.database.element.binary.BinaryCache.Companion.UNKNOWN
|
||||
import com.kunzisoft.keepass.utils.readAllBytes
|
||||
import org.apache.commons.codec.binary.Base64InputStream
|
||||
import org.apache.commons.codec.binary.Base64OutputStream
|
||||
import java.io.*
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
@@ -60,12 +59,12 @@ class BinaryByte : BinaryData {
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun getInputDataStream(binaryCache: BinaryCache): InputStream {
|
||||
return Base64InputStream(ByteArrayInputStream(getByteArray(binaryCache)), Base64.NO_WRAP)
|
||||
return Base64InputStream(ByteArrayInputStream(getByteArray(binaryCache)), false)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun getOutputDataStream(binaryCache: BinaryCache): OutputStream {
|
||||
return BinaryCountingOutputStream(Base64OutputStream(ByteOutputStream(binaryCache), Base64.NO_WRAP))
|
||||
return BinaryCountingOutputStream(Base64OutputStream(ByteOutputStream(binaryCache), true))
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element.binary
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import org.apache.commons.io.output.CountingOutputStream
|
||||
@@ -180,17 +178,6 @@ abstract class BinaryData : Parcelable {
|
||||
|
||||
companion object {
|
||||
private val TAG = BinaryData::class.java.name
|
||||
private const val MAX_BINARY_BYTE = 10485760 // 10 MB
|
||||
|
||||
fun canMemoryBeAllocatedInRAM(context: Context, memoryWanted: Long): Boolean {
|
||||
if (memoryWanted > MAX_BINARY_BYTE)
|
||||
return false
|
||||
val memoryInfo = ActivityManager.MemoryInfo()
|
||||
(context.getSystemService(Context.ACTIVITY_SERVICE)
|
||||
as? ActivityManager?)?.getMemoryInfo(memoryInfo)
|
||||
val availableMemory = memoryInfo.availMem
|
||||
return availableMemory > (memoryWanted * 5)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,10 +21,9 @@ package com.kunzisoft.keepass.database.element.binary
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.util.Base64
|
||||
import android.util.Base64InputStream
|
||||
import android.util.Base64OutputStream
|
||||
import com.kunzisoft.keepass.utils.readAllBytes
|
||||
import org.apache.commons.codec.binary.Base64InputStream
|
||||
import org.apache.commons.codec.binary.Base64OutputStream
|
||||
import java.io.*
|
||||
import java.util.zip.GZIPOutputStream
|
||||
import javax.crypto.Cipher
|
||||
@@ -75,7 +74,7 @@ class BinaryFile : BinaryData {
|
||||
return when {
|
||||
file != null && file.length() > 0 -> {
|
||||
cipherDecryption.init(Cipher.DECRYPT_MODE, cipherKey.key, IvParameterSpec(cipherKey.iv))
|
||||
Base64InputStream(CipherInputStream(FileInputStream(file), cipherDecryption), Base64.NO_WRAP)
|
||||
Base64InputStream(CipherInputStream(FileInputStream(file), cipherDecryption), false)
|
||||
}
|
||||
else -> ByteArrayInputStream(ByteArray(0))
|
||||
}
|
||||
@@ -87,7 +86,7 @@ class BinaryFile : BinaryData {
|
||||
return when {
|
||||
file != null -> {
|
||||
cipherEncryption.init(Cipher.ENCRYPT_MODE, cipherKey.key, IvParameterSpec(cipherKey.iv))
|
||||
BinaryCountingOutputStream(Base64OutputStream(CipherOutputStream(FileOutputStream(file), cipherEncryption), Base64.NO_WRAP))
|
||||
BinaryCountingOutputStream(Base64OutputStream(CipherOutputStream(FileOutputStream(file), cipherEncryption), true))
|
||||
}
|
||||
else -> throw IOException("Unable to write in an unknown file")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user