Conversation
Summary of ChangesHello @cy245, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates new digital credential management capabilities by updating project dependencies and introducing a dedicated Kotlin file for handling digital credential operations. The changes enable the application to register, process, and respond to digital credential requests, laying the groundwork for enhanced identity features. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request introduces new dependencies for digital credentials and adds a new activity DigitalCredentialHolderActivity containing several code snippets for handling these credentials. I've identified several issues in the new file, including missing variable definitions (TAG), potential nullability and index-out-of-bounds errors in certificate hashing, and opportunities to use more idiomatic Kotlin features like map instead of manual loops. Additionally, there are some unused variables and empty catch blocks that should be addressed to improve code quality and maintainability.
| // [START android_identity_process_selected_credential] | ||
| request.credentialOptions.forEach { option -> | ||
| if (option is GetDigitalCredentialOption) { | ||
| Log.i(TAG, "Got DC request: ${option.requestJson}") |
| val appSigningInfo = request?.callingAppInfo?.signingInfoCompat?.signingCertificateHistory[0]?.toByteArray() | ||
| val md = MessageDigest.getInstance("SHA-256") | ||
| val certHash = Base64.encodeToString(md.digest(appSigningInfo), Base64.NO_WRAP or Base64.NO_PADDING) | ||
| return "android:apk-key-hash:$certHash" |
There was a problem hiding this comment.
This block has several issues that will prevent compilation or cause crashes:
signingCertificateHistoryis accessed via a nullable chain, so[0]cannot be called directly without a null-safe operator (e.g.,?.get(0)).appSigningInfois nullable, butmd.digest()requires a non-nullByteArray. Passing a null value will result in aNullPointerException.- Accessing index
[0]without checking if the array is empty can cause anIndexOutOfBoundsException.
val appSigningInfo = request?.callingAppInfo?.signingInfoCompat?.signingCertificateHistory?.firstOrNull()?.toByteArray()
if (appSigningInfo == null) return ""
val md = MessageDigest.getInstance("SHA-256")
val certHash = Base64.encodeToString(md.digest(appSigningInfo), Base64.NO_WRAP or Base64.NO_PADDING)
return "android:apk-key-hash:$certHash"| } catch (e: Exception) { | ||
| // Handle exceptions | ||
| } |
| val list = mutableListOf<SdJwtEntry>() | ||
|
|
||
| for (sdJwt in sdJwtsFromStorage) { | ||
| list.add( | ||
| SdJwtEntry( | ||
| verifiableCredentialType = sdJwt.getVCT(), | ||
| claims = sdJwt.getClaimsList(), | ||
| entryDisplayPropertySet = sdJwt.toDisplayProperties(), | ||
| id = sdJwt.getId() // Make sure this cannot be readily guessed | ||
| ) | ||
| ) | ||
| } | ||
| return list |
There was a problem hiding this comment.
This loop can be simplified using the map function for better readability and idiomatic Kotlin.
return sdJwtsFromStorage.map { sdJwt ->
SdJwtEntry(
verifiableCredentialType = sdJwt.getVCT(),
claims = sdJwt.getClaimsList(),
entryDisplayPropertySet = sdJwt.toDisplayProperties(),
id = sdJwt.getId() // Make sure this cannot be readily guessed
)
}| val list = mutableListOf<MdocEntry>() | ||
|
|
||
| for (mdoc in mdocsFromStorage) { | ||
| list.add( | ||
| MdocEntry( | ||
| docType = mdoc.retrieveDocType(), | ||
| fields = mdoc.getFields(), | ||
| entryDisplayPropertySet = mdoc.toDisplayProperties(), | ||
| id = mdoc.getId() // Make sure this cannot be readily guessed | ||
| ) | ||
| ) | ||
| } | ||
| return list |
There was a problem hiding this comment.
This loop can be simplified using the map function for better readability and idiomatic Kotlin.
return mdocsFromStorage.map { mdoc ->
MdocEntry(
docType = mdoc.retrieveDocType(),
fields = mdoc.getFields(),
entryDisplayPropertySet = mdoc.toDisplayProperties(),
id = mdoc.getId() // Make sure this cannot be readily guessed
)
}|
|
||
| // [START android_identity_register_credentials_registrymanager] | ||
| try { | ||
| val response = registryManager.registerCredentials(openidRegistryRequest) |
No description provided.