-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/qr code detection update (#102)
* Added scanning QR code * Added scanning of QRs fetched from taking photo * Extracted logic to fetch green certificate * Extracted request keys for adding qrs * Updated PDF scanning logic * Fixed PDF scanning logic
- Loading branch information
1 parent
89002fd
commit 08a878d
Showing
10 changed files
with
207 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
app/src/main/java/dgca/wallet/app/android/certificate/DefaultGreenCertificateFetcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* ---license-start | ||
* eu-digital-green-certificates / dgca-wallet-app-android | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
* | ||
* Created by osarapulov on 8/26/21 10:36 AM | ||
*/ | ||
|
||
package dgca.wallet.app.android.certificate | ||
|
||
import dgca.verifier.app.decoder.base45.Base45Service | ||
import dgca.verifier.app.decoder.cbor.CborService | ||
import dgca.verifier.app.decoder.compression.CompressorService | ||
import dgca.verifier.app.decoder.cose.CoseService | ||
import dgca.verifier.app.decoder.model.GreenCertificate | ||
import dgca.verifier.app.decoder.model.VerificationResult | ||
import dgca.verifier.app.decoder.prefixvalidation.PrefixValidationService | ||
import dgca.verifier.app.decoder.schema.SchemaValidator | ||
import timber.log.Timber | ||
|
||
class DefaultGreenCertificateFetcher( | ||
private val prefixValidationService: PrefixValidationService, | ||
private val base45Service: Base45Service, | ||
private val compressorService: CompressorService, | ||
private val coseService: CoseService, | ||
private val schemaValidator: SchemaValidator, | ||
private val cborService: CborService, | ||
) : GreenCertificateFetcher { | ||
override fun fetchDataFromQrString(qrString: String): Pair<ByteArray?, GreenCertificate?> { | ||
val verificationResult = VerificationResult() | ||
val plainInput = prefixValidationService.decode(qrString, verificationResult) | ||
val compressedCose = base45Service.decode(plainInput, verificationResult) | ||
val coseResult: ByteArray? = compressorService.decode(compressedCose, verificationResult) | ||
|
||
if (coseResult == null) { | ||
Timber.d("Verification failed: Too many bytes read") | ||
return Pair(null, null) | ||
} | ||
val cose: ByteArray = coseResult | ||
|
||
val coseData = coseService.decode(cose, verificationResult) | ||
if (coseData == null) { | ||
Timber.d("Verification failed: COSE not decoded") | ||
return Pair(cose, null) | ||
} | ||
|
||
schemaValidator.validate(coseData.cbor, verificationResult) | ||
return Pair(cose, cborService.decode(coseData.cbor, verificationResult)) | ||
} | ||
|
||
override fun fetchGreenCertificateFromQrString(qrString: String): GreenCertificate? = fetchDataFromQrString(qrString).second | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/dgca/wallet/app/android/certificate/GreenCertificateFetcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* ---license-start | ||
* eu-digital-green-certificates / dgca-wallet-app-android | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
* | ||
* Created by osarapulov on 8/26/21 10:35 AM | ||
*/ | ||
|
||
package dgca.wallet.app.android.certificate | ||
|
||
import dgca.verifier.app.decoder.model.GreenCertificate | ||
|
||
interface GreenCertificateFetcher { | ||
fun fetchDataFromQrString(qrString: String): Pair<ByteArray?, GreenCertificate?> | ||
|
||
fun fetchGreenCertificateFromQrString(qrString: String): GreenCertificate? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.