Skip to content

Commit

Permalink
Add removeFilesOlderThanDays
Browse files Browse the repository at this point in the history
  • Loading branch information
markowanga committed Feb 19, 2022
1 parent ba52911 commit 52c5a0b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.github.markowanga.timberloggingtofile
import android.content.Context
import androidx.core.content.ContextCompat
import java.io.File
import java.time.Instant
import java.time.temporal.ChronoUnit

object LogManager {

Expand All @@ -24,4 +26,12 @@ object LogManager {
}
}

fun removeFilesOlderThanDays(daysCount: Long, rootFile: File) {
val minimumBefore = Instant.now().minus(daysCount, ChronoUnit.DAYS)
(rootFile.listFiles()?.toList() ?: listOf())
.filter { it.isFile }
.filter { Instant.ofEpochMilli(it.lastModified()).isBefore(minimumBefore) }
.forEach { it.delete() }
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package com.github.markowanga.timberloggingtofile

import android.annotation.SuppressLint
import android.util.Base64
import javax.crypto.Cipher
import javax.crypto.SecretKey
import javax.crypto.spec.SecretKeySpec

fun ByteArray.toBase64(): String = Base64.encodeToString(this, Base64.DEFAULT)

fun String.toBytesFromBase64(): ByteArray =
Base64.decode(this, Base64.DEFAULT)
class TextCrypt(password: String) {


class TextCrypt(private val password: String) {

private val secretKey: SecretKey = generateKey()
private val secretKey: SecretKey = generateKey(password)

@SuppressLint("GetInstance")
private val encryptCipher = Cipher.getInstance("AES/ECB/PKCS5Padding")
Expand All @@ -24,7 +18,7 @@ class TextCrypt(private val password: String) {
private val decryptCipher = Cipher.getInstance("AES/ECB/PKCS5Padding")
.also { it.init(Cipher.DECRYPT_MODE, secretKey) }

private fun generateKey(): SecretKey {
private fun generateKey(password: String): SecretKey {
return SecretKeySpec(password.toByteArray(), "AES")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.markowanga.timberloggingtofile

import android.util.Base64


fun ByteArray.toBase64(): String = Base64.encodeToString(this, Base64.DEFAULT)

fun String.toBytesFromBase64(): ByteArray =
Base64.decode(this, Base64.DEFAULT)

0 comments on commit 52c5a0b

Please sign in to comment.