diff --git a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteModule.kt b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteModule.kt index af22612ffae0..83c46329dfc0 100644 --- a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteModule.kt +++ b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteModule.kt @@ -19,7 +19,9 @@ package com.duckduckgo.malicioussiteprotection.impl import android.content.Context import androidx.room.Room import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.malicioussiteprotection.impl.MaliciousSitesDatabase.Companion.ALL_MIGRATIONS +import com.duckduckgo.malicioussiteprotection.impl.data.db.MaliciousSiteDao +import com.duckduckgo.malicioussiteprotection.impl.data.db.MaliciousSitesDatabase +import com.duckduckgo.malicioussiteprotection.impl.data.db.MaliciousSitesDatabase.Companion.ALL_MIGRATIONS import com.squareup.anvil.annotations.ContributesTo import dagger.Module import dagger.Provides diff --git a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteRepository.kt b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/MaliciousSiteRepository.kt similarity index 79% rename from malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteRepository.kt rename to malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/MaliciousSiteRepository.kt index b111b0419256..4c5318667619 100644 --- a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteRepository.kt +++ b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/MaliciousSiteRepository.kt @@ -14,12 +14,15 @@ * limitations under the License. */ -package com.duckduckgo.malicioussiteprotection.impl +package com.duckduckgo.malicioussiteprotection.impl.data import com.duckduckgo.app.di.AppCoroutineScope import com.duckduckgo.app.di.IsMainProcess import com.duckduckgo.common.utils.DispatcherProvider import com.duckduckgo.di.scopes.AppScope +import com.duckduckgo.malicioussiteprotection.impl.MaliciousSiteProtectionFeature +import com.duckduckgo.malicioussiteprotection.impl.data.db.MaliciousSiteDao +import com.duckduckgo.malicioussiteprotection.impl.data.embedded.MaliciousSiteProtectionEmbeddedDataProvider import com.squareup.anvil.annotations.ContributesBinding import dagger.SingleInstanceIn import javax.inject.Inject @@ -69,9 +72,9 @@ class RealMaliciousSiteRepository @Inject constructor( phishingHashPrefixesRevision = embeddedPhishingHashPrefixes?.revision, malwareHashPrefixesRevision = embeddedMalwareHashPrefixes?.revision, phishingHashPrefixes = embeddedPhishingHashPrefixes?.insert?.toSet() ?: setOf(), - phishingFilterSet = embeddedPhishingFilterSet?.insert?.map { FilterEntity(it.hash, it.regex, type = "phishing") }?.toSet() ?: setOf(), + phishingFilterSet = embeddedPhishingFilterSet?.insert ?: setOf(), malwareHashPrefixes = embeddedMalwareHashPrefixes?.insert?.toSet() ?: setOf(), - malwareFilterSet = embeddedMalwareFilterSet?.insert?.map { FilterEntity(it.hash, it.regex, type = "malware") }?.toSet() ?: setOf(), + malwareFilterSet = embeddedMalwareFilterSet?.insert ?: setOf(), ) } @@ -85,3 +88,29 @@ class RealMaliciousSiteRepository @Inject constructor( } } } + +data class Match( + val hostname: String, + val url: String, + val regex: String, + val hash: String, +) + +data class HashPrefixResponse( + val insert: Set, + val delete: Set, + val revision: Int, + val replace: Boolean, +) + +data class FilterSetResponse( + val insert: Set, + val delete: Set, + val revision: Int, + val replace: Boolean, +) + +data class Filter( + val hash: String, + val regex: String, +) diff --git a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteDao.kt b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSiteDao.kt similarity index 90% rename from malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteDao.kt rename to malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSiteDao.kt index 42397875c07c..eca0e1630a07 100644 --- a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteDao.kt +++ b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSiteDao.kt @@ -14,13 +14,14 @@ * limitations under the License. */ -package com.duckduckgo.malicioussiteprotection.impl +package com.duckduckgo.malicioussiteprotection.impl.data.db import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import androidx.room.Transaction +import com.duckduckgo.malicioussiteprotection.impl.data.Filter import kotlin.math.max @Dao @@ -76,9 +77,9 @@ interface MaliciousSiteDao { phishingHashPrefixesRevision: Int?, malwareHashPrefixesRevision: Int?, phishingHashPrefixes: Set, - phishingFilterSet: Set, + phishingFilterSet: Set, malwareHashPrefixes: Set, - malwareFilterSet: Set, + malwareFilterSet: Set, ) { val lastRevision = getLatestRevision() deleteRevisions() @@ -92,8 +93,8 @@ interface MaliciousSiteDao { ), ) insertHashPrefixes(phishingHashPrefixes.map { HashPrefixEntity(hashPrefix = it, type = "phishing") }) - insertFilters(phishingFilterSet) + insertFilters(phishingFilterSet.map { FilterEntity(it.hash, it.regex, type = "phishing") }.toSet()) insertHashPrefixes(malwareHashPrefixes.map { HashPrefixEntity(hashPrefix = it, type = "malware") }) - insertFilters(malwareFilterSet) + insertFilters(malwareFilterSet.map { FilterEntity(it.hash, it.regex, type = "malware") }.toSet()) } } diff --git a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSitesDataEntities.kt b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSitesDataEntities.kt similarity index 96% rename from malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSitesDataEntities.kt rename to malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSitesDataEntities.kt index 59bb2afb3619..eb2c01b9d57d 100644 --- a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSitesDataEntities.kt +++ b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSitesDataEntities.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.malicioussiteprotection.impl +package com.duckduckgo.malicioussiteprotection.impl.data.db import androidx.room.Entity import androidx.room.PrimaryKey diff --git a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSitesDatabase.kt b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSitesDatabase.kt similarity index 94% rename from malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSitesDatabase.kt rename to malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSitesDatabase.kt index cab03f23be8d..0c6ee83cd9aa 100644 --- a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSitesDatabase.kt +++ b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/db/MaliciousSitesDatabase.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.malicioussiteprotection.impl +package com.duckduckgo.malicioussiteprotection.impl.data.db import androidx.room.Database import androidx.room.RoomDatabase diff --git a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteEmbeddedDataProvider.kt b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/embedded/MaliciousSiteEmbeddedDataProvider.kt similarity index 86% rename from malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteEmbeddedDataProvider.kt rename to malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/embedded/MaliciousSiteEmbeddedDataProvider.kt index f8ccbfdab6c8..c4d6cd4a2d57 100644 --- a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteEmbeddedDataProvider.kt +++ b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/data/embedded/MaliciousSiteEmbeddedDataProvider.kt @@ -14,11 +14,14 @@ * limitations under the License. */ -package com.duckduckgo.malicioussiteprotection.impl +package com.duckduckgo.malicioussiteprotection.impl.data.embedded import android.content.Context import androidx.annotation.RawRes import com.duckduckgo.di.scopes.AppScope +import com.duckduckgo.malicioussiteprotection.impl.R +import com.duckduckgo.malicioussiteprotection.impl.data.FilterSetResponse +import com.duckduckgo.malicioussiteprotection.impl.data.HashPrefixResponse import com.squareup.anvil.annotations.ContributesBinding import com.squareup.moshi.Moshi import javax.inject.Inject @@ -84,29 +87,3 @@ class RealMaliciousSiteProtectionEmbeddedDataProvider @Inject constructor( } } } - -data class Match( - val hostname: String, - val url: String, - val regex: String, - val hash: String, -) - -data class HashPrefixResponse( - val insert: Set, - val delete: Set, - val revision: Int, - val replace: Boolean, -) - -data class FilterSetResponse( - val insert: Set, - val delete: Set, - val revision: Int, - val replace: Boolean, -) - -data class Filter( - val hash: String, - val regex: String, -) diff --git a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/RealMaliciousSiteProtection.kt b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/domain/RealMaliciousSiteProtection.kt similarity index 95% rename from malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/RealMaliciousSiteProtection.kt rename to malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/domain/RealMaliciousSiteProtection.kt index 7e6a43b8fa56..7ee4496692bc 100644 --- a/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/RealMaliciousSiteProtection.kt +++ b/malicious-site-protection/malicious-site-protection-impl/src/main/kotlin/com/duckduckgo/malicioussiteprotection/impl/domain/RealMaliciousSiteProtection.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.malicioussiteprotection.impl +package com.duckduckgo.malicioussiteprotection.impl.domain import android.net.Uri import com.duckduckgo.app.di.AppCoroutineScope @@ -22,6 +22,7 @@ import com.duckduckgo.app.di.IsMainProcess import com.duckduckgo.common.utils.DispatcherProvider import com.duckduckgo.di.scopes.AppScope import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection +import com.duckduckgo.malicioussiteprotection.impl.MaliciousSiteProtectionFeature import com.duckduckgo.privacy.config.api.PrivacyConfigCallbackPlugin import com.squareup.anvil.annotations.ContributesBinding import com.squareup.anvil.annotations.ContributesMultibinding diff --git a/malicious-site-protection/malicious-site-protection-impl/src/test/kotlin/com/duckduckgo/malicioussiteprotection/impl/RealMaliciousSiteProtectionTest.kt b/malicious-site-protection/malicious-site-protection-impl/src/test/kotlin/com/duckduckgo/malicioussiteprotection/impl/RealMaliciousSiteProtectionTest.kt new file mode 100644 index 000000000000..e69de29bb2d1