Skip to content

Commit

Permalink
Feature/partialvariablefilter (eu-digital-green-certificates#293)
Browse files Browse the repository at this point in the history
* - add working partial variable hash filter functionality;

* - remove hashList slices entity with dao methods;
- update test data generation for hashvariable filter type;
- update filter functionality;

* - convert dcc hash hex to bytearray;
- simplified logic for hash type check;

* - version update;
  • Loading branch information
MykhailoNester authored Mar 17, 2022
1 parent ec5b567 commit 4fa6d37
Show file tree
Hide file tree
Showing 29 changed files with 969 additions and 839 deletions.

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import dcc.app.revocation.data.local.EnumConverter
import dgca.verifier.app.android.data.local.dcc.revocation.DccRevocationDao
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationHashListSliceLocal
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationKidMetadataLocal
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationPartitionLocal
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationSliceLocal
Expand All @@ -39,8 +38,7 @@ import dgca.verifier.app.android.data.local.rules.Converters
Key::class,
DccRevocationKidMetadataLocal::class,
DccRevocationPartitionLocal::class,
DccRevocationSliceLocal::class,
DccRevocationHashListSliceLocal::class
DccRevocationSliceLocal::class
],
version = 1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package dgca.verifier.app.android.data.local.dcc.revocation

import androidx.room.*
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationHashListSliceLocal
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationKidMetadataLocal
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationPartitionLocal
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationSliceLocal
Expand All @@ -43,22 +42,6 @@ interface DccRevocationDao {
@Query("SELECT * FROM dcc_revocation_slice WHERE kid is :kid AND x is :x AND y is :y AND cid is :cid")
suspend fun getChunkSlices(kid: String, x: Char?, y: Char?, cid: String): List<DccRevocationSliceLocal>

@Query("SELECT * FROM dcc_revocation_hashlist_slice WHERE sid IN (:sidList) AND x is :x AND y is :y AND hash is :dccHashListBytes")
suspend fun getHashListSlice(
sidList: Set<String>,
x: Char?,
y: Char?,
dccHashListBytes: ByteArray
): DccRevocationHashListSliceLocal?

@Query("SELECT * FROM dcc_revocation_hashlist_slice WHERE sid IN (:sidList) AND x is :x AND y is :y AND substr(:hash, 1, length(hash)) like hash")
suspend fun getHashListSlices(
sidList: Set<String>,
x: Char?,
y: Char?,
hash: String
): List<DccRevocationHashListSliceLocal>

@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insert(entity: DccRevocationKidMetadataLocal): Long

Expand Down Expand Up @@ -108,9 +91,6 @@ interface DccRevocationDao {
removeOutdatedSlices(kidList)
}

@Insert(entity = DccRevocationHashListSliceLocal::class, onConflict = OnConflictStrategy.REPLACE)
suspend fun insertHashListSlices(list: List<DccRevocationHashListSliceLocal>)

@Query("DELETE FROM dcc_revocation_kid_metadata WHERE kid NOT IN (:kidList)")
suspend fun removeOutdatedKidMetadata(kidList: List<String>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
package dgca.verifier.app.android.data.local.dcc.revocation

import dcc.app.revocation.data.local.DccRevocationLocalDataSource
import dcc.app.revocation.domain.model.DccRevocationHashListSlice
import dcc.app.revocation.domain.model.DccRevocationKidMetadata
import dcc.app.revocation.domain.model.DccRevocationPartition
import dcc.app.revocation.domain.model.DccRevocationSlice
import dgca.verifier.app.android.data.local.dcc.revocation.mapper.fromLocal
import dgca.verifier.app.android.data.local.dcc.revocation.mapper.toLocal

class DccRevocationLocalDataSourceImpl(private val dccRevocationDao: DccRevocationDao) :
DccRevocationLocalDataSource {
class DccRevocationLocalDataSourceImpl(private val dccRevocationDao: DccRevocationDao) : DccRevocationLocalDataSource {

override suspend fun getDccRevocationKidMetadataBy(kid: String): DccRevocationKidMetadata? =
dccRevocationDao.getDccRevocationKidMetadataBy(kid)?.fromLocal()
Expand All @@ -57,23 +55,6 @@ class DccRevocationLocalDataSourceImpl(private val dccRevocationDao: DccRevocati
): List<DccRevocationSlice> =
dccRevocationDao.getChunkSlices(kid, x, y, cid).map { it.fromLocal() }

override suspend fun getHashListSlice(
sidList: Set<String>,
x: Char?,
y: Char?,
dccHashListBytes: ByteArray
): DccRevocationHashListSlice? =
dccRevocationDao.getHashListSlice(sidList, x, y, dccHashListBytes)?.fromLocal()

override suspend fun getHashListSlices(
sidList: Set<String>,
x: Char?,
y: Char?,
dccHash: String
): List<DccRevocationHashListSlice> {
return dccRevocationDao.getHashListSlices(sidList, x, y, dccHash).map { it.fromLocal() }
}

override fun addOrUpdate(dccRevocationKidMetadata: DccRevocationKidMetadata) {
dccRevocationDao.upsert(dccRevocationKidMetadata.toLocal())
}
Expand All @@ -86,10 +67,6 @@ class DccRevocationLocalDataSourceImpl(private val dccRevocationDao: DccRevocati
dccRevocationDao.upsert(dccRevocationSlice.toLocal())
}

override suspend fun saveHashListSlices(hashListSlices: List<DccRevocationHashListSlice>) {
dccRevocationDao.insertHashListSlices(hashListSlices.map { it.toLocal() })
}

override suspend fun removeOutdatedKidItems(kidList: List<String>) {
dccRevocationDao.removeOutdatedKidItems(kidList)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
package dgca.verifier.app.android.data.local.dcc.revocation.mapper

import dcc.app.revocation.data.network.model.SliceType
import dcc.app.revocation.domain.model.*
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationHashListSliceLocal
import dcc.app.revocation.domain.model.DccRevocationKidMetadata
import dcc.app.revocation.domain.model.DccRevocationPartition
import dcc.app.revocation.domain.model.DccRevocationSlice
import dcc.app.revocation.domain.model.DccSliceType
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationKidMetadataLocal
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationPartitionLocal
import dgca.verifier.app.android.data.local.dcc.revocation.model.DccRevocationSliceLocal
Expand Down Expand Up @@ -88,8 +90,7 @@ fun DccRevocationSliceLocal.fromLocal(): DccRevocationSlice {
fun DccSliceType.toSliceType(): SliceType =
when (this) {
DccSliceType.BF -> SliceType.BLOOMFILTER
DccSliceType.HASH -> SliceType.HASH
DccSliceType.PARTIAL_VARIABLE_LENGTH_HASH -> SliceType.PARTIAL_VARIABLE_LENGTH
DccSliceType.VARHASHLIST -> SliceType.VARHASHLIST
}

fun DccRevocationSlice.toLocal(): DccRevocationSliceLocal {
Expand All @@ -109,22 +110,5 @@ fun DccRevocationSlice.toLocal(): DccRevocationSliceLocal {
fun SliceType.toDccSliceType(): DccSliceType =
when (this) {
SliceType.BLOOMFILTER -> DccSliceType.BF
SliceType.HASH -> DccSliceType.HASH
SliceType.PARTIAL_VARIABLE_LENGTH -> DccSliceType.PARTIAL_VARIABLE_LENGTH_HASH
}

fun DccRevocationHashListSlice.toLocal(): DccRevocationHashListSliceLocal =
DccRevocationHashListSliceLocal(
sid = sid,
x = x,
y = y,
hash = hash
)

fun DccRevocationHashListSliceLocal.fromLocal(): DccRevocationHashListSlice =
DccRevocationHashListSlice(
sid = sid,
x = x,
y = y,
hash = hash
)
SliceType.VARHASHLIST -> DccSliceType.VARHASHLIST
}

This file was deleted.

Loading

0 comments on commit 4fa6d37

Please sign in to comment.