diff --git a/appholder/src/main/java/com/android/identity/wallet/trustmanagement/X509CertificateExtensions.kt b/appholder/src/main/java/com/android/identity/wallet/trustmanagement/X509CertificateExtensions.kt index 70be11b04..fe32decec 100644 --- a/appholder/src/main/java/com/android/identity/wallet/trustmanagement/X509CertificateExtensions.kt +++ b/appholder/src/main/java/com/android/identity/wallet/trustmanagement/X509CertificateExtensions.kt @@ -14,5 +14,5 @@ fun X509Certificate.getSubjectKeyIdentifier(): String { val extensionValue = this.getExtensionValue(Extension.subjectKeyIdentifier.id) val octets = DEROctetString.getInstance(extensionValue).octets val subjectKeyIdentifier = SubjectKeyIdentifier.getInstance(octets) - return subjectKeyIdentifier.keyIdentifier.toHex + return subjectKeyIdentifier.keyIdentifier.toHex() } \ No newline at end of file diff --git a/appholder/src/main/java/com/android/identity/wallet/util/ProvisioningUtil.kt b/appholder/src/main/java/com/android/identity/wallet/util/ProvisioningUtil.kt index 0aeba3541..04f3b55b4 100644 --- a/appholder/src/main/java/com/android/identity/wallet/util/ProvisioningUtil.kt +++ b/appholder/src/main/java/com/android/identity/wallet/util/ProvisioningUtil.kt @@ -207,7 +207,7 @@ class ProvisioningUtil private constructor( protectedHeaders = mapOf( Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - Algorithm.ES256.coseAlgorithmIdentifier.toDataItem + Algorithm.ES256.coseAlgorithmIdentifier.toDataItem() ) ), unprotectedHeaders = mapOf( @@ -215,10 +215,10 @@ class ProvisioningUtil private constructor( CoseNumberLabel(Cose.COSE_LABEL_X5CHAIN), X509CertChain( listOf(X509Cert(issuerCert.encoded)) - ).toDataItem + ).toDataItem() ) ), - ).toDataItem + ).toDataItem() ) val issuerProvidedAuthenticationData = StaticAuthDataGenerator( diff --git a/appverifier/src/main/java/com/android/mdl/appreader/trustmanagement/X509CertificateExtensions.kt b/appverifier/src/main/java/com/android/mdl/appreader/trustmanagement/X509CertificateExtensions.kt index 3e38535b3..38c8fd848 100644 --- a/appverifier/src/main/java/com/android/mdl/appreader/trustmanagement/X509CertificateExtensions.kt +++ b/appverifier/src/main/java/com/android/mdl/appreader/trustmanagement/X509CertificateExtensions.kt @@ -14,5 +14,5 @@ fun X509Certificate.getSubjectKeyIdentifier(): String { val extensionValue = this.getExtensionValue(Extension.subjectKeyIdentifier.id) val octets = DEROctetString.getInstance(extensionValue).octets val subjectKeyIdentifier = SubjectKeyIdentifier.getInstance(octets) - return subjectKeyIdentifier.keyIdentifier.toHex + return subjectKeyIdentifier.keyIdentifier.toHex() } \ No newline at end of file diff --git a/identity-android/src/androidTest/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelperTest.kt b/identity-android/src/androidTest/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelperTest.kt index 84b3860b2..ef915fc11 100644 --- a/identity-android/src/androidTest/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelperTest.kt +++ b/identity-android/src/androidTest/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelperTest.kt @@ -198,11 +198,11 @@ class DeviceRetrievalHelperTest { // val protectedHeaders = java.util.Map.of( CoseNumberLabel(Cose.COSE_LABEL_ALG), - Algorithm.ES256.coseAlgorithmIdentifier.toDataItem + Algorithm.ES256.coseAlgorithmIdentifier.toDataItem() ) val unprotectedHeaders = java.util.Map.of( CoseNumberLabel(Cose.COSE_LABEL_X5CHAIN), - X509CertChain(listOf(documentSignerCert)).toDataItem + X509CertChain(listOf(documentSignerCert)).toDataItem() ) val encodedIssuerAuth = encode( coseSign1Sign( @@ -212,7 +212,7 @@ class DeviceRetrievalHelperTest { Algorithm.ES256, protectedHeaders, unprotectedHeaders - ).toDataItem + ).toDataItem() ) val issuerProvidedAuthenticationData = StaticAuthDataGenerator( stripIssuerNameSpaces(issuerNameSpaces, null), @@ -269,7 +269,7 @@ class DeviceRetrievalHelperTest { val encodedDeviceEngagement = qrHelper.deviceEngagement val eReaderKey = createEcPrivateKey(EcCurve.P256) val encodedEReaderKeyPub = - encode(eReaderKey.publicKey.toCoseKey(java.util.Map.of()).toDataItem) + encode(eReaderKey.publicKey.toCoseKey(java.util.Map.of()).toDataItem()) val encodedSessionTranscript = encode( CborArray.builder() .addTaggedEncodedCbor(encodedDeviceEngagement) @@ -484,7 +484,7 @@ class DeviceRetrievalHelperTest { val encodedDeviceEngagement = qrHelper.deviceEngagement val eReaderKey = createEcPrivateKey(EcCurve.P256) val encodedEReaderKeyPub = - encode(eReaderKey.publicKey.toCoseKey(java.util.Map.of()).toDataItem) + encode(eReaderKey.publicKey.toCoseKey(java.util.Map.of()).toDataItem()) val encodedSessionTranscript = encode( CborArray.builder() .addTaggedEncodedCbor(encodedDeviceEngagement) diff --git a/identity-android/src/androidTest/java/com/android/identity/android/mdoc/engagement/NfcEnagementHelperTest.kt b/identity-android/src/androidTest/java/com/android/identity/android/mdoc/engagement/NfcEnagementHelperTest.kt index a334eb243..b2bb303dc 100644 --- a/identity-android/src/androidTest/java/com/android/identity/android/mdoc/engagement/NfcEnagementHelperTest.kt +++ b/identity-android/src/androidTest/java/com/android/identity/android/mdoc/engagement/NfcEnagementHelperTest.kt @@ -127,7 +127,7 @@ class NfcEnagementHelperTest { Assert.assertNotNull(responseApdu) // The response is the CC file followed by STATUS_WORD_OK. Keep in sync with // NfcEngagementHelper.handleSelectFile() for the contents. - Assert.assertEquals("000f207fff7fff0406e1047fff00ff9000", responseApdu.toHex) + Assert.assertEquals("000f207fff7fff0406e1047fff00ff9000", responseApdu.toHex()) // Select NDEF file responseApdu = helper.nfcProcessCommandApdu( @@ -268,7 +268,7 @@ class NfcEnagementHelperTest { Assert.assertNotNull(responseApdu) // The response is the CC file followed by STATUS_WORD_OK. Keep in sync with // NfcEngagementHelper.handleSelectFile() for the contents. - Assert.assertEquals("000f207fff7fff0406e1047fff00009000", responseApdu.toHex) + Assert.assertEquals("000f207fff7fff0406e1047fff00009000", responseApdu.toHex()) // Select NDEF file responseApdu = helper.nfcProcessCommandApdu( diff --git a/identity-android/src/androidTest/java/com/android/identity/android/mdoc/transport/DataTransportHttpTest.kt b/identity-android/src/androidTest/java/com/android/identity/android/mdoc/transport/DataTransportHttpTest.kt index 0d7ce292f..fbe9ecadd 100644 --- a/identity-android/src/androidTest/java/com/android/identity/android/mdoc/transport/DataTransportHttpTest.kt +++ b/identity-android/src/androidTest/java/com/android/identity/android/mdoc/transport/DataTransportHttpTest.kt @@ -84,8 +84,8 @@ class DataTransportHttpTest { null, DataTransportOptions.Builder().build() ) - val messageSentByVerifier = "010203".fromHex - val messageSentByProver = "0405".fromHex + val messageSentByVerifier = "010203".fromHex() + val messageSentByProver = "0405".fromHex() val messageReceivedByProver = arrayOf(null) val messageReceivedByVerifier = arrayOf(null) val proverMessageReceivedCondVar = ConditionVariable() diff --git a/identity-android/src/androidTest/java/com/android/identity/android/mdoc/transport/DataTransportTcpTest.kt b/identity-android/src/androidTest/java/com/android/identity/android/mdoc/transport/DataTransportTcpTest.kt index 00a526923..6079380b0 100644 --- a/identity-android/src/androidTest/java/com/android/identity/android/mdoc/transport/DataTransportTcpTest.kt +++ b/identity-android/src/androidTest/java/com/android/identity/android/mdoc/transport/DataTransportTcpTest.kt @@ -40,8 +40,8 @@ class DataTransportTcpTest { DataTransport.Role.MDOC, DataTransportOptions.Builder().build() ) - val messageSentByVerifier = "010203".fromHex - val messageSentByProver = "0405".fromHex + val messageSentByVerifier = "010203".fromHex() + val messageSentByProver = "0405".fromHex() val messageReceivedByProver = arrayOf(null) val messageReceivedByVerifier = arrayOf(null) val proverMessageReceivedCondVar = ConditionVariable() diff --git a/identity-android/src/androidTest/java/com/android/identity/android/storage/AndroidStorageTest.kt b/identity-android/src/androidTest/java/com/android/identity/android/storage/AndroidStorageTest.kt index 914db505c..4bed507d1 100644 --- a/identity-android/src/androidTest/java/com/android/identity/android/storage/AndroidStorageTest.kt +++ b/identity-android/src/androidTest/java/com/android/identity/android/storage/AndroidStorageTest.kt @@ -86,7 +86,7 @@ class AndroidStorageTest { storage.put("foo", data) var targetFile = File(storageDir, PREFIX + URLEncoder.encode("foo", "UTF-8")) var fileContents = AtomicFile(targetFile).readFully() - Assert.assertEquals(-1, (fileContents.toHex).indexOf(data.toHex).toLong()) + Assert.assertEquals(-1, (fileContents.toHex()).indexOf(data.toHex()).toLong()) // Try again without encryption. The data should start at offset 4. storage = AndroidStorageEngine.Builder(context, storageDir) diff --git a/identity-android/src/androidTest/java/com/android/identity/mdoc/connectionmethod/ConnectionMethodNdefTest.kt b/identity-android/src/androidTest/java/com/android/identity/mdoc/connectionmethod/ConnectionMethodNdefTest.kt index 7e2a58eeb..519386022 100644 --- a/identity-android/src/androidTest/java/com/android/identity/mdoc/connectionmethod/ConnectionMethodNdefTest.kt +++ b/identity-android/src/androidTest/java/com/android/identity/mdoc/connectionmethod/ConnectionMethodNdefTest.kt @@ -109,11 +109,11 @@ class ConnectionMethodNdefTest { Assert.assertEquals(uuidBoth, decoded.centralClientModeUuid) Assert.assertEquals( "da2015016170706c69636174696f6e2f766e642e626c7565746f6f74682e6c652e6f6f6230021c03110702000000000000000000000000000000", - pair.first.toByteArray().toHex + pair.first.toByteArray().toHex() ) Assert.assertEquals( "01013001046d646f63", - pair.second.toHex + pair.second.toHex() ) val hrPair = NfcUtil.toNdefRecord(cm, listOf(""), false) Assert.assertArrayEquals(pair.first.toByteArray(), hrPair!!.first.toByteArray()) @@ -161,11 +161,11 @@ class ConnectionMethodNdefTest { Assert.assertEquals(uuid, decoded.centralClientModeUuid) Assert.assertEquals( "da2015016170706c69636174696f6e2f766e642e626c7565746f6f74682e6c652e6f6f6230021c011107b168de3a0000000015cd5b0700000000", - pair.first.toByteArray().toHex + pair.first.toByteArray().toHex() ) Assert.assertEquals( "01013001046d646f63", - pair.second!!.toHex + pair.second!!.toHex() ) pair = NfcUtil.toNdefRecord(cm, emptyList(), false) decoded = fromNdefRecord(pair!!.first, false) @@ -176,9 +176,9 @@ class ConnectionMethodNdefTest { Assert.assertEquals(uuid, decoded.centralClientModeUuid) Assert.assertEquals( "da2015016170706c69636174696f6e2f766e642e626c7565746f6f74682e6c652e6f6f6230021c001107b168de3a0000000015cd5b0700000000", - pair.first.toByteArray().toHex + pair.first.toByteArray().toHex() ) - Assert.assertEquals("01013000", pair.second!!.toHex) + Assert.assertEquals("01013000", pair.second!!.toHex()) } @Test @@ -223,11 +223,11 @@ class ConnectionMethodNdefTest { Assert.assertNull(decoded.centralClientModeUuid) Assert.assertEquals( "da2015016170706c69636174696f6e2f766e642e626c7565746f6f74682e6c652e6f6f6230021c00110701000000000000000000000000000000", - pair.first.toByteArray().toHex + pair.first.toByteArray().toHex() ) Assert.assertEquals( "01013001046d646f63", - pair.second!!.toHex + pair.second!!.toHex() ) pair = NfcUtil.toNdefRecord(cm, emptyList(), false) decoded = fromNdefRecord(pair!!.first, false) @@ -238,9 +238,9 @@ class ConnectionMethodNdefTest { Assert.assertNull(decoded.centralClientModeUuid) Assert.assertEquals( "da2015016170706c69636174696f6e2f766e642e626c7565746f6f74682e6c652e6f6f6230021c01110701000000000000000000000000000000", - pair.first.toByteArray().toHex + pair.first.toByteArray().toHex() ) - Assert.assertEquals("01013000", pair.second!!.toHex) + Assert.assertEquals("01013000", pair.second!!.toHex()) } @Test @@ -273,7 +273,7 @@ class ConnectionMethodNdefTest { @Throws(FormatException::class) fun testConnectionMethodVector() { val ndefHsMessage = - NdefMessage("91020f487315d10209616301013001046d646f631a2003016170706c69636174696f6e2f766e642e626c7565746f6f74682e6c652e6f6f6230021c015c1e580469736f2e6f72673a31383031333a646576696365656e676167656d656e746d646f63a20063312e30018201d818584ba401022001215820e778fcb1513fad715c755462cb4d3ee3c1de2f618d10e07788a35eda2da58b982258205e6ee59512414cdb11ee330db2590ab6d1b5a78ede4a0ecac02e3af65cafbcd9".fromHex) + NdefMessage("91020f487315d10209616301013001046d646f631a2003016170706c69636174696f6e2f766e642e626c7565746f6f74682e6c652e6f6f6230021c015c1e580469736f2e6f72673a31383031333a646576696365656e676167656d656e746d646f63a20063312e30018201d818584ba401022001215820e778fcb1513fad715c755462cb4d3ee3c1de2f618d10e07788a35eda2da58b982258205e6ee59512414cdb11ee330db2590ab6d1b5a78ede4a0ecac02e3af65cafbcd9".fromHex()) Assert.assertNotNull(ndefHsMessage) var cm: ConnectionMethodBle? = null for (r in ndefHsMessage.records) { diff --git a/identity-android/src/main/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelper.kt b/identity-android/src/main/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelper.kt index 396be853c..ff2962fb3 100644 --- a/identity-android/src/main/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelper.kt +++ b/identity-android/src/main/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelper.kt @@ -232,7 +232,7 @@ class DeviceRetrievalHelper internal constructor( val encodedEDeviceKeyBytes: ByteArray = Cbor.encode( Tagged( 24, Bstr( - Cbor.encode(eDeviceKey.toCoseKey().toDataItem) + Cbor.encode(eDeviceKey.toCoseKey().toDataItem()) ) ) ) diff --git a/identity-android/src/main/java/com/android/identity/android/mdoc/deviceretrieval/VerificationHelper.kt b/identity-android/src/main/java/com/android/identity/android/mdoc/deviceretrieval/VerificationHelper.kt index 488823a74..f224b367a 100644 --- a/identity-android/src/main/java/com/android/identity/android/mdoc/deviceretrieval/VerificationHelper.kt +++ b/identity-android/src/main/java/com/android/identity/android/mdoc/deviceretrieval/VerificationHelper.kt @@ -715,7 +715,7 @@ class VerificationHelper internal constructor( // to avoid delaying the transaction... ephemeralKey = Crypto.createEcPrivateKey(engagement.eSenderKey.curve) val encodedEReaderKeyPub: ByteArray = Cbor.encode( - ephemeralKey!!.publicKey.toCoseKey().toDataItem + ephemeralKey!!.publicKey.toCoseKey().toDataItem() ) encodedSessionTranscript = Cbor.encode( CborArray.builder() diff --git a/identity-android/src/main/java/com/android/identity/android/mdoc/engagement/NfcEngagementHelper.kt b/identity-android/src/main/java/com/android/identity/android/mdoc/engagement/NfcEngagementHelper.kt index 938b1221e..d4980fbd1 100644 --- a/identity-android/src/main/java/com/android/identity/android/mdoc/engagement/NfcEngagementHelper.kt +++ b/identity-android/src/main/java/com/android/identity/android/mdoc/engagement/NfcEngagementHelper.kt @@ -126,7 +126,7 @@ class NfcEngagementHelper private constructor( Logger.d(TAG, "Setting up transports") val timeStartedSettingUpTransports = System.currentTimeMillis() val encodedEDeviceKeyBytes = Cbor.encode( - Tagged(24, Bstr(Cbor.encode(eDeviceKey.toCoseKey().toDataItem)))) + Tagged(24, Bstr(Cbor.encode(eDeviceKey.toCoseKey().toDataItem())))) // Need to disambiguate the connection methods here to get e.g. two ConnectionMethods // if both BLE modes are available at the same time. diff --git a/identity-android/src/main/java/com/android/identity/android/mdoc/engagement/QrEngagementHelper.kt b/identity-android/src/main/java/com/android/identity/android/mdoc/engagement/QrEngagementHelper.kt index eae4f73c7..5f0b119e6 100644 --- a/identity-android/src/main/java/com/android/identity/android/mdoc/engagement/QrEngagementHelper.kt +++ b/identity-android/src/main/java/com/android/identity/android/mdoc/engagement/QrEngagementHelper.kt @@ -66,7 +66,7 @@ class QrEngagementHelper internal constructor( init { val encodedEDeviceKeyBytes = - Cbor.encode(Tagged(24, Bstr(Cbor.encode(eDeviceKey.toCoseKey().toDataItem)))) + Cbor.encode(Tagged(24, Bstr(Cbor.encode(eDeviceKey.toCoseKey().toDataItem())))) // Set EDeviceKey for transports we were given. if (transports != null) { diff --git a/identity-android/src/main/java/com/android/identity/android/mdoc/transport/GattClient.kt b/identity-android/src/main/java/com/android/identity/android/mdoc/transport/GattClient.kt index a7d71132e..7d77d527b 100644 --- a/identity-android/src/main/java/com/android/identity/android/mdoc/transport/GattClient.kt +++ b/identity-android/src/main/java/com/android/identity/android/mdoc/transport/GattClient.kt @@ -263,13 +263,13 @@ internal class GattClient( if (characteristic.uuid == characteristicIdentUuid) { val identValue = characteristic.value if (Logger.isDebugEnabled) { - Logger.d(TAG, "Received identValue: ${identValue.toHex}") + Logger.d(TAG, "Received identValue: ${identValue.toHex()}") } // TODO: Don't even request IDENT since it cannot work w/ reverse engagement (there's // no way the mdoc reader knows EDeviceKeyBytes at this point) and it's also optional. if (!Arrays.equals(identValue, this.identValue)) { - Logger.w(TAG, "Received ident '${identValue.toHex}' does not match " + - "expected ident '${this.identValue!!.toHex}'") + Logger.w(TAG, "Received ident '${identValue.toHex()}' does not match " + + "expected ident '${this.identValue!!.toHex()}'") } afterIdentObtained(gatt) } else if (characteristic.uuid == characteristicL2CAPUuid) { diff --git a/identity-android/src/main/java/com/android/identity/android/mdoc/transport/GattServer.kt b/identity-android/src/main/java/com/android/identity/android/mdoc/transport/GattServer.kt index d3b4c7b5b..92d28ba67 100644 --- a/identity-android/src/main/java/com/android/identity/android/mdoc/transport/GattServer.kt +++ b/identity-android/src/main/java/com/android/identity/android/mdoc/transport/GattServer.kt @@ -279,7 +279,7 @@ internal class GattServer( ) { val charUuid = characteristic.uuid Logger.d(TAG, "onCharacteristicWriteRequest: ${device.address} $requestId " + - "$offset ${characteristic.uuid} ${value.toHex}") + "$offset ${characteristic.uuid} ${value.toHex()}") // If we are connected to a device, ignore write from any other device if (currentConnection != null && @@ -387,7 +387,7 @@ internal class GattServer( if (Logger.isDebugEnabled) { Logger.d( TAG, "onDescriptorWriteRequest: ${device.address}" + - "${descriptor.characteristic.uuid} $offset ${value.toHex}" + "${descriptor.characteristic.uuid} $offset ${value.toHex()}" ) } if (responseNeeded) { diff --git a/identity-android/src/main/java/com/android/identity/android/securearea/AndroidKeystoreSecureArea.kt b/identity-android/src/main/java/com/android/identity/android/securearea/AndroidKeystoreSecureArea.kt index 33554b4a4..b64a376a3 100644 --- a/identity-android/src/main/java/com/android/identity/android/securearea/AndroidKeystoreSecureArea.kt +++ b/identity-android/src/main/java/com/android/identity/android/securearea/AndroidKeystoreSecureArea.kt @@ -579,7 +579,7 @@ class AndroidKeystoreSecureArea( map.put("userAuthenticationRequired", settings.userAuthenticationRequired) map.put("userAuthenticationTimeoutMillis", settings.userAuthenticationTimeoutMillis) map.put("useStrongBox", settings.useStrongBox) - map.put("attestation", attestation.toDataItem) + map.put("attestation", attestation.toDataItem()) map.put("curve", settings.ecCurve.coseCurveIdentifier) storageEngine.put(PREFIX + alias, Cbor.encode(map.end().build())) } diff --git a/identity-android/src/main/java/com/android/identity/android/storage/AndroidStorageEngine.kt b/identity-android/src/main/java/com/android/identity/android/storage/AndroidStorageEngine.kt index 149fffaf6..7f0b42f10 100644 --- a/identity-android/src/main/java/com/android/identity/android/storage/AndroidStorageEngine.kt +++ b/identity-android/src/main/java/com/android/identity/android/storage/AndroidStorageEngine.kt @@ -99,7 +99,7 @@ class AndroidStorageEngine internal constructor( } else if (Arrays.equals(magic, MAGIC_NOT_ENCRYPTED)) { Arrays.copyOfRange(data, MAGIC_SIZE, data.size) } else { - throw IllegalStateException("Unexpected magic ${magic.toHex}") + throw IllegalStateException("Unexpected magic ${magic.toHex()}") } } catch (e: FileNotFoundException) { null diff --git a/identity-android/src/main/java/com/android/identity/android/util/NfcUtil.kt b/identity-android/src/main/java/com/android/identity/android/util/NfcUtil.kt index 3b0022a16..59fa5253b 100644 --- a/identity-android/src/main/java/com/android/identity/android/util/NfcUtil.kt +++ b/identity-android/src/main/java/com/android/identity/android/util/NfcUtil.kt @@ -30,10 +30,10 @@ object NfcUtil { // Defined by NFC Forum @JvmField - val AID_FOR_TYPE_4_TAG_NDEF_APPLICATION = "D2760000850101".fromHex + val AID_FOR_TYPE_4_TAG_NDEF_APPLICATION = "D2760000850101".fromHex() // Defined by 18013-5 Section 8.3.3.1.2 Data retrieval using near field communication (NFC) - val AID_FOR_MDL_DATA_TRANSFER = "A0000002480400".fromHex + val AID_FOR_MDL_DATA_TRANSFER = "A0000002480400".fromHex() const val COMMAND_TYPE_OTHER = 0 const val COMMAND_TYPE_SELECT_BY_AID = 1 @@ -216,8 +216,8 @@ object NfcUtil { if (Logger.isDebugEnabled) { Logger.d( TAG, "ConnectionMethod $cm: alternativeCarrierRecord: " - + "${records.second.toHex} carrierConfigurationRecord: " - + "${records.first.payload.toHex}" + + "${records.second.toHex()} carrierConfigurationRecord: " + + "${records.first.payload.toHex()}" ) } alternativeCarrierRecords.add(records.second) diff --git a/identity-doctypes/src/main/java/com/android/identity/documenttype/knowntypes/DrivingLicense.kt b/identity-doctypes/src/main/java/com/android/identity/documenttype/knowntypes/DrivingLicense.kt index 619bdfaf1..31be07bb9 100644 --- a/identity-doctypes/src/main/java/com/android/identity/documenttype/knowntypes/DrivingLicense.kt +++ b/identity-doctypes/src/main/java/com/android/identity/documenttype/knowntypes/DrivingLicense.kt @@ -52,7 +52,7 @@ object DrivingLicense { "Last name, surname, or primary identifier, of the mDL holder.", true, MDL_NAMESPACE, - SampleData.FAMILY_NAME.toDataItem + SampleData.FAMILY_NAME.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -61,7 +61,7 @@ object DrivingLicense { "First name(s), other name(s), or secondary identifier, of the mDL holder", true, MDL_NAMESPACE, - SampleData.GIVEN_NAME.toDataItem + SampleData.GIVEN_NAME.toDataItem() ) .addAttribute( DocumentAttributeType.Date, @@ -70,7 +70,7 @@ object DrivingLicense { "Day, month and year on which the mDL holder was born. If unknown, approximate date of birth", true, MDL_NAMESPACE, - SampleData.birthDate.toDataItemFullDate + SampleData.birthDate.toDataItemFullDate() ) .addAttribute( DocumentAttributeType.Date, @@ -79,7 +79,7 @@ object DrivingLicense { "Date when mDL was issued", true, MDL_NAMESPACE, - SampleData.issueDate.toDataItemFullDate + SampleData.issueDate.toDataItemFullDate() ) .addAttribute( DocumentAttributeType.Date, @@ -88,7 +88,7 @@ object DrivingLicense { "Date when mDL expires", true, MDL_NAMESPACE, - SampleData.expiryDate.toDataItemFullDate + SampleData.expiryDate.toDataItemFullDate() ) .addAttribute( DocumentAttributeType.StringOptions(Options.COUNTRY_ISO_3166_1_ALPHA_2), @@ -97,7 +97,7 @@ object DrivingLicense { "Alpha-2 country code, as defined in ISO 3166-1, of the issuing authority’s country or territory", true, MDL_NAMESPACE, - SampleData.ISSUING_COUNTRY.toDataItem + SampleData.ISSUING_COUNTRY.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -106,7 +106,7 @@ object DrivingLicense { "Issuing authority name.", true, MDL_NAMESPACE, - SampleData.ISSUING_AUTHORITY_MDL.toDataItem + SampleData.ISSUING_AUTHORITY_MDL.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -115,7 +115,7 @@ object DrivingLicense { "The number assigned or calculated by the issuing authority.", true, MDL_NAMESPACE, - SampleData.DOCUMENT_NUMBER.toDataItem + SampleData.DOCUMENT_NUMBER.toDataItem() ) .addAttribute( DocumentAttributeType.Picture, @@ -154,7 +154,7 @@ object DrivingLicense { "Distinguishing sign of the issuing country", true, MDL_NAMESPACE, - SampleData.UN_DISTINGUISHING_SIGN.toDataItem + SampleData.UN_DISTINGUISHING_SIGN.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -163,7 +163,7 @@ object DrivingLicense { "An audit control number assigned by the issuing authority", false, MDL_NAMESPACE, - SampleData.ADMINISTRATIVE_NUMBER.toDataItem + SampleData.ADMINISTRATIVE_NUMBER.toDataItem() ) .addAttribute( DocumentAttributeType.IntegerOptions(Options.SEX_ISO_IEC_5218), @@ -172,7 +172,7 @@ object DrivingLicense { "mDL holder’s sex", false, MDL_NAMESPACE, - SampleData.SEX_ISO218.toDataItem + SampleData.SEX_ISO218.toDataItem() ) .addAttribute( DocumentAttributeType.Number, @@ -181,7 +181,7 @@ object DrivingLicense { "mDL holder’s height in centimetres", false, MDL_NAMESPACE, - SampleData.HEIGHT_CM.toDataItem + SampleData.HEIGHT_CM.toDataItem() ) .addAttribute( DocumentAttributeType.Number, @@ -190,7 +190,7 @@ object DrivingLicense { "mDL holder’s weight in kilograms", false, MDL_NAMESPACE, - SampleData.WEIGHT_KG.toDataItem + SampleData.WEIGHT_KG.toDataItem() ) .addAttribute( DocumentAttributeType.StringOptions( @@ -213,7 +213,7 @@ object DrivingLicense { "mDL holder’s eye color", false, MDL_NAMESPACE, - "blue".toDataItem + "blue".toDataItem() ) .addAttribute( DocumentAttributeType.StringOptions( @@ -236,7 +236,7 @@ object DrivingLicense { "mDL holder’s hair color", false, MDL_NAMESPACE, - "blond".toDataItem + "blond".toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -245,7 +245,7 @@ object DrivingLicense { "Country and municipality or state/province where the mDL holder was born", false, MDL_NAMESPACE, - SampleData.BIRTH_PLACE.toDataItem + SampleData.BIRTH_PLACE.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -254,7 +254,7 @@ object DrivingLicense { "The place where the mDL holder resides and/or may be contacted (street/house number, municipality etc.)", false, MDL_NAMESPACE, - SampleData.RESIDENT_ADDRESS.toDataItem + SampleData.RESIDENT_ADDRESS.toDataItem() ) .addAttribute( DocumentAttributeType.Date, @@ -263,7 +263,7 @@ object DrivingLicense { "Date when portrait was taken", false, MDL_NAMESPACE, - SampleData.portraitCaptureDate.toDataItemFullDate + SampleData.portraitCaptureDate.toDataItemFullDate() ) .addAttribute( DocumentAttributeType.Number, @@ -272,7 +272,7 @@ object DrivingLicense { "The age of the mDL holder", false, MDL_NAMESPACE, - SampleData.AGE_IN_YEARS.toDataItem + SampleData.AGE_IN_YEARS.toDataItem() ) .addAttribute( DocumentAttributeType.Number, @@ -281,7 +281,7 @@ object DrivingLicense { "The year when the mDL holder was born", false, MDL_NAMESPACE, - SampleData.AGE_BIRTH_YEAR.toDataItem + SampleData.AGE_BIRTH_YEAR.toDataItem() ) .addMdocAttribute( DocumentAttributeType.Boolean, @@ -290,7 +290,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 13", false, MDL_NAMESPACE, - SampleData.AGE_OVER_13.toDataItem + SampleData.AGE_OVER_13.toDataItem() ) .addMdocAttribute( DocumentAttributeType.Boolean, @@ -299,7 +299,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 16", false, MDL_NAMESPACE, - SampleData.AGE_OVER_16.toDataItem + SampleData.AGE_OVER_16.toDataItem() ) .addAttribute( DocumentAttributeType.Boolean, @@ -308,7 +308,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 18", false, MDL_NAMESPACE, - SampleData.AGE_OVER_18.toDataItem + SampleData.AGE_OVER_18.toDataItem() ) .addAttribute( DocumentAttributeType.Boolean, @@ -317,7 +317,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 21", false, MDL_NAMESPACE, - SampleData.AGE_OVER_21.toDataItem + SampleData.AGE_OVER_21.toDataItem() ) .addAttribute( DocumentAttributeType.Boolean, @@ -326,7 +326,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 25", false, MDL_NAMESPACE, - SampleData.AGE_OVER_25.toDataItem + SampleData.AGE_OVER_25.toDataItem() ) .addAttribute( DocumentAttributeType.Boolean, @@ -335,7 +335,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 60", false, MDL_NAMESPACE, - SampleData.AGE_OVER_60.toDataItem + SampleData.AGE_OVER_60.toDataItem() ) .addAttribute( DocumentAttributeType.Boolean, @@ -344,7 +344,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 62", false, MDL_NAMESPACE, - SampleData.AGE_OVER_62.toDataItem + SampleData.AGE_OVER_62.toDataItem() ) .addAttribute( DocumentAttributeType.Boolean, @@ -353,7 +353,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 65", false, MDL_NAMESPACE, - SampleData.AGE_OVER_65.toDataItem + SampleData.AGE_OVER_65.toDataItem() ) .addAttribute( DocumentAttributeType.Boolean, @@ -362,7 +362,7 @@ object DrivingLicense { "Indication whether the mDL holder is as old or older than 68", false, MDL_NAMESPACE, - SampleData.AGE_OVER_68.toDataItem + SampleData.AGE_OVER_68.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -371,7 +371,7 @@ object DrivingLicense { "Country subdivision code of the jurisdiction that issued the mDL", false, MDL_NAMESPACE, - SampleData.ISSUING_JURISDICTION.toDataItem + SampleData.ISSUING_JURISDICTION.toDataItem() ) .addAttribute( DocumentAttributeType.StringOptions(Options.COUNTRY_ISO_3166_1_ALPHA_2), @@ -380,7 +380,7 @@ object DrivingLicense { "Nationality of the mDL holder", false, MDL_NAMESPACE, - SampleData.NATIONALITY.toDataItem + SampleData.NATIONALITY.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -389,7 +389,7 @@ object DrivingLicense { "The city where the mDL holder lives", false, MDL_NAMESPACE, - SampleData.RESIDENT_CITY.toDataItem + SampleData.RESIDENT_CITY.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -398,7 +398,7 @@ object DrivingLicense { "The state/province/district where the mDL holder lives", false, MDL_NAMESPACE, - SampleData.RESIDENT_STATE.toDataItem + SampleData.RESIDENT_STATE.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -407,7 +407,7 @@ object DrivingLicense { "The postal code of the mDL holder", false, MDL_NAMESPACE, - SampleData.RESIDENT_POSTAL_CODE.toDataItem + SampleData.RESIDENT_POSTAL_CODE.toDataItem() ) .addAttribute( DocumentAttributeType.StringOptions(Options.COUNTRY_ISO_3166_1_ALPHA_2), @@ -416,7 +416,7 @@ object DrivingLicense { "The country where the mDL holder lives", false, MDL_NAMESPACE, - SampleData.RESIDENT_COUNTRY.toDataItem + SampleData.RESIDENT_COUNTRY.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -425,7 +425,7 @@ object DrivingLicense { "The family name of the mDL holder", false, MDL_NAMESPACE, - SampleData.FAMILY_NAME_NATIONAL_CHARACTER.toDataItem + SampleData.FAMILY_NAME_NATIONAL_CHARACTER.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -434,7 +434,7 @@ object DrivingLicense { "The given name of the mDL holder", false, MDL_NAMESPACE, - SampleData.GIVEN_NAMES_NATIONAL_CHARACTER.toDataItem + SampleData.GIVEN_NAMES_NATIONAL_CHARACTER.toDataItem() ) .addAttribute( DocumentAttributeType.Picture, @@ -478,7 +478,7 @@ object DrivingLicense { "An indicator that denotes whether the credential holder is an organ donor.", false, AAMVA_NAMESPACE, - 1.toDataItem + 1.toDataItem() ) .addAttribute( DocumentAttributeType.IntegerOptions( @@ -581,7 +581,7 @@ object DrivingLicense { "Indicates the approximate weight range of the cardholder", false, AAMVA_NAMESPACE, - 3.toDataItem + 3.toDataItem() ) .addAttribute( DocumentAttributeType.StringOptions( @@ -602,7 +602,7 @@ object DrivingLicense { "Codes for race or ethnicity of the cardholder", false, AAMVA_NAMESPACE, - "W".toDataItem + "W".toDataItem() ) .addAttribute( DocumentAttributeType.StringOptions( @@ -618,7 +618,7 @@ object DrivingLicense { "DHS required field that indicates compliance", false, AAMVA_NAMESPACE, - "F".toDataItem + "F".toDataItem() ) .addAttribute( DocumentAttributeType.IntegerOptions( @@ -649,7 +649,7 @@ object DrivingLicense { "Present if the credential is an EDL", false, AAMVA_NAMESPACE, - 1.toDataItem + 1.toDataItem() ) .addAttribute( DocumentAttributeType.String, @@ -679,7 +679,7 @@ object DrivingLicense { "mDL holder’s sex", true, AAMVA_NAMESPACE, - SampleData.SEX_ISO218.toDataItem + SampleData.SEX_ISO218.toDataItem() ) /* * Then the attributes that exist only in the mDL Credential Type and not in the VC Credential Type diff --git a/identity-doctypes/src/main/java/com/android/identity/documenttype/knowntypes/EUPersonalID.kt b/identity-doctypes/src/main/java/com/android/identity/documenttype/knowntypes/EUPersonalID.kt index eda32da30..ee36064e5 100644 --- a/identity-doctypes/src/main/java/com/android/identity/documenttype/knowntypes/EUPersonalID.kt +++ b/identity-doctypes/src/main/java/com/android/identity/documenttype/knowntypes/EUPersonalID.kt @@ -43,7 +43,7 @@ object EUPersonalID { "Current last name(s), surname(s), or primary identifier of the PID holder", true, EUPID_NAMESPACE, - SampleData.FAMILY_NAME.toDataItem + SampleData.FAMILY_NAME.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -52,7 +52,7 @@ object EUPersonalID { "Current first name(s), other name(s), or secondary identifier of the PID holder", true, EUPID_NAMESPACE, - SampleData.GIVEN_NAME.toDataItem + SampleData.GIVEN_NAME.toDataItem() ) .addMdocAttribute( DocumentAttributeType.Date, @@ -61,7 +61,7 @@ object EUPersonalID { "Day, month, and year on which the PID holder was born. If unknown, approximate date of birth.", true, EUPID_NAMESPACE, - SampleData.birthDate.toDataItemFullDate + SampleData.birthDate.toDataItemFullDate() ) .addMdocAttribute( DocumentAttributeType.Number, @@ -70,7 +70,7 @@ object EUPersonalID { "The age of the PID holder in years", false, EUPID_NAMESPACE, - SampleData.AGE_IN_YEARS.toDataItem + SampleData.AGE_IN_YEARS.toDataItem() ) .addMdocAttribute( DocumentAttributeType.Number, @@ -79,7 +79,7 @@ object EUPersonalID { "The year when the PID holder was born", false, EUPID_NAMESPACE, - SampleData.AGE_BIRTH_YEAR.toDataItem + SampleData.AGE_BIRTH_YEAR.toDataItem() ) .addMdocAttribute( DocumentAttributeType.Boolean, @@ -88,7 +88,7 @@ object EUPersonalID { "Age over 18?", false, EUPID_NAMESPACE, - SampleData.AGE_OVER_18.toDataItem + SampleData.AGE_OVER_18.toDataItem() ) .addMdocAttribute( DocumentAttributeType.Boolean, @@ -97,7 +97,7 @@ object EUPersonalID { "Age over 21?", false, EUPID_NAMESPACE, - SampleData.AGE_OVER_21.toDataItem + SampleData.AGE_OVER_21.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -106,7 +106,7 @@ object EUPersonalID { "Last name(s), surname(s), or primary identifier of the PID holder at birth", false, EUPID_NAMESPACE, - SampleData.FAMILY_NAME_BIRTH.toDataItem + SampleData.FAMILY_NAME_BIRTH.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -115,7 +115,7 @@ object EUPersonalID { "First name(s), other name(s), or secondary identifier of the PID holder at birth", false, EUPID_NAMESPACE, - SampleData.GIVEN_NAME_BIRTH.toDataItem + SampleData.GIVEN_NAME_BIRTH.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -124,7 +124,7 @@ object EUPersonalID { "Country and municipality or state/province where the PID holder was born", false, EUPID_NAMESPACE, - SampleData.BIRTH_PLACE.toDataItem + SampleData.BIRTH_PLACE.toDataItem() ) .addMdocAttribute( DocumentAttributeType.StringOptions(Options.COUNTRY_ISO_3166_1_ALPHA_2), @@ -133,7 +133,7 @@ object EUPersonalID { "The country where the PID User was born, as an Alpha-2 country code as specified in ISO 3166-1", false, EUPID_NAMESPACE, - SampleData.BIRTH_COUNTRY.toDataItem + SampleData.BIRTH_COUNTRY.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -142,7 +142,7 @@ object EUPersonalID { "The state, province, district, or local area where the PID User was born", false, EUPID_NAMESPACE, - SampleData.BIRTH_STATE.toDataItem + SampleData.BIRTH_STATE.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -151,7 +151,7 @@ object EUPersonalID { "The municipality, city, town, or village where the PID User was born", false, EUPID_NAMESPACE, - SampleData.BIRTH_CITY.toDataItem + SampleData.BIRTH_CITY.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -160,7 +160,7 @@ object EUPersonalID { "The full address of the place where the PID holder currently resides and/or may be contacted (street/house number, municipality etc.)", false, EUPID_NAMESPACE, - SampleData.RESIDENT_ADDRESS.toDataItem + SampleData.RESIDENT_ADDRESS.toDataItem() ) .addMdocAttribute( DocumentAttributeType.StringOptions(Options.COUNTRY_ISO_3166_1_ALPHA_2), @@ -169,7 +169,7 @@ object EUPersonalID { "The country where the PID User currently resides, as an Alpha-2 country code as specified in ISO 3166-1", false, EUPID_NAMESPACE, - SampleData.RESIDENT_COUNTRY.toDataItem + SampleData.RESIDENT_COUNTRY.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -178,7 +178,7 @@ object EUPersonalID { "The state, province, district, or local area where the PID User currently resides.", false, EUPID_NAMESPACE, - SampleData.RESIDENT_STATE.toDataItem + SampleData.RESIDENT_STATE.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -187,7 +187,7 @@ object EUPersonalID { "The city where the PID holder currently resides", false, EUPID_NAMESPACE, - SampleData.RESIDENT_CITY.toDataItem + SampleData.RESIDENT_CITY.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -196,7 +196,7 @@ object EUPersonalID { "The postal code of the place where the PID holder currently resides", false, EUPID_NAMESPACE, - SampleData.RESIDENT_POSTAL_CODE.toDataItem + SampleData.RESIDENT_POSTAL_CODE.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -205,7 +205,7 @@ object EUPersonalID { "The name of the street where the PID User currently resides.", false, EUPID_NAMESPACE, - SampleData.RESIDENT_STREET.toDataItem + SampleData.RESIDENT_STREET.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -214,7 +214,7 @@ object EUPersonalID { "The house number where the PID User currently resides, including any affix or suffix", false, EUPID_NAMESPACE, - SampleData.RESIDENT_HOUSE_NUMBER.toDataItem + SampleData.RESIDENT_HOUSE_NUMBER.toDataItem() ) .addMdocAttribute( DocumentAttributeType.IntegerOptions(Options.SEX_ISO_IEC_5218), @@ -223,7 +223,7 @@ object EUPersonalID { "PID holder’s gender", false, EUPID_NAMESPACE, - SampleData.SEX_ISO218.toDataItem + SampleData.SEX_ISO218.toDataItem() ) .addMdocAttribute( DocumentAttributeType.StringOptions(Options.COUNTRY_ISO_3166_1_ALPHA_2), @@ -232,7 +232,7 @@ object EUPersonalID { "Alpha-2 country code as specified in ISO 3166-1, representing the nationality of the PID User.", true, EUPID_NAMESPACE, - SampleData.NATIONALITY.toDataItem + SampleData.NATIONALITY.toDataItem() ) .addMdocAttribute( DocumentAttributeType.Date, @@ -241,7 +241,7 @@ object EUPersonalID { "Date (and possibly time) when the PID was issued.", true, EUPID_NAMESPACE, - SampleData.issueDate.toDataItemFullDate + SampleData.issueDate.toDataItemFullDate() ) .addMdocAttribute( DocumentAttributeType.Date, @@ -250,7 +250,7 @@ object EUPersonalID { "Date (and possibly time) when the PID will expire.", true, EUPID_NAMESPACE, - SampleData.expiryDate.toDataItemFullDate + SampleData.expiryDate.toDataItemFullDate() ) .addMdocAttribute( DocumentAttributeType.String, @@ -261,7 +261,7 @@ object EUPersonalID { "no separate authority authorized to issue PIDs.", true, EUPID_NAMESPACE, - SampleData.ISSUING_AUTHORITY_EU_PID.toDataItem + SampleData.ISSUING_AUTHORITY_EU_PID.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -270,7 +270,7 @@ object EUPersonalID { "A number for the PID, assigned by the PID Provider.", false, EUPID_NAMESPACE, - SampleData.DOCUMENT_NUMBER.toDataItem + SampleData.DOCUMENT_NUMBER.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -279,7 +279,7 @@ object EUPersonalID { "A number assigned by the PID Provider for audit control or other purposes.", false, EUPID_NAMESPACE, - SampleData.ADMINISTRATIVE_NUMBER.toDataItem + SampleData.ADMINISTRATIVE_NUMBER.toDataItem() ) .addMdocAttribute( DocumentAttributeType.String, @@ -290,7 +290,7 @@ object EUPersonalID { "as the value for issuing_country.", false, EUPID_NAMESPACE, - SampleData.ISSUING_JURISDICTION.toDataItem + SampleData.ISSUING_JURISDICTION.toDataItem() ) .addMdocAttribute( DocumentAttributeType.StringOptions(Options.COUNTRY_ISO_3166_1_ALPHA_2), @@ -300,7 +300,7 @@ object EUPersonalID { "country or territory", true, EUPID_NAMESPACE, - SampleData.ISSUING_COUNTRY.toDataItem + SampleData.ISSUING_COUNTRY.toDataItem() ) .build() } diff --git a/identity-doctypes/src/test/java/com/android/identity/documenttype/TestDocumentTypeRepository.kt b/identity-doctypes/src/test/java/com/android/identity/documenttype/TestDocumentTypeRepository.kt index 6eff76ef8..bd6c058ba 100644 --- a/identity-doctypes/src/test/java/com/android/identity/documenttype/TestDocumentTypeRepository.kt +++ b/identity-doctypes/src/test/java/com/android/identity/documenttype/TestDocumentTypeRepository.kt @@ -137,7 +137,7 @@ class TestDocumentTypeRepository { ), false ).renderValue( - Instant.parse("1976-02-03T05:30:00Z").toDataItemDateTimeString, + Instant.parse("1976-02-03T05:30:00Z").toDataItemDateTimeString(), timeZone = TimeZone.of("Europe/Copenhagen") ) ) @@ -156,7 +156,7 @@ class TestDocumentTypeRepository { ), false ).renderValue( - LocalDate.parse("1976-02-03").toDataItemFullDate, + LocalDate.parse("1976-02-03").toDataItemFullDate(), timeZone = TimeZone.of(zoneId) ) ) @@ -167,28 +167,28 @@ class TestDocumentTypeRepository { Assert.assertEquals( "1976-02-03", mdlNs.dataElements["birth_date"]?.renderValue( - Instant.parse("1976-02-03T05:30:00Z").toDataItemDateTimeString, + Instant.parse("1976-02-03T05:30:00Z").toDataItemDateTimeString(), timeZone = TimeZone.of("Europe/Copenhagen") ) ) Assert.assertEquals( "1976-02-02", mdlNs.dataElements["birth_date"]?.renderValue( - Instant.parse("1976-02-03T05:30:00Z").toDataItemDateTimeString, + Instant.parse("1976-02-03T05:30:00Z").toDataItemDateTimeString(), timeZone = TimeZone.of("America/Los_Angeles") ) ) Assert.assertEquals( "1976-02-03", mdlNs.dataElements["birth_date"]?.renderValue( - LocalDate.parse("1976-02-03").toDataItemFullDate, + LocalDate.parse("1976-02-03").toDataItemFullDate(), timeZone = TimeZone.of("Europe/Copenhagen") ) ) Assert.assertEquals( "1976-02-03", mdlNs.dataElements["birth_date"]?.renderValue( - LocalDate.parse("1976-02-03").toDataItemFullDate, + LocalDate.parse("1976-02-03").toDataItemFullDate(), timeZone = TimeZone.of("America/Los_Angeles") ) ) diff --git a/identity-flow/src/main/java/com/android/identity/flow/handler/FlowDispatcherLocal.kt b/identity-flow/src/main/java/com/android/identity/flow/handler/FlowDispatcherLocal.kt index c0e689bcb..2688f557b 100644 --- a/identity-flow/src/main/java/com/android/identity/flow/handler/FlowDispatcherLocal.kt +++ b/identity-flow/src/main/java/com/android/identity/flow/handler/FlowDispatcherLocal.kt @@ -128,7 +128,7 @@ class FlowDispatcherLocal private constructor( try { val result = handler(owner, state, args.subList(1, args.size)) val newStateBlob = stateDataItem(cipher, args[0], decryptedState, state) - return listOf(newStateBlob, FlowReturnCode.RESULT.ordinal.toDataItem, result) + return listOf(newStateBlob, FlowReturnCode.RESULT.ordinal.toDataItem(), result) } catch (err: Throwable) { val newStateBlob = stateDataItem(cipher, args[0], decryptedState, state) return owner.exceptionMap.exceptionReturn(newStateBlob, err) diff --git a/identity-flow/src/main/java/com/android/identity/flow/handler/FlowExceptionMap.kt b/identity-flow/src/main/java/com/android/identity/flow/handler/FlowExceptionMap.kt index 5c14c15be..df377ee6e 100644 --- a/identity-flow/src/main/java/com/android/identity/flow/handler/FlowExceptionMap.kt +++ b/identity-flow/src/main/java/com/android/identity/flow/handler/FlowExceptionMap.kt @@ -61,8 +61,8 @@ class FlowExceptionMap private constructor( val item = byClass[exception::class] ?: throw exception return listOf( state, - FlowReturnCode.EXCEPTION.ordinal.toDataItem, - item.exceptionId.toDataItem, + FlowReturnCode.EXCEPTION.ordinal.toDataItem(), + item.exceptionId.toDataItem(), item.serialize(exception) ) } diff --git a/identity-flow/src/main/java/com/android/identity/flow/handler/HttpHandler.kt b/identity-flow/src/main/java/com/android/identity/flow/handler/HttpHandler.kt index 9cc129c77..1ebc44c1b 100644 --- a/identity-flow/src/main/java/com/android/identity/flow/handler/HttpHandler.kt +++ b/identity-flow/src/main/java/com/android/identity/flow/handler/HttpHandler.kt @@ -40,8 +40,8 @@ class HttpHandler( try { val result = flowPoll.poll(consumedToken, pollKeys) val resultList = mutableListOf() - resultList.add(result.consumeToken.toDataItem) - resultList.add(result.index.toDataItem) + resultList.add(result.consumeToken.toDataItem()) + resultList.add(result.index.toDataItem()) resultList.add(result.notification) return resultList.toList() } catch (err: FlowPoll.TimeoutException) { diff --git a/identity-issuance/src/main/java/com/android/identity/issuance/DocumentState.kt b/identity-issuance/src/main/java/com/android/identity/issuance/DocumentState.kt index b272b275b..3a429ee11 100644 --- a/identity-issuance/src/main/java/com/android/identity/issuance/DocumentState.kt +++ b/identity-issuance/src/main/java/com/android/identity/issuance/DocumentState.kt @@ -51,17 +51,16 @@ data class DocumentState( } fun toCbor(): ByteArray { - return Cbor.encode(toDataItem) + return Cbor.encode(toDataItem()) } - val toDataItem: DataItem - get() { - return CborMap.builder() - .put("timestamp", timestamp.toEpochMilliseconds()) - .put("condition", condition.value) - .put("numPendingCredentials", numPendingCredentials) - .put("numAvailableCredentials", numAvailableCredentials) - .end() - .build() - } + fun toDataItem(): DataItem { + return CborMap.builder() + .put("timestamp", timestamp.toEpochMilliseconds()) + .put("condition", condition.value) + .put("numPendingCredentials", numPendingCredentials) + .put("numAvailableCredentials", numAvailableCredentials) + .end() + .build() + } } diff --git a/identity-issuance/src/main/java/com/android/identity/issuance/authenticationUtilities.kt b/identity-issuance/src/main/java/com/android/identity/issuance/authenticationUtilities.kt index f51481a9c..8196dd75b 100644 --- a/identity-issuance/src/main/java/com/android/identity/issuance/authenticationUtilities.kt +++ b/identity-issuance/src/main/java/com/android/identity/issuance/authenticationUtilities.kt @@ -84,7 +84,7 @@ fun validateKeyAttestation( check (parser.applicationSignatureDigests.size == requireAppSignatureCertificateDigests.size) { "Number Signing certificates mismatch" } for (n in 0.. - credentialRequestsBuilder.add(RawCbor(cpoRequest.toCbor())) - } - val ceMapBuilder = CborMap.builder() - collectedEvidence.forEach() { evidence -> - ceMapBuilder.put(evidence.key, RawCbor(evidence.value.toCbor())) - } - val mapBuilder = CborMap.builder() - .put("registrationResponse", registrationResponse.toDataItem) - .put("state", state.ordinal.toLong()) - .put("collectedEvidence", ceMapBuilder.end().build()) - .put("credentialRequests", credentialRequestsBuilder.end().build()) - if (documentConfiguration != null) { - mapBuilder.put("documentConfiguration", documentConfiguration!!.toDataItem) - } - return mapBuilder.end().build() + fun toDataItem(): DataItem { + val credentialRequestsBuilder = CborArray.builder() + simpleCredentialRequests.forEach() { cpoRequest -> + credentialRequestsBuilder.add(RawCbor(cpoRequest.toCbor())) } + val ceMapBuilder = CborMap.builder() + collectedEvidence.forEach() { evidence -> + ceMapBuilder.put(evidence.key, RawCbor(evidence.value.toCbor())) + } + val mapBuilder = CborMap.builder() + .put("registrationResponse", registrationResponse.toDataItem()) + .put("state", state.ordinal.toLong()) + .put("collectedEvidence", ceMapBuilder.end().build()) + .put("credentialRequests", credentialRequestsBuilder.end().build()) + if (documentConfiguration != null) { + mapBuilder.put("documentConfiguration", documentConfiguration!!.toDataItem()) + } + return mapBuilder.end().build() + } } diff --git a/identity-issuance/src/main/java/com/android/identity/issuance/hardcoded/IssuingAuthorityState.kt b/identity-issuance/src/main/java/com/android/identity/issuance/hardcoded/IssuingAuthorityState.kt index 79d5ea7aa..d0fcc28d3 100644 --- a/identity-issuance/src/main/java/com/android/identity/issuance/hardcoded/IssuingAuthorityState.kt +++ b/identity-issuance/src/main/java/com/android/identity/issuance/hardcoded/IssuingAuthorityState.kt @@ -436,13 +436,13 @@ class IssuingAuthorityState( val taggedEncodedMso = Cbor.encode(Tagged(Tagged.ENCODED_CBOR, Bstr(mso))) val protectedHeaders = mapOf(Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - Algorithm.ES256.coseAlgorithmIdentifier.toDataItem + Algorithm.ES256.coseAlgorithmIdentifier.toDataItem() )) val unprotectedHeaders = mapOf(Pair( CoseNumberLabel(Cose.COSE_LABEL_X5CHAIN), X509CertChain(listOf( X509Cert(documentSigningKeyCert.encodedCertificate)) - ).toDataItem + ).toDataItem() )) val encodedIssuerAuth = Cbor.encode( Cose.coseSign1Sign( @@ -452,7 +452,7 @@ class IssuingAuthorityState( Algorithm.ES256, protectedHeaders, unprotectedHeaders - ).toDataItem + ).toDataItem() ) val issuerProvidedAuthenticationData = StaticAuthDataGenerator( @@ -518,7 +518,7 @@ class IssuingAuthorityState( .putEntryString(EUPID_NAMESPACE, "family_name", lastName) .putEntryString(EUPID_NAMESPACE, "given_name", firstName) .putEntry(EUPID_NAMESPACE, "birth_date", - Cbor.encode(dateOfBirth.toDataItemFullDate)) + Cbor.encode(dateOfBirth.toDataItemFullDate())) .putEntryNumber(EUPID_NAMESPACE, "age_in_years", dateOfBirth.yearsUntil(now.toLocalDateTime(timeZone).date).toLong()) .putEntryNumber(EUPID_NAMESPACE, "age_birth_year", dateOfBirth.year.toLong()) .putEntryBoolean(EUPID_NAMESPACE, "age_over_18", ageOver18) @@ -529,9 +529,9 @@ class IssuingAuthorityState( // issuing_jurisdiction, .putEntryString(EUPID_NAMESPACE, "nationality", "UT") .putEntry(EUPID_NAMESPACE, "issuance_date", - Cbor.encode(issueDate.toDataItemDateTimeString)) + Cbor.encode(issueDate.toDataItemDateTimeString())) .putEntry(EUPID_NAMESPACE, "expiry_date", - Cbor.encode(expiryDate.toDataItemDateTimeString) + Cbor.encode(expiryDate.toDataItemDateTimeString()) ) .putEntryString(EUPID_NAMESPACE, "issuing_authority", issuingAuthorityName) @@ -574,7 +574,7 @@ class IssuingAuthorityState( .putEntryString(EUPID_NAMESPACE, "family_name", lastName) .putEntryString(EUPID_NAMESPACE, "given_name", firstName) .putEntry(EUPID_NAMESPACE, "birth_date", - Cbor.encode(dateOfBirth.toDataItemFullDate)) + Cbor.encode(dateOfBirth.toDataItemFullDate())) .putEntryNumber(EUPID_NAMESPACE, "age_in_years", dateOfBirth.yearsUntil(now.toLocalDateTime(timeZone).date).toLong()) .putEntryNumber(EUPID_NAMESPACE, "age_birth_year", dateOfBirth.year.toLong()) .putEntryBoolean(EUPID_NAMESPACE, "age_over_18", ageOver18) @@ -586,9 +586,9 @@ class IssuingAuthorityState( .putEntryNumber(EUPID_NAMESPACE, "gender", sex) .putEntryString(EUPID_NAMESPACE, "nationality", "UT") .putEntry(EUPID_NAMESPACE, "issuance_date", - Cbor.encode(issueDate.toDataItemDateTimeString)) + Cbor.encode(issueDate.toDataItemDateTimeString())) .putEntry(EUPID_NAMESPACE, "expiry_date", - Cbor.encode(expiryDate.toDataItemDateTimeString) + Cbor.encode(expiryDate.toDataItemDateTimeString()) ) .putEntryString(EUPID_NAMESPACE, "issuing_authority", issuingAuthorityName) @@ -658,14 +658,14 @@ class IssuingAuthorityState( .putEntryString(MDL_NAMESPACE, "given_name", firstName) .putEntryString(MDL_NAMESPACE, "family_name", lastName) .putEntry(MDL_NAMESPACE, "birth_date", - Cbor.encode(dateOfBirth.toDataItemFullDate)) + Cbor.encode(dateOfBirth.toDataItemFullDate())) .putEntryByteString(MDL_NAMESPACE, "portrait", portrait.toByteArray()) .putEntryByteString(MDL_NAMESPACE, "signature_usual_mark", signatureOrUsualMark.toByteArray()) .putEntry(MDL_NAMESPACE, "issue_date", - Cbor.encode(issueDate.toDataItemDateTimeString)) + Cbor.encode(issueDate.toDataItemDateTimeString())) .putEntry(MDL_NAMESPACE, "expiry_date", - Cbor.encode(expiryDate.toDataItemDateTimeString) + Cbor.encode(expiryDate.toDataItemDateTimeString()) ) // TODO .putEntryString(MDL_NAMESPACE, "issuing_authority", @@ -721,15 +721,15 @@ class IssuingAuthorityState( .putEntryString(MDL_NAMESPACE, "given_name", firstName) .putEntryString(MDL_NAMESPACE, "family_name", lastName) .putEntry(MDL_NAMESPACE, "birth_date", - Cbor.encode(dateOfBirth.toDataItemFullDate)) + Cbor.encode(dateOfBirth.toDataItemFullDate())) .putEntryByteString(MDL_NAMESPACE, "portrait", portrait.toByteArray()) .putEntryByteString(MDL_NAMESPACE, "signature_usual_mark", signatureOrUsualMark.toByteArray()) .putEntryNumber(MDL_NAMESPACE, "sex", sex) .putEntry(MDL_NAMESPACE, "issue_date", - Cbor.encode(issueDate.toDataItemDateTimeString)) + Cbor.encode(issueDate.toDataItemDateTimeString())) .putEntry(MDL_NAMESPACE, "expiry_date", - Cbor.encode(expiryDate.toDataItemDateTimeString) + Cbor.encode(expiryDate.toDataItemDateTimeString()) ) // TODO .putEntryString(MDL_NAMESPACE, "issuing_authority", @@ -867,7 +867,7 @@ class IssuingAuthorityState( throw IllegalStateException("Client not authenticated") } val storage = env.getInterface(Storage::class)!! - val bytes = Cbor.encode(document.toDataItem) + val bytes = Cbor.encode(document.toDataItem()) return storage.insert("IssuerDocument", clientId, ByteString(bytes)) } @@ -894,7 +894,7 @@ class IssuingAuthorityState( throw IllegalStateException("Client not authenticated") } val storage = env.getInterface(Storage::class)!! - val bytes = Cbor.encode(document.toDataItem) + val bytes = Cbor.encode(document.toDataItem()) storage.update("IssuerDocument", clientId, documentId, ByteString(bytes)) if (emitNotification) { emit(env, IssuingAuthorityNotification(documentId)) diff --git a/identity-issuance/src/main/java/com/android/identity/issuance/hardcoded/SimpleCredentialRequest.kt b/identity-issuance/src/main/java/com/android/identity/issuance/hardcoded/SimpleCredentialRequest.kt index 35767d0f6..49278a5ac 100644 --- a/identity-issuance/src/main/java/com/android/identity/issuance/hardcoded/SimpleCredentialRequest.kt +++ b/identity-issuance/src/main/java/com/android/identity/issuance/hardcoded/SimpleCredentialRequest.kt @@ -26,7 +26,7 @@ data class SimpleCredentialRequest( fun toCbor(): ByteArray { return Cbor.encode( CborMap.builder() - .put("authenticationKey", authenticationKey.toCoseKey().toDataItem) + .put("authenticationKey", authenticationKey.toCoseKey().toDataItem()) .put("format", format.name) .put("data", data) .end() diff --git a/identity-issuance/src/main/java/com/android/identity/issuance/proofing/defaultGraph.kt b/identity-issuance/src/main/java/com/android/identity/issuance/proofing/defaultGraph.kt index c7f15bb2c..472fe55d5 100644 --- a/identity-issuance/src/main/java/com/android/identity/issuance/proofing/defaultGraph.kt +++ b/identity-issuance/src/main/java/com/android/identity/issuance/proofing/defaultGraph.kt @@ -396,7 +396,7 @@ fun defaultCredentialConfiguration(collectedEvidence: Map( Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - signatureAlgorithm.coseAlgorithmIdentifier.toDataItem + signatureAlgorithm.coseAlgorithmIdentifier.toDataItem() ) ) val unprotectedHeaders = mapOf( Pair( CoseNumberLabel(Cose.COSE_LABEL_X5CHAIN), - readerKeyCertificateChain.toDataItem + readerKeyCertificateChain.toDataItem() ) ) readerAuth = coseSign1Sign( @@ -131,7 +131,7 @@ class DeviceRequestGenerator( signatureAlgorithm, protectedHeaders, unprotectedHeaders - ).toDataItem + ).toDataItem() } CborMap.builder().let { mapBuilder -> diff --git a/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/response/DeviceResponseParser.kt b/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/response/DeviceResponseParser.kt index 707ef6c04..f9d294865 100644 --- a/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/response/DeviceResponseParser.kt +++ b/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/response/DeviceResponseParser.kt @@ -273,7 +273,7 @@ class DeviceResponseParser( mapOf( Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - Algorithm.HMAC_SHA256.coseAlgorithmIdentifier.toDataItem + Algorithm.HMAC_SHA256.coseAlgorithmIdentifier.toDataItem() ) ), mapOf() @@ -283,8 +283,8 @@ class DeviceResponseParser( Logger.d(TAG, "Verified DeviceSigned using MAC") } else { Logger.d( - TAG, "Device MAC mismatch, got ${tagInResponse.toHex}" - + " expected ${expectedTag.toHex}" + TAG, "Device MAC mismatch, got ${tagInResponse.toHex()}" + + " expected ${expectedTag.toHex()}" ) } } diff --git a/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/response/DocumentGenerator.kt b/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/response/DocumentGenerator.kt index f8cffddaf..99d694858 100644 --- a/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/response/DocumentGenerator.kt +++ b/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/response/DocumentGenerator.kt @@ -122,12 +122,12 @@ class DocumentGenerator mapOf( Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - signatureAlgorithm.coseAlgorithmIdentifier.toDataItem + signatureAlgorithm.coseAlgorithmIdentifier.toDataItem() ) ), mapOf(), keyUnlockData - ).toDataItem + ).toDataItem() ) } else { val sharedSecret = secureArea.keyAgreement( @@ -148,11 +148,11 @@ class DocumentGenerator mapOf( Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - Algorithm.HMAC_SHA256.coseAlgorithmIdentifier.toDataItem + Algorithm.HMAC_SHA256.coseAlgorithmIdentifier.toDataItem() ) ), mapOf() - ).toDataItem + ).toDataItem() ) } val deviceAuthType: String diff --git a/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/sessionencryption/SessionEncryption.kt b/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/sessionencryption/SessionEncryption.kt index 8d64f1d89..179ce2946 100644 --- a/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/sessionencryption/SessionEncryption.kt +++ b/identity-mdoc/src/commonMain/kotlin/com/android/identity/mdoc/sessionencryption/SessionEncryption.kt @@ -145,7 +145,7 @@ class SessionEncryption( var eReaderKey = eSelfKey.publicKey mapBuilder.putTaggedEncodedCbor( "eReaderKey", - Cbor.encode(eReaderKey.toCoseKey().toDataItem) + Cbor.encode(eReaderKey.toCoseKey().toDataItem()) ) checkNotNull(messageCiphertext) { "Data cannot be empty in initial message" } } diff --git a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/engagement/EngagementParserTest.kt b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/engagement/EngagementParserTest.kt index 4d0661c15..ed3ac542f 100644 --- a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/engagement/EngagementParserTest.kt +++ b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/engagement/EngagementParserTest.kt @@ -28,7 +28,7 @@ import kotlin.test.assertTrue class EngagementParserTest { @Test fun testDeviceRequestEngagementWithVectors() { - val deviceEngagement = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_ENGAGEMENT.fromHex + val deviceEngagement = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_ENGAGEMENT.fromHex() val parser = EngagementParser(deviceEngagement) val engagement = parser.parse() assertEquals("1.0", engagement.version) @@ -46,7 +46,7 @@ class EngagementParserTest { val eDeviceKeyBytes = engagement.eSenderKeyBytes assertEquals( TestVectors.ISO_18013_5_ANNEX_D_E_DEVICE_KEY_BYTES, - eDeviceKeyBytes.toHex + eDeviceKeyBytes.toHex() ) } } diff --git a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/mso/MobileSecurityObjectGeneratorTest.kt b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/mso/MobileSecurityObjectGeneratorTest.kt index 402bccdb7..33ae530af 100644 --- a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/mso/MobileSecurityObjectGeneratorTest.kt +++ b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/mso/MobileSecurityObjectGeneratorTest.kt @@ -152,8 +152,8 @@ class MobileSecurityObjectGeneratorTest { fun testFullMSO(digestAlgorithm: String) { val deviceKeyFromVector = EcPublicKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex() ) val signedTimestamp = Instant.fromEpochMilliseconds(1601559002000L) val validFromTimestamp = Instant.fromEpochMilliseconds(1601559002000L) @@ -163,7 +163,7 @@ class MobileSecurityObjectGeneratorTest { deviceKeyAuthorizedDataElements["a"] = listOf("1", "2", "f") deviceKeyAuthorizedDataElements["b"] = listOf("4", "5", "k") val keyInfo: MutableMap = HashMap() - keyInfo[10L] = "C985".fromHex + keyInfo[10L] = "C985".fromHex() val encodedMSO = MobileSecurityObjectGenerator( digestAlgorithm, "org.iso.18013.5.1.mDL", deviceKeyFromVector @@ -198,8 +198,8 @@ class MobileSecurityObjectGeneratorTest { assertEquals(deviceKeyAuthorizedDataElements, mso.deviceKeyAuthorizedDataElements) assertEquals(keyInfo.keys, mso.deviceKeyInfo!!.keys) assertEquals( - keyInfo[10L]!!.toHex, - mso.deviceKeyInfo!![10L]!!.toHex + keyInfo[10L]!!.toHex(), + mso.deviceKeyInfo!![10L]!!.toHex() ) assertEquals(signedTimestamp, mso.signed) assertEquals(validFromTimestamp, mso.validFrom) @@ -211,8 +211,8 @@ class MobileSecurityObjectGeneratorTest { fun testBasicMSO() { val deviceKeyFromVector = EcPublicKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex() ) val signedTimestamp = Instant.fromEpochMilliseconds(1601559002000L) val validFromTimestamp = Instant.fromEpochMilliseconds(1601559002000L) @@ -266,8 +266,8 @@ class MobileSecurityObjectGeneratorTest { fun testMSOExceptions() { val deviceKeyFromVector = EcPublicKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex() ) assertFailsWith( "expect exception for illegal digestAlgorithm") { diff --git a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/mso/MobileSecurityObjectParserTest.kt b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/mso/MobileSecurityObjectParserTest.kt index a1b798134..97310d07a 100644 --- a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/mso/MobileSecurityObjectParserTest.kt +++ b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/mso/MobileSecurityObjectParserTest.kt @@ -30,7 +30,7 @@ class MobileSecurityObjectParserTest { @Test fun testMSOParserWithVectors() { val deviceResponse = - Cbor.decode(TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex) + Cbor.decode(TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex()) val documentDataItem = deviceResponse["documents"][0] val issuerSigned = documentDataItem["issuerSigned"] val issuerAuthDataItem = issuerSigned["issuerAuth"] @@ -56,78 +56,78 @@ class MobileSecurityObjectParserTest { ) assertEquals( "75167333b47b6c2bfb86eccc1f438cf57af055371ac55e1e359e20f254adcebf", - isoDigestIDs[0L]!!.toHex + isoDigestIDs[0L]!!.toHex() ) assertEquals( "67e539d6139ebd131aef441b445645dd831b2b375b390ca5ef6279b205ed4571", - isoDigestIDs[1L]!!.toHex + isoDigestIDs[1L]!!.toHex() ) assertEquals( "3394372ddb78053f36d5d869780e61eda313d44a392092ad8e0527a2fbfe55ae", - isoDigestIDs[2L]!!.toHex + isoDigestIDs[2L]!!.toHex() ) assertEquals( "2e35ad3c4e514bb67b1a9db51ce74e4cb9b7146e41ac52dac9ce86b8613db555", - isoDigestIDs[3L]!!.toHex + isoDigestIDs[3L]!!.toHex() ) assertEquals( "ea5c3304bb7c4a8dcb51c4c13b65264f845541341342093cca786e058fac2d59", - isoDigestIDs[4L]!!.toHex + isoDigestIDs[4L]!!.toHex() ) assertEquals( "fae487f68b7a0e87a749774e56e9e1dc3a8ec7b77e490d21f0e1d3475661aa1d", - isoDigestIDs[5L]!!.toHex + isoDigestIDs[5L]!!.toHex() ) assertEquals( "7d83e507ae77db815de4d803b88555d0511d894c897439f5774056416a1c7533", - isoDigestIDs[6L]!!.toHex + isoDigestIDs[6L]!!.toHex() ) assertEquals( "f0549a145f1cf75cbeeffa881d4857dd438d627cf32174b1731c4c38e12ca936", - isoDigestIDs[7L]!!.toHex + isoDigestIDs[7L]!!.toHex() ) assertEquals( "b68c8afcb2aaf7c581411d2877def155be2eb121a42bc9ba5b7312377e068f66", - isoDigestIDs[8L]!!.toHex + isoDigestIDs[8L]!!.toHex() ) assertEquals( "0b3587d1dd0c2a07a35bfb120d99a0abfb5df56865bb7fa15cc8b56a66df6e0c", - isoDigestIDs[9L]!!.toHex + isoDigestIDs[9L]!!.toHex() ) assertEquals( "c98a170cf36e11abb724e98a75a5343dfa2b6ed3df2ecfbb8ef2ee55dd41c881", - isoDigestIDs[10L]!!.toHex + isoDigestIDs[10L]!!.toHex() ) assertEquals( "b57dd036782f7b14c6a30faaaae6ccd5054ce88bdfa51a016ba75eda1edea948", - isoDigestIDs[11L]!!.toHex + isoDigestIDs[11L]!!.toHex() ) assertEquals( "651f8736b18480fe252a03224ea087b5d10ca5485146c67c74ac4ec3112d4c3a", - isoDigestIDs[12L]!!.toHex + isoDigestIDs[12L]!!.toHex() ) val isoUSDigestIDs = mso.getDigestIDs("org.iso.18013.5.1.US") assertEquals(setOf(0L, 1L, 2L, 3L), isoUSDigestIDs!!.keys) assertEquals( "d80b83d25173c484c5640610ff1a31c949c1d934bf4cf7f18d5223b15dd4f21c", - isoUSDigestIDs[0L]!!.toHex + isoUSDigestIDs[0L]!!.toHex() ) assertEquals( "4d80e1e2e4fb246d97895427ce7000bb59bb24c8cd003ecf94bf35bbd2917e34", - isoUSDigestIDs[1L]!!.toHex + isoUSDigestIDs[1L]!!.toHex() ) assertEquals( "8b331f3b685bca372e85351a25c9484ab7afcdf0d2233105511f778d98c2f544", - isoUSDigestIDs[2L]!!.toHex + isoUSDigestIDs[2L]!!.toHex() ) assertEquals( "c343af1bd1690715439161aba73702c474abf992b20c9fb55c36a336ebe01a87", - isoUSDigestIDs[3L]!!.toHex + isoUSDigestIDs[3L]!!.toHex() ) val deviceKeyFromVector = EcPublicKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex() ) assertEquals(deviceKeyFromVector, mso.deviceKey) assertNull(mso.deviceKeyAuthorizedNameSpaces) diff --git a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/response/DeviceResponseParserTest.kt b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/response/DeviceResponseParserTest.kt index b3739675f..df76b0f70 100644 --- a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/response/DeviceResponseParserTest.kt +++ b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/response/DeviceResponseParserTest.kt @@ -38,19 +38,19 @@ class DeviceResponseParserTest { // NOTE: This tests tests the MAC verification path of DeviceResponseParser, the // ECDSA verification path is tested in DeviceResponseGeneratorTest by virtue of // SUtil.getIdentityCredentialStore() defaulting to the Jetpack. - val encodedDeviceResponse = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex + val encodedDeviceResponse = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex() // Strip the #6.24 tag since our APIs expects just the bytes of SessionTranscript. val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val encodedSessionTranscript = Cbor.encode( Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor ) val eReaderKey: EcPrivateKey = EcPrivateKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex() ) val dr = DeviceResponseParser( encodedDeviceResponse, @@ -76,8 +76,8 @@ class DeviceResponseParserTest { // Check DeviceKey is correctly parsed val deviceKeyFromVector = EcPublicKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_STATIC_DEVICE_KEY_Y.fromHex() ) assertEquals(deviceKeyFromVector, d.deviceKey) @@ -135,7 +135,7 @@ class DeviceResponseParserTest { ) ) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE_PORTRAIT_DATA.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE_PORTRAIT_DATA.fromHex(), d.getIssuerEntryByteString(MDL_NAMESPACE, "portrait") ) @@ -153,7 +153,7 @@ class DeviceResponseParserTest { val (certificates) = d.issuerCertificateChain assertEquals(1, certificates.size.toLong()) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_DS_CERT.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DS_CERT.fromHex(), certificates[0].encodedCertificate ) } @@ -161,7 +161,7 @@ class DeviceResponseParserTest { @Test fun testDeviceResponseParserWithVectorsMalformedIssuerItem() { val encodedDeviceResponse = - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex() // We know that the value for family_name in IssuerSignedItem is at offset 200. // Change this from "Doe" to "Foe" to force validation of that item to fail. @@ -171,15 +171,15 @@ class DeviceResponseParserTest { // Strip the #6.24 tag since our APIs expects just the bytes of SessionTranscript. val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val encodedSessionTranscript = Cbor.encode( Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor ) val eReaderKey: EcPrivateKey = EcPrivateKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex() ) val dr = DeviceResponseParser( encodedDeviceResponse, @@ -211,7 +211,7 @@ class DeviceResponseParserTest { @Test fun testDeviceResponseParserWithVectorsMalformedDeviceSigned() { - val encodedDeviceResponse = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex + val encodedDeviceResponse = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex() // We know that the 32 bytes for the MAC in DeviceMac CBOR starts at offset 3522 and // starts with E99521A8. Poison that to cause DeviceSigned to not authenticate. @@ -220,15 +220,15 @@ class DeviceResponseParserTest { // Strip the #6.24 tag since our APIs expects just the bytes of SessionTranscript. val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val encodedSessionTranscript = Cbor.encode( Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor ) val eReaderKey: EcPrivateKey = EcPrivateKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex() ) val dr = DeviceResponseParser( encodedDeviceResponse, @@ -253,7 +253,7 @@ class DeviceResponseParserTest { @Test fun testDeviceResponseParserWithVectorsMalformedIssuerSigned() { - val encodedDeviceResponse = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex + val encodedDeviceResponse = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex() // We know that issuer signature starts at offset 3398 and starts with 59E64205DF1E. // Poison that to cause IssuerSigned to not authenticate. @@ -262,15 +262,15 @@ class DeviceResponseParserTest { // Strip the #6.24 tag since our APIs expects just the bytes of SessionTranscript. val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val encodedSessionTranscript = Cbor.encode( Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor ) val eReaderKey: EcPrivateKey = EcPrivateKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex() ) val dr = DeviceResponseParser( encodedDeviceResponse, diff --git a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/sessionencryption/SessionEncryptionTest.kt b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/sessionencryption/SessionEncryptionTest.kt index d21d00c03..44f22fbee 100644 --- a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/sessionencryption/SessionEncryptionTest.kt +++ b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/sessionencryption/SessionEncryptionTest.kt @@ -34,14 +34,14 @@ class SessionEncryptionTest { fun testReaderAgainstVectors() { val eReaderKey: EcPrivateKey = EcPrivateKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_D.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_READER_KEY_Y.fromHex() ) // Strip the #6.24 tag since our APIs expects just the bytes of SessionTranscript. val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val sessionTranscript = Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor val deviceEngagementBytes = sessionTranscript[0] val encodedDeviceEngagement = deviceEngagementBytes.asTagged.asBstr @@ -57,33 +57,33 @@ class SessionEncryptionTest { // Check that encryption works. assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_SESSION_ESTABLISHMENT.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_SESSION_ESTABLISHMENT.fromHex(), sessionEncryption.encryptMessage( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex(), null ) ) // Check that decryption works. var result = sessionEncryption.decryptMessage( - TestVectors.ISO_18013_5_ANNEX_D_SESSION_DATA.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_DATA.fromHex() ) assertNull(result.second) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex(), result.first ) // Check that we parse status correctly. result = sessionEncryption.decryptMessage( - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TERMINATION.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TERMINATION.fromHex() ) assertEquals(Constants.SESSION_DATA_STATUS_SESSION_TERMINATION, result.second) assertNull(result.first) // Check we can generate messages with status. assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TERMINATION.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TERMINATION.fromHex(), sessionEncryption.encryptMessage( null, Constants.SESSION_DATA_STATUS_SESSION_TERMINATION @@ -95,16 +95,16 @@ class SessionEncryptionTest { fun testDeviceAgainstVectors() { val eDeviceKey: EcPrivateKey = EcPrivateKeyDoubleCoordinate( EcCurve.P256, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_DEVICE_KEY_D.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_DEVICE_KEY_X.fromHex, - TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_DEVICE_KEY_Y.fromHex + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_DEVICE_KEY_D.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_DEVICE_KEY_X.fromHex(), + TestVectors.ISO_18013_5_ANNEX_D_EPHEMERAL_DEVICE_KEY_Y.fromHex() ) // Strip the #6.24 tag since our API expects just the bytes of SessionTranscript. val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val sessionTranscript = Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor - val sessionEstablishment = TestVectors.ISO_18013_5_ANNEX_D_SESSION_ESTABLISHMENT.fromHex + val sessionEstablishment = TestVectors.ISO_18013_5_ANNEX_D_SESSION_ESTABLISHMENT.fromHex() val eReaderKey = Cbor.decode(sessionEstablishment)["eReaderKey"] .asTaggedEncodedCbor.asCoseKey.ecPublicKey val sessionEncryptionDevice = SessionEncryption( @@ -120,22 +120,22 @@ class SessionEncryptionTest { ) assertNull(result.second) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex(), result.first ) // Check that encryption works. assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_SESSION_DATA.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_SESSION_DATA.fromHex(), sessionEncryptionDevice.encryptMessage( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex(), null ) ) // Check that we parse status correctly. result = sessionEncryptionDevice.decryptMessage( - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TERMINATION.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TERMINATION.fromHex() ) assertEquals( Constants.SESSION_DATA_STATUS_SESSION_TERMINATION, @@ -145,7 +145,7 @@ class SessionEncryptionTest { // Check we can generate messages with status. assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TERMINATION.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TERMINATION.fromHex(), sessionEncryptionDevice.encryptMessage(null, 20L) ) } @@ -176,7 +176,7 @@ class SessionEncryptionTest { for (i in 1..3) { // have reader generate sessionEstablishment and check holder decryption of sessionEstablishment val mdocRequest = sessionEncryptionReader.encryptMessage( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex(), null ) var result = sessionEncryptionHolder.decryptMessage( @@ -184,7 +184,7 @@ class SessionEncryptionTest { ) assertNull(result.second) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex(), result.first ) assertEquals(i.toLong(), sessionEncryptionReader.numMessagesEncrypted.toLong()) @@ -192,13 +192,13 @@ class SessionEncryptionTest { // have holder generate deviceResponse and check reader decryption of deviceResponse val deviceResponse = sessionEncryptionHolder.encryptMessage( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex(), null ) result = sessionEncryptionReader.decryptMessage(deviceResponse) assertNull(result.second) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex(), result.first ) assertEquals(i.toLong(), sessionEncryptionHolder.numMessagesEncrypted.toLong()) diff --git a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/util/MdocUtilTest.kt b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/util/MdocUtilTest.kt index ecf047aa7..c1ee0a763 100644 --- a/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/util/MdocUtilTest.kt +++ b/identity-mdoc/src/commonTest/kotlin/com/android/identity/mdoc/util/MdocUtilTest.kt @@ -130,25 +130,25 @@ class MdocUtilTest { assertEquals(3, digests.size.toLong()) assertEquals( "9f10afbca223fcfe0ee9f239e995cfe79e7f845b68981a4a0943706717c64efa", - digests[0L]!!.toHex + digests[0L]!!.toHex() ) assertEquals( "a5e74b031ea380267d39905981ea80c68178229219556ffd72d312a0366a7d63", - digests[4L]!!.toHex + digests[4L]!!.toHex() ) assertEquals( "03f0ac0623c2eaefd76bcbca00df782d84f544cf7ac1b1f9ed46144275e1d47c", - digests[2L]!!.toHex + digests[2L]!!.toHex() ) digests = calculateDigestsForNameSpace("ns2", issuerNameSpaces, Algorithm.SHA256) assertEquals(2, digests.size.toLong()) assertEquals( "fd69be5fcc0df04ae78e147bb3ad95ce4ecff51028322cccf02195f36612a212", - digests[1L]!!.toHex + digests[1L]!!.toHex() ) assertEquals( "47083a3473ddfcf3c8cc00f2035ac41d0b791fc50106be416c068536c249c0dd", - digests[3L]!!.toHex + digests[3L]!!.toHex() ) // Check stripping @@ -222,7 +222,7 @@ class MdocUtilTest { @Test fun testGetDigestsForNameSpaceInTestVectors() { val deviceResponse = Cbor.decode( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_RESPONSE.fromHex() ) val documentDataItem = deviceResponse["documents"][0] val issuerSigned = documentDataItem["issuerSigned"] @@ -261,12 +261,12 @@ class MdocUtilTest { @Test fun testGenerateDocumentRequest() { val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val encodedSessionTranscript = Cbor.encode( Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor ) val parser = DeviceRequestParser( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex(), encodedSessionTranscript ) val request = parser.parse() diff --git a/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/request/DeviceRequestGeneratorTest.kt b/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/request/DeviceRequestGeneratorTest.kt index 9a51fcb37..46e8f20af 100644 --- a/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/request/DeviceRequestGeneratorTest.kt +++ b/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/request/DeviceRequestGeneratorTest.kt @@ -85,7 +85,7 @@ class DeviceRequestGeneratorTest { val readerCertChain = X509CertChain(listOf(readerCert)) val mdlRequestInfo: MutableMap = HashMap() mdlRequestInfo["foo"] = Cbor.encode(Tstr("bar")) - mdlRequestInfo["bar"] = Cbor.encode(42.toDataItem) + mdlRequestInfo["bar"] = Cbor.encode(42.toDataItem()) val encodedDeviceRequest = DeviceRequestGenerator(encodedSessionTranscript) .addDocumentRequest( MDL_DOCTYPE, @@ -137,7 +137,7 @@ class DeviceRequestGeneratorTest { assertNotNull(requestInfo) assertEquals(2, requestInfo.keys.size.toLong()) assertContentEquals(Cbor.encode(Tstr("bar")), requestInfo["foo"]) - assertContentEquals(Cbor.encode(42.toDataItem), requestInfo["bar"]) + assertContentEquals(Cbor.encode(42.toDataItem()), requestInfo["bar"]) docRequest = it.next() assertTrue(docRequest.readerAuthenticated) assertEquals(MVR_DOCTYPE, docRequest.docType) diff --git a/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/request/DeviceRequestParserTest.kt b/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/request/DeviceRequestParserTest.kt index 40d21f893..a484e1f3c 100644 --- a/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/request/DeviceRequestParserTest.kt +++ b/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/request/DeviceRequestParserTest.kt @@ -50,11 +50,11 @@ class DeviceRequestParserTest { fun testDeviceRequestParserWithVectors() { // Strip the #6.24 tag since our APIs expects just the bytes of SessionTranscript. val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val encodedSessionTranscript = Cbor.encode(Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor) val parser = DeviceRequestParser( - TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex(), encodedSessionTranscript ) val request = parser.parse() @@ -64,17 +64,17 @@ class DeviceRequestParserTest { val dr = docRequests.iterator().next() assertEquals(MDL_DOCTYPE, dr.docType) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_ITEMS_REQUEST.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_ITEMS_REQUEST.fromHex(), dr.itemsRequest ) val readerCertChain = dr.readerCertificateChain assertEquals(1, readerCertChain!!.certificates.size.toLong()) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_READER_CERT.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_READER_CERT.fromHex(), readerCertChain.certificates[0].encodedCertificate ) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_READER_AUTH.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_READER_AUTH.fromHex(), dr.readerAuth ) assertTrue(dr.readerAuthenticated) @@ -104,14 +104,14 @@ class DeviceRequestParserTest { fun testDeviceRequestParserWithVectorsMalformedReaderSignature() { // Strip the #6.24 tag since our APIs expects just the bytes of SessionTranscript. val encodedSessionTranscriptBytes = - TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex + TestVectors.ISO_18013_5_ANNEX_D_SESSION_TRANSCRIPT_BYTES.fromHex() val encodedSessionTranscript = Cbor.encode(Cbor.decode(encodedSessionTranscriptBytes).asTaggedEncodedCbor) // We know the COSE_Sign1 signature for reader authentication is at index 655 and // starts with 1f340006... Poison that so we can check whether signature verification // detects it... - val encodedDeviceRequest = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex + val encodedDeviceRequest = TestVectors.ISO_18013_5_ANNEX_D_DEVICE_REQUEST.fromHex() assertEquals(0x1f.toByte().toLong(), encodedDeviceRequest[655].toLong()) encodedDeviceRequest[655] = 0x1e val parser = DeviceRequestParser( @@ -125,13 +125,13 @@ class DeviceRequestParserTest { val dr = docRequests.iterator().next() assertEquals(MDL_DOCTYPE, dr.docType) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_ITEMS_REQUEST.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_ITEMS_REQUEST.fromHex(), dr.itemsRequest ) val readerCertChain = dr.readerCertificateChain assertEquals(1, readerCertChain!!.certificates.size.toLong()) assertContentEquals( - TestVectors.ISO_18013_5_ANNEX_D_READER_CERT.fromHex, + TestVectors.ISO_18013_5_ANNEX_D_READER_CERT.fromHex(), readerCertChain.certificates[0].encodedCertificate ) assertFalse(dr.readerAuthenticated) @@ -166,7 +166,7 @@ class DeviceRequestParserTest { val readerCertChain = X509CertChain(listOf(certificate)) val mdlRequestInfo: MutableMap = HashMap() mdlRequestInfo["foo"] = Cbor.encode(Tstr("bar")) - mdlRequestInfo["bar"] = Cbor.encode(42.toDataItem) + mdlRequestInfo["bar"] = Cbor.encode(42.toDataItem()) val encodedDeviceRequest = DeviceRequestGenerator(encodedSessionTranscript) .addDocumentRequest( MDL_DOCTYPE, diff --git a/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/response/DeviceResponseGeneratorTest.kt b/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/response/DeviceResponseGeneratorTest.kt index 41b12862e..6ec7ca6d3 100644 --- a/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/response/DeviceResponseGeneratorTest.kt +++ b/identity-mdoc/src/jvmTest/kotlin/com/android/identity/mdoc/response/DeviceResponseGeneratorTest.kt @@ -189,13 +189,13 @@ class DeviceResponseGeneratorTest { val protectedHeaders = mapOf( Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - Algorithm.ES256.coseAlgorithmIdentifier.toDataItem + Algorithm.ES256.coseAlgorithmIdentifier.toDataItem() ) ) val unprotectedHeaders = mapOf( Pair( CoseNumberLabel(Cose.COSE_LABEL_X5CHAIN), - X509CertChain(listOf(documentSignerCert)).toDataItem + X509CertChain(listOf(documentSignerCert)).toDataItem() ) ) val encodedIssuerAuth = Cbor.encode( @@ -206,7 +206,7 @@ class DeviceResponseGeneratorTest { Algorithm.ES256, protectedHeaders, unprotectedHeaders - ).toDataItem + ).toDataItem() ) val issuerProvidedAuthenticationData = StaticAuthDataGenerator( MdocUtil.stripIssuerNameSpaces(issuerNameSpaces, exceptions), diff --git a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/Disclosure.kt b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/Disclosure.kt index 6222cc111..e041652e8 100644 --- a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/Disclosure.kt +++ b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/Disclosure.kt @@ -34,7 +34,7 @@ class Disclosure( val value: JsonElement init { - val contentsString = String(disclosure.fromBase64, Charsets.UTF_8) + val contentsString = String(disclosure.fromBase64(), Charsets.UTF_8) val contents = Json.decodeFromString(JsonArray.serializer(), contentsString).jsonArray key = contents[1].jsonPrimitive.content value = contents[2] @@ -62,7 +62,7 @@ class Disclosure( override fun toString(): String = disclosure val hash - get() = Crypto.digest(digestAlg, toString().toByteArray()).toBase64 + get() = Crypto.digest(digestAlg, toString().toByteArray()).toBase64() companion object { private fun calculateDisclosure(key: String, value: JsonElement, random: Random): String { @@ -71,7 +71,7 @@ class Disclosure( add(JsonPrimitive(key)) add(value) } - return disclosureArray.toString().toByteArray(Charsets.UTF_8).toBase64 + return disclosureArray.toString().toByteArray(Charsets.UTF_8).toBase64() } } } @@ -79,5 +79,5 @@ class Disclosure( private fun Random.getRandomSalt(): String { val bytes = ByteArray(20) this.nextBytes(bytes) - return bytes.toBase64 + return bytes.toBase64() } \ No newline at end of file diff --git a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/SdJwtVcGenerator.kt b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/SdJwtVcGenerator.kt index 2d836c976..1c3449204 100644 --- a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/SdJwtVcGenerator.kt +++ b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/SdJwtVcGenerator.kt @@ -86,7 +86,7 @@ class SdJwtVcGenerator( val toBeSigned = "$headerStr.$bodyStr".toByteArray(Charsets.US_ASCII) val signature = sign(toBeSigned, issuer) - val signatureStr = (signature.r + signature.s).toBase64 + val signatureStr = (signature.r + signature.s).toBase64() return SdJwtVerifiableCredential( headerStr, diff --git a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/SdJwtVerifiableCredential.kt b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/SdJwtVerifiableCredential.kt index 6036a932d..e23c143ce 100644 --- a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/SdJwtVerifiableCredential.kt +++ b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/SdJwtVerifiableCredential.kt @@ -110,7 +110,7 @@ class SdJwtVerifiableCredential( val bodyObj = JwtBody.fromString(body) val toBeVerified = "$header.$body".toByteArray(Charsets.US_ASCII) - val signature = EcSignature.fromCoseEncoded(signature.fromBase64) + val signature = EcSignature.fromCoseEncoded(signature.fromBase64()) if(!verify(headerObj, bodyObj, toBeVerified, signature)) { throw IllegalStateException("Signature verification failed") @@ -140,12 +140,12 @@ class SdJwtVerifiableCredential( val keyBindingHeaderStr = KeyBindingHeader(alg).toString() - val sdHash = Crypto.digest(this.sdHashAlg, toString().toByteArray()).toBase64 + val sdHash = Crypto.digest(this.sdHashAlg, toString().toByteArray()).toBase64() val keyBindingBodyStr = KeyBindingBody(nonce, audience, creationTime, sdHash).toString() val toBeSigned = "$keyBindingHeaderStr.$keyBindingBodyStr".toByteArray(Charsets.US_ASCII) val signature = secureArea.sign(alias, alg, toBeSigned, keyUnlockData) - val signatureStr = signature.toCoseEncoded().toBase64 + val signatureStr = signature.toCoseEncoded().toBase64() return SdJwtVerifiablePresentation( this, diff --git a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/presentation/SdJwtVerifiablePresentation.kt b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/presentation/SdJwtVerifiablePresentation.kt index 0ec82e2a4..9c9774797 100644 --- a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/presentation/SdJwtVerifiablePresentation.kt +++ b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/presentation/SdJwtVerifiablePresentation.kt @@ -35,13 +35,13 @@ class SdJwtVerifiablePresentation( val keyBindingBodyObj = KeyBindingBody.fromString(keyBindingBody) // compare the hash of the VC against what's in the key binding JWT - val sdHash = Crypto.digest(sdJwtVc.sdHashAlg, sdJwtVc.toString().toByteArray()).toBase64 + val sdHash = Crypto.digest(sdJwtVc.sdHashAlg, sdJwtVc.toString().toByteArray()).toBase64() if (sdHash != keyBindingBodyObj.sdHash) { throw IllegalStateException("hash in key binding JWT didn't match SD-JWT") } val toBeVerified = "$keyBindingHeader.$keyBindingBody".toByteArray(Charsets.US_ASCII) - val signature = EcSignature.fromCoseEncoded(keyBindingSignature.fromBase64) + val signature = EcSignature.fromCoseEncoded(keyBindingSignature.fromBase64()) if (!Crypto.checkSignature(key, toBeVerified, keyBindingHeaderObj.algorithm, signature)) { throw IllegalStateException("Signature verification failed") diff --git a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/util/JsonWebKey.kt b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/util/JsonWebKey.kt index c89dfa294..f7c346bb3 100644 --- a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/util/JsonWebKey.kt +++ b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/util/JsonWebKey.kt @@ -51,13 +51,13 @@ class JsonWebKey { is EcPublicKeyOkp -> { put("kty", JsonPrimitive("OKP")) put("crv", JsonPrimitive(pubKey.curve.jwkName)) - put("x", JsonPrimitive(pubKey.x.toBase64)) + put("x", JsonPrimitive(pubKey.x.toBase64())) } is EcPublicKeyDoubleCoordinate -> { put("kty", JsonPrimitive("EC")) put("crv", JsonPrimitive(pubKey.curve.jwkName)) - put("x", JsonPrimitive(pubKey.x.toBase64)) - put("y", JsonPrimitive(pubKey.y.toBase64)) + put("x", JsonPrimitive(pubKey.x.toBase64())) + put("y", JsonPrimitive(pubKey.y.toBase64())) } else -> throw IllegalStateException("Unsupported key $pubKey") } @@ -72,14 +72,14 @@ class JsonWebKey { "OKP" -> { EcPublicKeyOkp( EcCurve.fromJwkName(key.getString("crv")), - key.getString("x").fromBase64 + key.getString("x").fromBase64() ) } "EC" -> { EcPublicKeyDoubleCoordinate( EcCurve.fromJwkName(key.getString("crv")), - key.getString("x").fromBase64, - key.getString("y").fromBase64 + key.getString("x").fromBase64(), + key.getString("y").fromBase64() ) } else -> throw IllegalArgumentException("Not supporting key type $kty") diff --git a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/util/JwtJsonObject.kt b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/util/JwtJsonObject.kt index da2cf0b14..4a5e7f7a1 100644 --- a/identity-sdjwt/src/main/java/com/android/identity/sdjwt/util/JwtJsonObject.kt +++ b/identity-sdjwt/src/main/java/com/android/identity/sdjwt/util/JwtJsonObject.kt @@ -23,14 +23,14 @@ abstract class JwtJsonObject { private fun toJsonObject() = buildJsonObject(buildJson()) - override fun toString() = toJsonObject().toString().toByteArray().toBase64 + override fun toString() = toJsonObject().toString().toByteArray().toBase64() protected companion object { @JvmStatic protected fun parse(input: String): JsonObject { return Json.decodeFromString( JsonObject.serializer(), - String(input.fromBase64)) + String(input.fromBase64())) } } } diff --git a/identity/src/commonMain/kotlin/com/android/identity/cbor/ArrayBuilder.kt b/identity/src/commonMain/kotlin/com/android/identity/cbor/ArrayBuilder.kt index 3efbb517b..af4c65a39 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cbor/ArrayBuilder.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cbor/ArrayBuilder.kt @@ -78,7 +78,7 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: ByteArray) = apply { - add(value.toDataItem) + add(value.toDataItem()) } /** @@ -88,7 +88,7 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: String) = apply { - add(value.toDataItem) + add(value.toDataItem()) } /** @@ -98,7 +98,7 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: Byte) = apply { - add(value.toDataItem) + add(value.toDataItem()) } /** @@ -108,7 +108,7 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: Short) = apply { - add(value.toDataItem) + add(value.toDataItem()) } /** @@ -118,7 +118,7 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: Int) = apply { - add(value.toDataItem) + add(value.toDataItem()) } /** @@ -128,7 +128,7 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: Long) = apply { - add(value.toDataItem) + add(value.toDataItem()) } /** @@ -138,7 +138,7 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: Boolean) = apply { - add(value.toDataItem) + add(value.toDataItem()) } /** @@ -148,7 +148,7 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: Double) = apply { - add(value.toDataItem) + add(value.toDataItem()) } @@ -159,6 +159,6 @@ data class ArrayBuilder(private val parent: T, private val array: CborArray) * @return the builder. */ fun add(value: Float) = apply { - add(value.toDataItem) + add(value.toDataItem()) } } diff --git a/identity/src/commonMain/kotlin/com/android/identity/cbor/DataItem.kt b/identity/src/commonMain/kotlin/com/android/identity/cbor/DataItem.kt index 9e38ad00f..7b9029f6a 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cbor/DataItem.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cbor/DataItem.kt @@ -216,7 +216,7 @@ sealed class DataItem( */ fun hasKey(key: String): Boolean { require(this is CborMap) - return items.get(key.toDataItem) != null + return items.get(key.toDataItem()) != null } /** @@ -228,7 +228,7 @@ sealed class DataItem( */ fun hasKey(key: Long): Boolean { require(this is CborMap) - return items.get(key.toDataItem) != null + return items.get(key.toDataItem()) != null } /** @@ -257,7 +257,7 @@ sealed class DataItem( * @throws IllegalStateException if the value doesn't exist in the map. */ operator fun get(key: String): DataItem { - return get(key.toDataItem) + return get(key.toDataItem()) } /** @@ -275,7 +275,7 @@ sealed class DataItem( items[key.toInt()] } else -> { - get(key.toDataItem) + get(key.toDataItem()) } } } @@ -307,7 +307,7 @@ sealed class DataItem( */ fun getOrDefault(key: String, defaultValue: DataItem): DataItem { require(this is CborMap) - val value = items.get(key.toDataItem) + val value = items.get(key.toDataItem()) if (value == null) { return defaultValue } @@ -324,7 +324,7 @@ sealed class DataItem( */ fun getOrDefault(key: Long, defaultValue: DataItem): DataItem { require(this is CborMap) - val value = items.get(key.toDataItem) + val value = items.get(key.toDataItem()) if (value == null) { return defaultValue } @@ -352,7 +352,7 @@ sealed class DataItem( */ fun getOrNull(key: String): DataItem? { require(this is CborMap) - return items.get(key.toDataItem) + return items.get(key.toDataItem()) } /** @@ -364,7 +364,7 @@ sealed class DataItem( */ fun getOrNull(key: Long): DataItem? { require(this is CborMap) - return items.get(key.toDataItem) + return items.get(key.toDataItem()) } /** diff --git a/identity/src/commonMain/kotlin/com/android/identity/cbor/DataItemExtensions.kt b/identity/src/commonMain/kotlin/com/android/identity/cbor/DataItemExtensions.kt index b8fee1632..5fff352e5 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cbor/DataItemExtensions.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cbor/DataItemExtensions.kt @@ -7,38 +7,32 @@ import kotlinx.datetime.toInstant /** * Extension to get a [Tstr] data item for the value. */ -val String.toDataItem: Tstr - get() = Tstr(this) +fun String.toDataItem(): Tstr = Tstr(this) /** * Extension to get a [Bstr] data item for the value. */ -val ByteArray.toDataItem: Bstr - get() = Bstr(this) +fun ByteArray.toDataItem(): Bstr = Bstr(this) /** * Extension to get a [CborInt] data item for the value. */ -val Byte.toDataItem: CborInt - get() = this.toLong().toDataItem +fun Byte.toDataItem(): CborInt = this.toLong().toDataItem() /** * Extension to get a [CborInt] data item for the value. */ -val Short.toDataItem: CborInt - get() = this.toLong().toDataItem +fun Short.toDataItem(): CborInt = this.toLong().toDataItem() /** * Extension to get a [CborInt] data item for the value. */ -val Int.toDataItem: CborInt - get() = this.toLong().toDataItem +fun Int.toDataItem(): CborInt = this.toLong().toDataItem() /** * Extension to get a [CborInt] data item for the value. */ -val Long.toDataItem: CborInt - get() = if (this >= 0) { +fun Long.toDataItem(): CborInt = if (this >= 0) { Uint(toULong()) } else { Nint((-this).toULong()) @@ -47,8 +41,7 @@ val Long.toDataItem: CborInt /** * Extension to get a [Simple] data item for the value. */ -val Boolean.toDataItem: Simple - get() = if (this) { +fun Boolean.toDataItem(): Simple = if (this) { Simple.TRUE } else { Simple.FALSE @@ -57,28 +50,24 @@ val Boolean.toDataItem: Simple /** * Extension to get a [CborFloat] data item for the value. */ -val Float.toDataItem: CborFloat - get() = CborFloat(this) +fun Float.toDataItem(): CborFloat = CborFloat(this) /** * Extension to get a [CborDouble] data item for the value. */ -val Double.toDataItem: CborDouble - get() = CborDouble(this) +fun Double.toDataItem(): CborDouble = CborDouble(this) /** * Extension to get a date-time string data item for a point in time. */ -val Instant.toDataItemDateTimeString: DataItem - get() = Tagged(Tagged.DATE_TIME_STRING, Tstr(this.toString())) +fun Instant.toDataItemDateTimeString(): DataItem = Tagged(Tagged.DATE_TIME_STRING, Tstr(this.toString())) /** * Extension to get a date-time string data item for a point in time. * * The value of the [Long] is interpreted as number of milliseconds since the Epoch. */ -val Long.toDataItemDateTimeString: DataItem - get() { +fun Long.toDataItemDateTimeString(): DataItem { val instant = Instant.fromEpochMilliseconds(this) return Tagged(Tagged.DATE_TIME_STRING, Tstr(instant.toString())) } @@ -87,13 +76,11 @@ val Long.toDataItemDateTimeString: DataItem * Extension to get a date-time string data item for a RFC 3339-formatted string representing a * point in time. */ -val String.toDataItemDateTimeString: DataItem - get() = Instant.parse(this).toDataItemDateTimeString +fun String.toDataItemDateTimeString(): DataItem = Instant.parse(this).toDataItemDateTimeString() /** * Extension to get a full-date data item as specified in RFC 8943. * * The tagged text string is represented as specified by the RFC 3339 full-date production. */ -val LocalDate.toDataItemFullDate: DataItem - get() = Tagged(Tagged.FULL_DATE_STRING, Tstr(this.toString())) +fun LocalDate.toDataItemFullDate(): DataItem = Tagged(Tagged.FULL_DATE_STRING, Tstr(this.toString())) diff --git a/identity/src/commonMain/kotlin/com/android/identity/cbor/MapBuilder.kt b/identity/src/commonMain/kotlin/com/android/identity/cbor/MapBuilder.kt index 6eca7f543..1377e97d5 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cbor/MapBuilder.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cbor/MapBuilder.kt @@ -86,7 +86,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: DataItem) = apply { - map.items[key.toDataItem] = value + map.items[key.toDataItem()] = value } /** @@ -97,7 +97,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: String) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -108,7 +108,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: ByteArray) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -119,7 +119,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: Byte) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -130,7 +130,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: Short) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -141,7 +141,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: Int) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -152,7 +152,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: Long) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -163,7 +163,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: Boolean) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -174,7 +174,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: Double) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -185,7 +185,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: String, value: Float) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -197,7 +197,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @param key the key. * @return a [ArrayBuilder]. */ - fun putArray(key: String): ArrayBuilder> = putArray(key.toDataItem) + fun putArray(key: String): ArrayBuilder> = putArray(key.toDataItem()) /** * Puts a new map in the map. @@ -209,7 +209,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return a [MapBuilder]. */ fun putMap(key: String): MapBuilder> { - return putMap(key.toDataItem) + return putMap(key.toDataItem()) } /** @@ -221,7 +221,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun putTagged(key: String, tagNumber: Long, value: DataItem) = apply { - putTagged(key.toDataItem, tagNumber, value) + putTagged(key.toDataItem(), tagNumber, value) } /** @@ -231,7 +231,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @param encodedCbor the bytes of the encoded CBOR. */ fun putTaggedEncodedCbor(key: String, encodedCbor: ByteArray) = apply { - putTaggedEncodedCbor(key.toDataItem, encodedCbor) + putTaggedEncodedCbor(key.toDataItem(), encodedCbor) } // Convenience putters for Long keys @@ -244,7 +244,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: DataItem) = apply { - map.items[key.toDataItem] = value + map.items[key.toDataItem()] = value } /** @@ -255,7 +255,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: String) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -266,7 +266,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: ByteArray) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -277,7 +277,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: Byte) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -288,7 +288,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: Short) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -299,7 +299,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: Int) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -310,7 +310,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: Long) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -321,7 +321,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: Boolean) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -332,7 +332,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: Double) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -343,7 +343,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun put(key: Long, value: Float) = apply { - put(key.toDataItem, value.toDataItem) + put(key.toDataItem(), value.toDataItem()) } /** @@ -355,7 +355,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @param key the key. * @return a [ArrayBuilder]. */ - fun putArray(key: Long): ArrayBuilder> = putArray(key.toDataItem) + fun putArray(key: Long): ArrayBuilder> = putArray(key.toDataItem()) /** * Puts a new map in the map. @@ -366,7 +366,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @param key the key. * @return a [MapBuilder]. */ - fun putMap(key: Long): MapBuilder> = putMap(key.toDataItem) + fun putMap(key: Long): MapBuilder> = putMap(key.toDataItem()) /** * Puts a tagged data item in the map. @@ -377,7 +377,7 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @return the builder. */ fun putTagged(key: Long, tagNumber: Long, value: DataItem): MapBuilder = - putTagged(key.toDataItem, tagNumber, value) + putTagged(key.toDataItem(), tagNumber, value) /** @@ -387,6 +387,6 @@ class MapBuilder(private val parent: T, private val map: CborMap) { * @param encodedCbor the bytes of the encoded CBOR. */ fun putTaggedEncodedCbor(key: Long, encodedCbor: ByteArray) = apply { - putTaggedEncodedCbor(key.toDataItem, encodedCbor) + putTaggedEncodedCbor(key.toDataItem(), encodedCbor) } } diff --git a/identity/src/commonMain/kotlin/com/android/identity/cose/Cose.kt b/identity/src/commonMain/kotlin/com/android/identity/cose/Cose.kt index 52e2386a5..d2c20d181 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cose/Cose.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cose/Cose.kt @@ -140,7 +140,7 @@ object Cose { val encodedProtectedHeaders = if (signature.protectedHeaders.isNotEmpty()) { val phb = CborMap.builder() - signature.protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem, di) } + signature.protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem(), di) } Cbor.encode(phb.end().build()) } else { byteArrayOf() @@ -189,7 +189,7 @@ object Cose { ): CoseSign1 { val encodedProtectedHeaders = if (protectedHeaders.isNotEmpty()) { val phb = CborMap.builder() - protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem, di) } + protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem(), di) } Cbor.encode(phb.end().build()) } else { byteArrayOf() @@ -233,7 +233,7 @@ object Cose { ): CoseSign1 { val encodedProtectedHeaders = if (protectedHeaders.size > 0) { val phb = CborMap.builder() - protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem, di) } + protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem(), di) } Cbor.encode(phb.end().build()) } else { byteArrayOf() @@ -272,7 +272,7 @@ object Cose { ): CoseMac0 { val encodedProtectedHeaders = if (protectedHeaders.size > 0) { val phb = CborMap.builder() - protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem, di) } + protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem(), di) } Cbor.encode(phb.end().build()) } else { byteArrayOf() diff --git a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseKey.kt b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseKey.kt index f22cd4544..83b7c7a6b 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseKey.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseKey.kt @@ -28,13 +28,13 @@ class CoseKey(val labels: Map) { /** * Encodes the COSE Key as a CBOR data item. */ - val toDataItem: DataItem - get() = CborMap.builder().apply { + fun toDataItem(): DataItem { + return CborMap.builder().apply { for ((key, value) in labels) { - put(key.toDataItem, value) + put(key.toDataItem(), value) } }.end().build() - + } /** * Gets the public key in the COSE Key as a [EcPublicKey]. diff --git a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseLabel.kt b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseLabel.kt index 127bf5b60..f62b560e1 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseLabel.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseLabel.kt @@ -13,7 +13,7 @@ sealed class CoseLabel { /** * The CBOR encoding for a COSE Label. */ - abstract val toDataItem: DataItem + abstract fun toDataItem(): DataItem companion object { /** diff --git a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseMac0.kt b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseMac0.kt index 1833f608d..d61a70231 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseMac0.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseMac0.kt @@ -24,32 +24,31 @@ data class CoseMac0( /** * Encodes the COSE_Mac0 as a CBOR data item. */ - val toDataItem: DataItem - get() { - val uphb = CborMap.builder() - unprotectedHeaders.forEach { (label, dataItem) -> uphb.put(label.toDataItem, dataItem) } + fun toDataItem(): DataItem { + val uphb = CborMap.builder() + unprotectedHeaders.forEach { (label, dataItem) -> uphb.put(label.toDataItem(), dataItem) } - val serializedProtectedHeaders = - if (protectedHeaders.isNotEmpty()) { - val phb = CborMap.builder() - protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem, di) } - Cbor.encode(phb.end().build()) - } else { - byteArrayOf() - } - val payloadOrNil = - if (payload != null) { - Bstr(payload) - } else { - Simple.NULL - } - return CborArray.builder() - .add(serializedProtectedHeaders) - .add(uphb.end().build()) - .add(payloadOrNil) - .add(tag) - .end().build() - } + val serializedProtectedHeaders = + if (protectedHeaders.isNotEmpty()) { + val phb = CborMap.builder() + protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem(), di) } + Cbor.encode(phb.end().build()) + } else { + byteArrayOf() + } + val payloadOrNil = + if (payload != null) { + Bstr(payload) + } else { + Simple.NULL + } + return CborArray.builder() + .add(serializedProtectedHeaders) + .add(uphb.end().build()) + .add(payloadOrNil) + .add(tag) + .end().build() + } companion object { /** diff --git a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseNumberLabel.kt b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseNumberLabel.kt index 4199ec3fe..fba6dfdc7 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseNumberLabel.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseNumberLabel.kt @@ -9,8 +9,7 @@ import com.android.identity.cbor.toDataItem * @param number the number. */ data class CoseNumberLabel(val number: Long) : CoseLabel() { - override val toDataItem: DataItem - get() = number.toDataItem + override fun toDataItem(): DataItem = number.toDataItem() } /** diff --git a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseSign1.kt b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseSign1.kt index 09c6067f4..ac1b91e5f 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseSign1.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseSign1.kt @@ -24,32 +24,31 @@ data class CoseSign1( /** * Encodes the COSE_Sign1 as a CBOR data item. */ - val toDataItem: DataItem - get() { - val uphb = CborMap.builder() - unprotectedHeaders.forEach { (label, dataItem) -> uphb.put(label.toDataItem, dataItem) } + fun toDataItem(): DataItem { + val uphb = CborMap.builder() + unprotectedHeaders.forEach { (label, dataItem) -> uphb.put(label.toDataItem(), dataItem) } - val serializedProtectedHeaders = - if (protectedHeaders.isNotEmpty()) { - val phb = CborMap.builder() - protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem, di) } - Cbor.encode(phb.end().build()) - } else { - byteArrayOf() - } - val payloadOrNil = - if (payload != null) { - Bstr(payload) - } else { - Simple.NULL - } - return CborArray.builder() - .add(serializedProtectedHeaders) - .add(uphb.end().build()) - .add(payloadOrNil) - .add(signature) - .end().build() - } + val serializedProtectedHeaders = + if (protectedHeaders.isNotEmpty()) { + val phb = CborMap.builder() + protectedHeaders.forEach { (label, di) -> phb.put(label.toDataItem(), di) } + Cbor.encode(phb.end().build()) + } else { + byteArrayOf() + } + val payloadOrNil = + if (payload != null) { + Bstr(payload) + } else { + Simple.NULL + } + return CborArray.builder() + .add(serializedProtectedHeaders) + .add(uphb.end().build()) + .add(payloadOrNil) + .add(signature) + .end().build() + } companion object { /** diff --git a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseTextLabel.kt b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseTextLabel.kt index f52623886..4ab514090 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/cose/CoseTextLabel.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/cose/CoseTextLabel.kt @@ -9,12 +9,10 @@ import com.android.identity.cbor.toDataItem * @param text the string. */ data class CoseTextLabel(val text: String) : CoseLabel() { - override val toDataItem: DataItem - get() = text.toDataItem + override fun toDataItem(): DataItem = text.toDataItem() } /** * Gets a [CoseLabel] from a string. */ -val String.toCoseLabel - get() = CoseTextLabel(this) +fun String.toCoseLabel() = CoseTextLabel(this) diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKey.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKey.kt index 695f869a0..323f23bf1 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKey.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKey.kt @@ -61,7 +61,7 @@ sealed class EcPrivateKey( */ fun fromCoseKey(coseKey: CoseKey): EcPrivateKey = when (coseKey.keyType) { - Cose.COSE_KEY_TYPE_EC2.toDataItem -> { + Cose.COSE_KEY_TYPE_EC2.toDataItem() -> { val curve = EcCurve.fromInt( coseKey.labels[Cose.COSE_KEY_PARAM_CRV.toCoseLabel]!!.asNumber.toInt() ) @@ -74,7 +74,7 @@ sealed class EcPrivateKey( EcPrivateKeyDoubleCoordinate(curve, d, x, y) } - Cose.COSE_KEY_TYPE_OKP.toDataItem -> { + Cose.COSE_KEY_TYPE_OKP.toDataItem() -> { val curve = EcCurve.fromInt( coseKey.labels[Cose.COSE_KEY_PARAM_CRV.toCoseLabel]!!.asNumber.toInt() ) diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKeyDoubleCoordinate.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKeyDoubleCoordinate.kt index d959e8379..b778443d9 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKeyDoubleCoordinate.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKeyDoubleCoordinate.kt @@ -23,11 +23,11 @@ data class EcPrivateKeyDoubleCoordinate( override fun toCoseKey(additionalLabels: Map): CoseKey { return CoseKey( mapOf( - Pair(Cose.COSE_KEY_KTY.toCoseLabel, Cose.COSE_KEY_TYPE_EC2.toDataItem), - Pair(Cose.COSE_KEY_PARAM_CRV.toCoseLabel, curve.coseCurveIdentifier.toDataItem), - Pair(Cose.COSE_KEY_PARAM_D.toCoseLabel, d.toDataItem), - Pair(Cose.COSE_KEY_PARAM_X.toCoseLabel, x.toDataItem), - Pair(Cose.COSE_KEY_PARAM_Y.toCoseLabel, y.toDataItem) + Pair(Cose.COSE_KEY_KTY.toCoseLabel, Cose.COSE_KEY_TYPE_EC2.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_CRV.toCoseLabel, curve.coseCurveIdentifier.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_D.toCoseLabel, d.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_X.toCoseLabel, x.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_Y.toCoseLabel, y.toDataItem()) ) + additionalLabels ) } diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKeyOkp.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKeyOkp.kt index 7f85d033c..f6c008f94 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKeyOkp.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPrivateKeyOkp.kt @@ -20,10 +20,10 @@ data class EcPrivateKeyOkp( override fun toCoseKey(additionalLabels: Map): CoseKey { return CoseKey(mapOf( - Pair(Cose.COSE_KEY_KTY.toCoseLabel, Cose.COSE_KEY_TYPE_OKP.toDataItem), - Pair(Cose.COSE_KEY_PARAM_CRV.toCoseLabel, curve.coseCurveIdentifier.toDataItem), - Pair(Cose.COSE_KEY_PARAM_D.toCoseLabel, d.toDataItem), - Pair(Cose.COSE_KEY_PARAM_X.toCoseLabel, x.toDataItem)) + additionalLabels) + Pair(Cose.COSE_KEY_KTY.toCoseLabel, Cose.COSE_KEY_TYPE_OKP.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_CRV.toCoseLabel, curve.coseCurveIdentifier.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_D.toCoseLabel, d.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_X.toCoseLabel, x.toDataItem())) + additionalLabels) } override val publicKey: EcPublicKey diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKey.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKey.kt index 85726e103..0981aaf04 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKey.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKey.kt @@ -36,10 +36,7 @@ sealed class EcPublicKey( @OptIn(ExperimentalEncodingApi::class) fun toPem(): String = Crypto.ecPublicKeyToPem(this) - val toDataItem: DataItem - get() { - return toCoseKey().toDataItem - } + fun toDataItem(): DataItem = toCoseKey().toDataItem() companion object { /** @@ -61,7 +58,7 @@ sealed class EcPublicKey( */ fun fromCoseKey(coseKey: CoseKey): EcPublicKey = when (coseKey.keyType) { - Cose.COSE_KEY_TYPE_EC2.toDataItem -> { + Cose.COSE_KEY_TYPE_EC2.toDataItem() -> { val curve = EcCurve.fromInt( coseKey.labels[Cose.COSE_KEY_PARAM_CRV.toCoseLabel]!!.asNumber.toInt() ) @@ -74,7 +71,7 @@ sealed class EcPublicKey( EcPublicKeyDoubleCoordinate(curve, x, y) } - Cose.COSE_KEY_TYPE_OKP.toDataItem -> { + Cose.COSE_KEY_TYPE_OKP.toDataItem() -> { val curve = EcCurve.fromInt( coseKey.labels[Cose.COSE_KEY_PARAM_CRV.toCoseLabel]!!.asNumber.toInt() ) diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKeyDoubleCoordinate.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKeyDoubleCoordinate.kt index a633be4ce..abd6b1acf 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKeyDoubleCoordinate.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKeyDoubleCoordinate.kt @@ -23,10 +23,10 @@ data class EcPublicKeyDoubleCoordinate( override fun toCoseKey(additionalLabels: Map): CoseKey = CoseKey( mapOf( - Pair(Cose.COSE_KEY_KTY.toCoseLabel, Cose.COSE_KEY_TYPE_EC2.toDataItem), - Pair(Cose.COSE_KEY_PARAM_CRV.toCoseLabel, curve.coseCurveIdentifier.toDataItem), - Pair(Cose.COSE_KEY_PARAM_X.toCoseLabel, x.toDataItem), - Pair(Cose.COSE_KEY_PARAM_Y.toCoseLabel, y.toDataItem) + Pair(Cose.COSE_KEY_KTY.toCoseLabel, Cose.COSE_KEY_TYPE_EC2.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_CRV.toCoseLabel, curve.coseCurveIdentifier.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_X.toCoseLabel, x.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_Y.toCoseLabel, y.toDataItem()) ) + additionalLabels ) diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKeyOkp.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKeyOkp.kt index 7a422dc6f..6f40ea210 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKeyOkp.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcPublicKeyOkp.kt @@ -20,9 +20,9 @@ data class EcPublicKeyOkp( override fun toCoseKey(additionalLabels: Map): CoseKey = CoseKey( mapOf( - Pair(Cose.COSE_KEY_KTY.toCoseLabel, Cose.COSE_KEY_TYPE_OKP.toDataItem), - Pair(Cose.COSE_KEY_PARAM_CRV.toCoseLabel, curve.coseCurveIdentifier.toDataItem), - Pair(Cose.COSE_KEY_PARAM_X.toCoseLabel, x.toDataItem) + Pair(Cose.COSE_KEY_KTY.toCoseLabel, Cose.COSE_KEY_TYPE_OKP.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_CRV.toCoseLabel, curve.coseCurveIdentifier.toDataItem()), + Pair(Cose.COSE_KEY_PARAM_X.toCoseLabel, x.toDataItem()) ) + additionalLabels ) diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcSignature.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcSignature.kt index 5ab3295cb..edad8a695 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/EcSignature.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/EcSignature.kt @@ -15,11 +15,12 @@ data class EcSignature( ) { fun toCoseEncoded() = r + s - val toDataItem: DataItem - get() = CborMap.builder().apply { + fun toDataItem(): DataItem { + return CborMap.builder().apply { put("r", r) put("s", s) }.end().build() + } override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/X509Cert.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/X509Cert.kt index 155b8053f..5053be792 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/X509Cert.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/X509Cert.kt @@ -18,7 +18,7 @@ expect class X509Cert( /** * Gets an [DataItem] with the encoded X.509 certificate. */ - val toDataItem: DataItem + fun toDataItem(): DataItem /** * Encode this certificate in PEM format diff --git a/identity/src/commonMain/kotlin/com/android/identity/crypto/X509CertChain.kt b/identity/src/commonMain/kotlin/com/android/identity/crypto/X509CertChain.kt index 8d250b938..ae9cbd5c3 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/crypto/X509CertChain.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/crypto/X509CertChain.kt @@ -21,16 +21,16 @@ data class X509CertChain( * * Use [fromDataItem] to decode the returned data item. */ - val toDataItem: DataItem - get() = if (certificates.size == 1) { - certificates[0].toDataItem + fun toDataItem(): DataItem { + if (certificates.size == 1) { + return certificates[0].toDataItem() } else { CborArray.builder().run { - certificates.forEach { certificate -> add(certificate.toDataItem) } + certificates.forEach { certificate -> add(certificate.toDataItem()) } return end().build() } - } + } companion object { /** diff --git a/identity/src/commonMain/kotlin/com/android/identity/document/NameSpacedData.kt b/identity/src/commonMain/kotlin/com/android/identity/document/NameSpacedData.kt index cedba8535..778351230 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/document/NameSpacedData.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/document/NameSpacedData.kt @@ -149,19 +149,21 @@ class NameSpacedData private constructor( dataElementName: String ) = Cbor.decode(getDataElement(nameSpaceName, dataElementName)).asBoolean - val toDataItem: DataItem = CborMap.builder().run { - for (namespaceName in map.keys) { - val innerMapBuilder = putMap(namespaceName) - val namespace = map[namespaceName]!! - for ((dataElementName, dataElementValue) in namespace) { - innerMapBuilder.putTagged( - dataElementName, - Tagged.ENCODED_CBOR, - Bstr(dataElementValue) - ) + fun toDataItem(): DataItem { + CborMap.builder().run { + for (namespaceName in map.keys) { + val innerMapBuilder = putMap(namespaceName) + val namespace = map[namespaceName]!! + for ((dataElementName, dataElementValue) in namespace) { + innerMapBuilder.putTagged( + dataElementName, + Tagged.ENCODED_CBOR, + Bstr(dataElementValue) + ) + } } + return end().build() } - end().build() } /** @@ -202,7 +204,7 @@ class NameSpacedData private constructor( * * @return the bytes of the encoding describe above. */ - fun encodeAsCbor() = Cbor.encode(toDataItem) + fun encodeAsCbor() = Cbor.encode(toDataItem()) /** * A builder for [NameSpacedData]. @@ -252,7 +254,7 @@ class NameSpacedData private constructor( nameSpaceName: String, dataElementName: String, value: String - ) = putEntry(nameSpaceName, dataElementName, Cbor.encode(value.toDataItem)) + ) = putEntry(nameSpaceName, dataElementName, Cbor.encode(value.toDataItem())) /** * Encode the given value as `bstr` CBOR and adds it to the builder. @@ -266,7 +268,7 @@ class NameSpacedData private constructor( nameSpaceName: String, dataElementName: String, value: ByteArray - ) = putEntry(nameSpaceName, dataElementName, Cbor.encode(value.toDataItem)) + ) = putEntry(nameSpaceName, dataElementName, Cbor.encode(value.toDataItem())) /** * Encode the given value as an integer or unsigned integer and adds it to the builder. @@ -280,7 +282,7 @@ class NameSpacedData private constructor( nameSpaceName: String, dataElementName: String, value: Long - ) = putEntry(nameSpaceName, dataElementName, Cbor.encode(value.toDataItem)) + ) = putEntry(nameSpaceName, dataElementName, Cbor.encode(value.toDataItem())) /** * Encode the given value as a boolean and adds it to the builder. @@ -294,7 +296,7 @@ class NameSpacedData private constructor( nameSpaceName: String, dataElementName: String, value: Boolean - ) = putEntry(nameSpaceName, dataElementName, Cbor.encode(value.toDataItem)) + ) = putEntry(nameSpaceName, dataElementName, Cbor.encode(value.toDataItem())) /** * Builds a [NameSpacedData] from the builder diff --git a/identity/src/commonMain/kotlin/com/android/identity/securearea/software/SoftwareSecureArea.kt b/identity/src/commonMain/kotlin/com/android/identity/securearea/software/SoftwareSecureArea.kt index 4b65e2e7b..e7de2739e 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/securearea/software/SoftwareSecureArea.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/securearea/software/SoftwareSecureArea.kt @@ -75,14 +75,14 @@ class SoftwareSecureArea(private val storageEngine: StorageEngine) : SecureArea } if (!settings.passphraseRequired) { - mapBuilder.put("privateKey", privateKey.toCoseKey().toDataItem) + mapBuilder.put("privateKey", privateKey.toCoseKey().toDataItem()) } else { - val encodedPublicKey = Cbor.encode(privateKey.publicKey.toCoseKey().toDataItem) + val encodedPublicKey = Cbor.encode(privateKey.publicKey.toCoseKey().toDataItem()) val secretKey = derivePrivateKeyEncryptionKey( encodedPublicKey, settings.passphrase!! ) - val cleartextPrivateKey = Cbor.encode(privateKey.toCoseKey().toDataItem) + val cleartextPrivateKey = Cbor.encode(privateKey.toCoseKey().toDataItem()) val iv = Random.Default.nextBytes(12) val encryptedPrivateKey = Crypto.encrypt( Algorithm.A128GCM, @@ -96,9 +96,9 @@ class SoftwareSecureArea(private val storageEngine: StorageEngine) : SecureArea put("encryptedPrivateKeyIv", iv) } } - mapBuilder.put("publicKey", privateKey.publicKey.toCoseKey().toDataItem) + mapBuilder.put("publicKey", privateKey.publicKey.toCoseKey().toDataItem()) if (settings.passphraseConstraints != null) { - mapBuilder.put("passphraseConstraints", settings.passphraseConstraints.toDataItem) + mapBuilder.put("passphraseConstraints", settings.passphraseConstraints.toDataItem()) } storageEngine.put(PREFIX + alias, Cbor.encode(mapBuilder.end().build())) } catch (e: Exception) { diff --git a/identity/src/commonMain/kotlin/com/android/identity/util/Base64Util.kt b/identity/src/commonMain/kotlin/com/android/identity/util/Base64Util.kt index 45af57907..ccadc55fc 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/util/Base64Util.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/util/Base64Util.kt @@ -7,12 +7,10 @@ import kotlin.io.encoding.ExperimentalEncodingApi * Extension to encode a [ByteArray] to a base64 encoded string. */ @OptIn(ExperimentalEncodingApi::class) -val ByteArray.toBase64: String - get() = Base64.UrlSafe.encode(this).trimEnd('=') +fun ByteArray.toBase64(): String = Base64.UrlSafe.encode(this).trimEnd('=') /** * Extension to decode a [ByteArray] from a base64 encoded string. */ @OptIn(ExperimentalEncodingApi::class) -val String.fromBase64: ByteArray - get() = Base64.UrlSafe.decode(this) +fun String.fromBase64(): ByteArray = Base64.UrlSafe.decode(this) diff --git a/identity/src/commonMain/kotlin/com/android/identity/util/HexUtil.kt b/identity/src/commonMain/kotlin/com/android/identity/util/HexUtil.kt index c508a177f..1f4d1516c 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/util/HexUtil.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/util/HexUtil.kt @@ -48,11 +48,9 @@ object HexUtil { /** * Extension to encode a [ByteArray] to a string with hexadecimal numbers. */ -val ByteArray.toHex: String - get() = HexUtil.toHex(this) +fun ByteArray.toHex(): String = HexUtil.toHex(this) /** * Extension to decode a [ByteArray] from a string with hexadecimal numbers. */ -val String.fromHex: ByteArray - get() = HexUtil.fromHex(this) +fun String.fromHex(): ByteArray = HexUtil.fromHex(this) diff --git a/identity/src/commonMain/kotlin/com/android/identity/util/Logger.kt b/identity/src/commonMain/kotlin/com/android/identity/util/Logger.kt index ebeddb0f2..df1fe7b26 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/util/Logger.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/util/Logger.kt @@ -170,7 +170,7 @@ object Logger { } private fun hex(level: Int, tag: String, message: String, data: ByteArray) { - val sb = "$message: ${data.size} bytes of data: " + data.toHex + val sb = "$message: ${data.size} bytes of data: " + data.toHex() println(level, tag, sb, null) } @@ -193,7 +193,7 @@ object Logger { } private fun cbor(level: Int, tag: String, message: String, encodedCbor: ByteArray) { - val sb = "$message: ${encodedCbor.size} bytes of CBOR: " + encodedCbor.toHex + + val sb = "$message: ${encodedCbor.size} bytes of CBOR: " + encodedCbor.toHex() + "\n" + "In diagnostic notation:\n" + Cbor.toDiagnostics( diff --git a/identity/src/commonMain/kotlin/com/android/identity/util/SimpleApplicationData.kt b/identity/src/commonMain/kotlin/com/android/identity/util/SimpleApplicationData.kt index f81548dd0..67d77c6d4 100644 --- a/identity/src/commonMain/kotlin/com/android/identity/util/SimpleApplicationData.kt +++ b/identity/src/commonMain/kotlin/com/android/identity/util/SimpleApplicationData.kt @@ -43,13 +43,13 @@ class SimpleApplicationData(private val onDataChanged: (key: String) -> Unit) : } override fun setString(key: String, value: String): ApplicationData = - setData(key, Cbor.encode(value.toDataItem)) + setData(key, Cbor.encode(value.toDataItem())) override fun setNumber(key: String, value: Long): ApplicationData = - setData(key, Cbor.encode(value.toDataItem)) + setData(key, Cbor.encode(value.toDataItem())) override fun setBoolean(key: String, value: Boolean): ApplicationData = - setData(key, Cbor.encode(value.toDataItem)) + setData(key, Cbor.encode(value.toDataItem())) override fun setNameSpacedData(key: String, value: NameSpacedData): ApplicationData = setData(key, value.encodeAsCbor()) diff --git a/identity/src/commonTest/kotlin/com/android/identity/cbor/CborTests.kt b/identity/src/commonTest/kotlin/com/android/identity/cbor/CborTests.kt index da65c8f70..47c9b3866 100644 --- a/identity/src/commonTest/kotlin/com/android/identity/cbor/CborTests.kt +++ b/identity/src/commonTest/kotlin/com/android/identity/cbor/CborTests.kt @@ -15,17 +15,17 @@ class CborTests { ) private fun encodeNumber(value: Long) = Cbor.toDiagnostics( - Cbor.encode(value.toDataItem), + Cbor.encode(value.toDataItem()), setOf(DiagnosticOption.EMBEDDED_CBOR, DiagnosticOption.PRETTY_PRINT) ) private fun encodeFloat(value: Float) = Cbor.toDiagnostics( - Cbor.encode(value.toDataItem), + Cbor.encode(value.toDataItem()), setOf(DiagnosticOption.EMBEDDED_CBOR, DiagnosticOption.PRETTY_PRINT) ) private fun encodeDouble(value: Double) = Cbor.toDiagnostics( - Cbor.encode(value.toDataItem), + Cbor.encode(value.toDataItem()), setOf(DiagnosticOption.EMBEDDED_CBOR, DiagnosticOption.PRETTY_PRINT) ) @@ -353,9 +353,9 @@ class CborTests { ) ) ) - .add(RawCbor(Cbor.encode("some tstr".toDataItem))) + .add(RawCbor(Cbor.encode("some tstr".toDataItem()))) .add("Sprinkled in item") - .add(RawCbor(Cbor.encode(42.toDataItem))) + .add(RawCbor(Cbor.encode(42.toDataItem()))) .end() .build() ) @@ -382,7 +382,7 @@ class CborTests { fun indefiniteLengthArray() { assertEquals( "[_ \"foo\", \"bar\"]", - cborToString(CborArray(mutableListOf("foo".toDataItem, "bar".toDataItem), true)) + cborToString(CborArray(mutableListOf("foo".toDataItem(), "bar".toDataItem()), true)) ) } @@ -396,8 +396,8 @@ class CborTests { cborToString( CborMap( mutableMapOf( - Pair("foo".toDataItem, "fooVal".toDataItem), - Pair("bar".toDataItem, "barVar".toDataItem) + Pair("foo".toDataItem(), "fooVal".toDataItem()), + Pair("bar".toDataItem(), "barVar".toDataItem()) ), true ) @@ -406,7 +406,7 @@ class CborTests { } private fun encodeAndDecodeNumber(value: Long): String { - val encodedData = Cbor.encode(value.toDataItem) + val encodedData = Cbor.encode(value.toDataItem()) return cborToString(Cbor.decode(encodedData)) } @@ -418,30 +418,30 @@ class CborTests { @Test fun decodeBasic() { - assertEncodeDecode("tstr".toDataItem) - assertEncodeDecode(byteArrayOf(1, 2, 3).toDataItem) - assertEncodeDecode(42.toDataItem) - assertEncodeDecode((-42).toDataItem) - assertEncodeDecode(true.toDataItem) - assertEncodeDecode(false.toDataItem) + assertEncodeDecode("tstr".toDataItem()) + assertEncodeDecode(byteArrayOf(1, 2, 3).toDataItem()) + assertEncodeDecode(42.toDataItem()) + assertEncodeDecode((-42).toDataItem()) + assertEncodeDecode(true.toDataItem()) + assertEncodeDecode(false.toDataItem()) assertEncodeDecode(Simple.NULL) assertEncodeDecode(Simple.UNDEFINED) - assertEncodeDecode(0.0.toDataItem) - assertEncodeDecode(42.0.toDataItem) - assertEncodeDecode((-42.1).toDataItem) - assertEncodeDecode(Double.MIN_VALUE.toDataItem) - assertEncodeDecode(Double.MAX_VALUE.toDataItem) - assertEncodeDecode(Double.NaN.toDataItem) - assertEncodeDecode(Double.NEGATIVE_INFINITY.toDataItem) - assertEncodeDecode(Double.POSITIVE_INFINITY.toDataItem) - assertEncodeDecode(0.0f.toDataItem) - assertEncodeDecode(42.0f.toDataItem) - assertEncodeDecode((-42.1f).toDataItem) - assertEncodeDecode(Float.MIN_VALUE.toDataItem) - assertEncodeDecode(Float.MAX_VALUE.toDataItem) - assertEncodeDecode(Float.NaN.toDataItem) - assertEncodeDecode(Float.NEGATIVE_INFINITY.toDataItem) - assertEncodeDecode(Float.POSITIVE_INFINITY.toDataItem) + assertEncodeDecode(0.0.toDataItem()) + assertEncodeDecode(42.0.toDataItem()) + assertEncodeDecode((-42.1).toDataItem()) + assertEncodeDecode(Double.MIN_VALUE.toDataItem()) + assertEncodeDecode(Double.MAX_VALUE.toDataItem()) + assertEncodeDecode(Double.NaN.toDataItem()) + assertEncodeDecode(Double.NEGATIVE_INFINITY.toDataItem()) + assertEncodeDecode(Double.POSITIVE_INFINITY.toDataItem()) + assertEncodeDecode(0.0f.toDataItem()) + assertEncodeDecode(42.0f.toDataItem()) + assertEncodeDecode((-42.1f).toDataItem()) + assertEncodeDecode(Float.MIN_VALUE.toDataItem()) + assertEncodeDecode(Float.MAX_VALUE.toDataItem()) + assertEncodeDecode(Float.NaN.toDataItem()) + assertEncodeDecode(Float.NEGATIVE_INFINITY.toDataItem()) + assertEncodeDecode(Float.POSITIVE_INFINITY.toDataItem()) } @Test @@ -712,7 +712,7 @@ class CborTests { @Test fun diagnosticsVectors() { for (testVector in diagnosticsTestVectors) { - val encodedCbor = testVector.hexEncoding.fromHex + val encodedCbor = testVector.hexEncoding.fromHex() assertEquals(testVector.expectedDiagnostics, Cbor.toDiagnostics(encodedCbor)) } } @@ -776,7 +776,7 @@ class CborTests { @Test fun nonWellformedThrowsWhenDecoding() { for (hexEncodedData in nonWellformedExamples) { - val data = hexEncodedData.replace(" ", "").fromHex + val data = hexEncodedData.replace(" ", "").fromHex() assertFailsWith(IllegalArgumentException::class) { Cbor.decode(data) } @@ -787,27 +787,27 @@ class CborTests { @Test fun parseHelperBasic() { - assertContentEquals(byteArrayOf(1, 42), byteArrayOf(1, 42).toDataItem.asBstr) - assertEquals("Tstr", "Tstr".toDataItem.asTstr) - assertEquals(42, 42.toDataItem.asNumber) - assertEquals(-35, (-35).toDataItem.asNumber) - assertEquals(42.0, 42.0.toDataItem.asDouble, 0.01) - assertEquals(43.0f, 43.0f.toDataItem.asFloat, 0.01f) - assertEquals(true, true.toDataItem.asBoolean) - assertEquals(false, false.toDataItem.asBoolean) + assertContentEquals(byteArrayOf(1, 42), byteArrayOf(1, 42).toDataItem().asBstr) + assertEquals("Tstr", "Tstr".toDataItem().asTstr) + assertEquals(42, 42.toDataItem().asNumber) + assertEquals(-35, (-35).toDataItem().asNumber) + assertEquals(42.0, 42.0.toDataItem().asDouble, 0.01) + assertEquals(43.0f, 43.0f.toDataItem().asFloat, 0.01f) + assertEquals(true, true.toDataItem().asBoolean) + assertEquals(false, false.toDataItem().asBoolean) - assertFailsWith(IllegalArgumentException::class) { 42.toDataItem.asBstr } - assertFailsWith(IllegalArgumentException::class) { 42.toDataItem.asTstr } - assertFailsWith(IllegalArgumentException::class) { 4.0.toDataItem.asNumber } - assertFailsWith(IllegalArgumentException::class) { 42.toDataItem.asDouble } - assertFailsWith(IllegalArgumentException::class) { 42.toDataItem.asFloat } - assertFailsWith(IllegalArgumentException::class) { 42.toDataItem.asBoolean } + assertFailsWith(IllegalArgumentException::class) { 42.toDataItem().asBstr } + assertFailsWith(IllegalArgumentException::class) { 42.toDataItem().asTstr } + assertFailsWith(IllegalArgumentException::class) { 4.0.toDataItem().asNumber } + assertFailsWith(IllegalArgumentException::class) { 42.toDataItem().asDouble } + assertFailsWith(IllegalArgumentException::class) { 42.toDataItem().asFloat } + assertFailsWith(IllegalArgumentException::class) { 42.toDataItem().asBoolean } } @Test fun parseHelperMap() { val map = CborMap.builder() - .put("foo0", "Tstr".toDataItem) + .put("foo0", "Tstr".toDataItem()) .put("foo1", byteArrayOf(1, 2, 3)) .put("foo2", 42) .put("foo3", -35) @@ -875,7 +875,7 @@ class CborTests { @Test fun parseHelperArray() { val array = CborArray.builder() - .add("Tstr".toDataItem) + .add("Tstr".toDataItem()) .add(byteArrayOf(1, 2, 3)) .add(42) .add(-35) @@ -905,7 +905,7 @@ class CborTests { @Test fun mapLookupException() { val map = CborMap.builder() - .put("foo0", "Tstr".toDataItem) + .put("foo0", "Tstr".toDataItem()) .end().build() assertEquals("Tstr", map["foo0"].asTstr) assertFailsWith(IllegalStateException::class) { map["foo1"] } @@ -914,26 +914,26 @@ class CborTests { @Test fun mapGetOrDefault() { val map = CborMap.builder() - .put("foo0", "Tstr".toDataItem) + .put("foo0", "Tstr".toDataItem()) .end().build() - assertEquals("Tstr", map.getOrDefault("foo0", "dTstr".toDataItem).asTstr) - assertEquals("dTstr", map.getOrDefault("foo1", "dTstr".toDataItem).asTstr) + assertEquals("Tstr", map.getOrDefault("foo0", "dTstr".toDataItem()).asTstr) + assertEquals("dTstr", map.getOrDefault("foo1", "dTstr".toDataItem()).asTstr) } @Test fun mapGetOrNull() { val map = CborMap.builder() - .put("foo0", "Tstr".toDataItem) + .put("foo0", "Tstr".toDataItem()) .end().build() - assertEquals("Tstr".toDataItem, map.getOrNull("foo0")) + assertEquals("Tstr".toDataItem(), map.getOrNull("foo0")) assertEquals(null, map.getOrNull("foo1")) } @Test fun arrayLookupException() { val array = CborArray.builder() - .add("Tstr".toDataItem) - .add("OtherTstr".toDataItem) + .add("Tstr".toDataItem()) + .add("OtherTstr".toDataItem()) .end().build() assertEquals("Tstr", array[0].asTstr) assertEquals("OtherTstr", array[1].asTstr) @@ -955,10 +955,10 @@ class CborTests { fun toDateTimeString() { assertEquals( "0(\"1970-01-01T00:00:00Z\")", - Cbor.toDiagnostics(Instant.fromEpochMilliseconds(0).toDataItemDateTimeString)) + Cbor.toDiagnostics(Instant.fromEpochMilliseconds(0).toDataItemDateTimeString())) assertEquals( "0(\"2001-09-09T01:46:40Z\")", - Cbor.toDiagnostics(Instant.fromEpochMilliseconds(1000000000000).toDataItemDateTimeString)) + Cbor.toDiagnostics(Instant.fromEpochMilliseconds(1000000000000).toDataItemDateTimeString())) } } \ No newline at end of file diff --git a/identity/src/commonTest/kotlin/com/android/identity/cose/CoseTests.kt b/identity/src/commonTest/kotlin/com/android/identity/cose/CoseTests.kt index c38ec686a..e8e79896a 100644 --- a/identity/src/commonTest/kotlin/com/android/identity/cose/CoseTests.kt +++ b/identity/src/commonTest/kotlin/com/android/identity/cose/CoseTests.kt @@ -27,8 +27,8 @@ class CoseTests { // // https://datatracker.ietf.org/doc/html/rfc9052#name-public-keys // - val x = "65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d".fromHex - val y = "1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c".fromHex + val x = "65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d".fromHex() + val y = "1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c".fromHex() val id = "meriadoc.brandybuck@buckland.example".encodeToByteArray() val item = CborMap.builder() .put(-1, 1) @@ -85,8 +85,8 @@ class CoseTests { // // https://datatracker.ietf.org/doc/html/rfc9052#name-public-keys // - val x = "bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a09eff".fromHex - val y = "20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbfc117e".fromHex + val x = "bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a09eff".fromHex() + val y = "20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbfc117e".fromHex() val coseKey = CborMap.builder() .put(-1, 1) .put(-2, x) @@ -96,14 +96,14 @@ class CoseTests { val coseSign1 = CoseSign1( mutableMapOf( - Pair(1L.toCoseLabel, (-7).toDataItem) + Pair(1L.toCoseLabel, (-7).toDataItem()) ), mutableMapOf( - Pair(11L.toCoseLabel, byteArrayOf(1, 1).toDataItem) + Pair(11L.toCoseLabel, byteArrayOf(1, 1).toDataItem()) ), ("8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4" + "d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5" + - "a4c345cacb36").fromHex, + "a4c345cacb36").fromHex(), "This is the content.".encodeToByteArray() ) @@ -130,7 +130,7 @@ class CoseTests { val protectedHeaders = mapOf( Pair( Cose.COSE_LABEL_ALG.toCoseLabel, - signatureAlgorithm.coseAlgorithmIdentifier.toDataItem + signatureAlgorithm.coseAlgorithmIdentifier.toDataItem() ) ) val message = "Hello World".encodeToByteArray() diff --git a/identity/src/commonTest/kotlin/com/android/identity/crypto/CryptoTests.kt b/identity/src/commonTest/kotlin/com/android/identity/crypto/CryptoTests.kt index 5910a2dc9..d4fbaece3 100644 --- a/identity/src/commonTest/kotlin/com/android/identity/crypto/CryptoTests.kt +++ b/identity/src/commonTest/kotlin/com/android/identity/crypto/CryptoTests.kt @@ -14,19 +14,19 @@ class CryptoTests { fun digests() { assertEquals( "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - Crypto.digest(Algorithm.SHA256, "".encodeToByteArray()).toHex + Crypto.digest(Algorithm.SHA256, "".encodeToByteArray()).toHex() ) assertEquals( "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e", - Crypto.digest(Algorithm.SHA256, "Hello World".encodeToByteArray()).toHex + Crypto.digest(Algorithm.SHA256, "Hello World".encodeToByteArray()).toHex() ) assertEquals( "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b", - Crypto.digest(Algorithm.SHA384, "".encodeToByteArray()).toHex + Crypto.digest(Algorithm.SHA384, "".encodeToByteArray()).toHex() ) assertEquals( "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", - Crypto.digest(Algorithm.SHA512, "".encodeToByteArray()).toHex + Crypto.digest(Algorithm.SHA512, "".encodeToByteArray()).toHex() ) } @@ -42,9 +42,9 @@ class CryptoTests { "769f00d3e6a6cc1fb426a14a4f76c6462e6149726e0dee0ec0cf97a16605ac8b", Crypto.mac( Algorithm.HMAC_SHA256, - "9779d9120642797f1747025d5b22b7ac607cab08e1758f2f3a46c8be1e25c53b8c6a8f58ffefa176".fromHex, - "b1689c2591eaf3c9e66070f8a77954ffb81749f1b00346f9dfe0b2ee905dcc288baf4a92de3f4001dd9f44c468c3d07d6c6ee82faceafc97c2fc0fc0601719d2dcd0aa2aec92d1b0ae933c65eb06a03c9c935c2bad0459810241347ab87e9f11adb30415424c6c7f5f22a003b8ab8de54f6ded0e3ab9245fa79568451dfa258e".fromHex - ).toHex + "9779d9120642797f1747025d5b22b7ac607cab08e1758f2f3a46c8be1e25c53b8c6a8f58ffefa176".fromHex(), + "b1689c2591eaf3c9e66070f8a77954ffb81749f1b00346f9dfe0b2ee905dcc288baf4a92de3f4001dd9f44c468c3d07d6c6ee82faceafc97c2fc0fc0601719d2dcd0aa2aec92d1b0ae933c65eb06a03c9c935c2bad0459810241347ab87e9f11adb30415424c6c7f5f22a003b8ab8de54f6ded0e3ab9245fa79568451dfa258e".fromHex() + ).toHex() ) // First item with L=48 and T=48 @@ -52,9 +52,9 @@ class CryptoTests { "7cf5a06156ad3de5405a5d261de90275f9bb36de45667f84d08fbcb308ca8f53a419b07deab3b5f8ea231c5b036f8875", Crypto.mac( Algorithm.HMAC_SHA384, - "5eab0dfa27311260d7bddcf77112b23d8b42eb7a5d72a5a318e1ba7e7927f0079dbb701317b87a3340e156dbcee28ec3a8d9".fromHex, - "f41380123ccbec4c527b425652641191e90a17d45e2f6206cf01b5edbe932d41cc8a2405c3195617da2f420535eed422ac6040d9cd65314224f023f3ba730d19db9844c71c329c8d9d73d04d8c5f244aea80488292dc803e772402e72d2e9f1baba5a6004f0006d822b0b2d65e9e4a302dd4f776b47a972250051a701fab2b70".fromHex - ).toHex + "5eab0dfa27311260d7bddcf77112b23d8b42eb7a5d72a5a318e1ba7e7927f0079dbb701317b87a3340e156dbcee28ec3a8d9".fromHex(), + "f41380123ccbec4c527b425652641191e90a17d45e2f6206cf01b5edbe932d41cc8a2405c3195617da2f420535eed422ac6040d9cd65314224f023f3ba730d19db9844c71c329c8d9d73d04d8c5f244aea80488292dc803e772402e72d2e9f1baba5a6004f0006d822b0b2d65e9e4a302dd4f776b47a972250051a701fab2b70".fromHex() + ).toHex() ) // First item with L=64 and T=64 @@ -62,9 +62,9 @@ class CryptoTests { "33c511e9bc2307c62758df61125a980ee64cefebd90931cb91c13742d4714c06de4003faf3c41c06aefc638ad47b21906e6b104816b72de6269e045a1f4429d4", Crypto.mac( Algorithm.HMAC_SHA512, - "57c2eb677b5093b9e829ea4babb50bde55d0ad59fec34a618973802b2ad9b78e26b2045dda784df3ff90ae0f2cc51ce39cf54867320ac6f3ba2c6f0d72360480c96614ae66581f266c35fb79fd28774afd113fa5187eff9206d7cbe90dd8bf67c844e202".fromHex, - "2423dff48b312be864cb3490641f793d2b9fb68a7763b8e298c86f42245e4540eb01ae4d2d4500370b1886f23ca2cf9701704cad5bd21ba87b811daf7a854ea24a56565ced425b35e40e1acbebe03603e35dcf4a100e57218408a1d8dbcc3b99296cfea931efe3ebd8f719a6d9a15487b9ad67eafedf15559ca42445b0f9b42e".fromHex - ).toHex + "57c2eb677b5093b9e829ea4babb50bde55d0ad59fec34a618973802b2ad9b78e26b2045dda784df3ff90ae0f2cc51ce39cf54867320ac6f3ba2c6f0d72360480c96614ae66581f266c35fb79fd28774afd113fa5187eff9206d7cbe90dd8bf67c844e202".fromHex(), + "2423dff48b312be864cb3490641f793d2b9fb68a7763b8e298c86f42245e4540eb01ae4d2d4500370b1886f23ca2cf9701704cad5bd21ba87b811daf7a854ea24a56565ced425b35e40e1acbebe03603e35dcf4a100e57218408a1d8dbcc3b99296cfea931efe3ebd8f719a6d9a15487b9ad67eafedf15559ca42445b0f9b42e".fromHex() + ).toHex() ) } @@ -78,30 +78,30 @@ class CryptoTests { "2ccda4a5415cb91e135c2a0f78c9b2fd" + "b36d1df9b9d5e596f83e8b7f52971cb3", Crypto.encrypt( Algorithm.A128GCM, - "7fddb57453c241d03efbed3ac44e371c".fromHex, - "ee283a3fc75575e33efd4887".fromHex, - "d5de42b461646c255c87bd2962d3b9a2".fromHex, - ).toHex + "7fddb57453c241d03efbed3ac44e371c".fromHex(), + "ee283a3fc75575e33efd4887".fromHex(), + "d5de42b461646c255c87bd2962d3b9a2".fromHex(), + ).toHex() ) assertEquals( "69482957e6be5c54882d00314e0259cf" + "191e9f29bef63a26860c1e020a21137e", Crypto.encrypt( Algorithm.A192GCM, - "fbc0b4c56a714c83217b2d1bcadd2ed2e9efb0dcac6cc19f".fromHex, - "5f4b43e811da9c470d6a9b01".fromHex, - "d2ae38c4375954835d75b8e4c2f9bbb4".fromHex, - ).toHex + "fbc0b4c56a714c83217b2d1bcadd2ed2e9efb0dcac6cc19f".fromHex(), + "5f4b43e811da9c470d6a9b01".fromHex(), + "d2ae38c4375954835d75b8e4c2f9bbb4".fromHex(), + ).toHex() ) assertEquals( "fa4362189661d163fcd6a56d8bf0405a" + "d636ac1bbedd5cc3ee727dc2ab4a9489", Crypto.encrypt( Algorithm.A256GCM, - "31bdadd96698c204aa9ce1448ea94ae1fb4a9a0b3c9d773b51bb1822666b8f22".fromHex, - "0d18e06c7c725ac9e362e1ce".fromHex, - "2db5168e932556f8089a0622981d017d".fromHex, - ).toHex + "31bdadd96698c204aa9ce1448ea94ae1fb4a9a0b3c9d773b51bb1822666b8f22".fromHex(), + "0d18e06c7c725ac9e362e1ce".fromHex(), + "2db5168e932556f8089a0622981d017d".fromHex(), + ).toHex() ) } @@ -115,37 +115,37 @@ class CryptoTests { "28286a321293253c3e0aa2704a278032", Crypto.decrypt( Algorithm.A128GCM, - "e98b72a9881a84ca6b76e0f43e68647a".fromHex, - "8b23299fde174053f3d652ba".fromHex, - ("5a3c1cf1985dbb8bed818036fdd5ab42" + "23c7ab0f952b7091cd324835043b5eb5").fromHex, - ).toHex + "e98b72a9881a84ca6b76e0f43e68647a".fromHex(), + "8b23299fde174053f3d652ba".fromHex(), + ("5a3c1cf1985dbb8bed818036fdd5ab42" + "23c7ab0f952b7091cd324835043b5eb5").fromHex(), + ).toHex() ) assertEquals( "99ae6f479b3004354ff18cd86c0b6efb", Crypto.decrypt( Algorithm.A192GCM, - "7a7c5b6a8a9ab5acae34a9f6e41f19a971f9c330023c0f0c".fromHex, - "aa4c38bf587f94f99fee77d5".fromHex, - ("132ae95bd359c44aaefa6348632cafbd" + "19d7c7d5809ad6648110f22f272e7d72").fromHex, - ).toHex + "7a7c5b6a8a9ab5acae34a9f6e41f19a971f9c330023c0f0c".fromHex(), + "aa4c38bf587f94f99fee77d5".fromHex(), + ("132ae95bd359c44aaefa6348632cafbd" + "19d7c7d5809ad6648110f22f272e7d72").fromHex(), + ).toHex() ) assertEquals( "7789b41cb3ee548814ca0b388c10b343", Crypto.decrypt( Algorithm.A256GCM, - "4c8ebfe1444ec1b2d503c6986659af2c94fafe945f72c1e8486a5acfedb8a0f8".fromHex, - "473360e0ad24889959858995".fromHex, - ("d2c78110ac7e8f107c0df0570bd7c90c" + "c26a379b6d98ef2852ead8ce83a833a7").fromHex, - ).toHex + "4c8ebfe1444ec1b2d503c6986659af2c94fafe945f72c1e8486a5acfedb8a0f8".fromHex(), + "473360e0ad24889959858995".fromHex(), + ("d2c78110ac7e8f107c0df0570bd7c90c" + "c26a379b6d98ef2852ead8ce83a833a7").fromHex(), + ).toHex() ) } @Test fun encryptDecrypt() { - val key = "00000000000000000000000000000000".fromHex - val nonce = "000000000000000000000000".fromHex + val key = "00000000000000000000000000000000".fromHex() + val nonce = "000000000000000000000000".fromHex() val message = "Hello World".encodeToByteArray() val ciptherTextAndTag = Crypto.encrypt(Algorithm.A128GCM, key, nonce, message) val decryptedMessage = Crypto.decrypt(Algorithm.A128GCM, key, nonce, ciptherTextAndTag) @@ -154,8 +154,8 @@ class CryptoTests { @Test fun decryptionFailure() { - val key = "00000000000000000000000000000000".fromHex - val nonce = "000000000000000000000000".fromHex + val key = "00000000000000000000000000000000".fromHex() + val nonce = "000000000000000000000000".fromHex() val message = "Hello World".encodeToByteArray() val ciptherTextAndTag = Crypto.encrypt(Algorithm.A128GCM, key, nonce, message) // Tamper with the cipher text to induce failure. @@ -172,11 +172,11 @@ class CryptoTests { "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", Crypto.hkdf( Algorithm.HMAC_SHA256, - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b".fromHex, - "000102030405060708090a0b0c".fromHex, - "f0f1f2f3f4f5f6f7f8f9".fromHex, + "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b".fromHex(), + "000102030405060708090a0b0c".fromHex(), + "f0f1f2f3f4f5f6f7f8f9".fromHex(), 42 - ).toHex + ).toHex() ) } diff --git a/identity/src/commonTest/kotlin/com/android/identity/crypto/X509CertTests.kt b/identity/src/commonTest/kotlin/com/android/identity/crypto/X509CertTests.kt index 6577ebe53..85a1d54f7 100644 --- a/identity/src/commonTest/kotlin/com/android/identity/crypto/X509CertTests.kt +++ b/identity/src/commonTest/kotlin/com/android/identity/crypto/X509CertTests.kt @@ -14,11 +14,11 @@ class X509CertTests { // private val androidKeyCertChain = X509CertChain( listOf( - "308202ce30820273a003020102020101300a06082a8648ce3d040302303931293027060355040313203037653832313634373436306364383232663631363063383565386138616261310c300a060355040a1303544545301e170d3234303631383032313533335a170d3234303731383032313533335a301f311d301b06035504031314416e64726f6964204b657973746f7265204b65793059301306072a8648ce3d020106082a8648ce3d03010703420004ac858c2a816562929c5c69bfd64aacaf7c2e84c0db4f0b71a6a1dd153a72265c1b91fb8608e39bedf168a56634966b6fd4c140796397ce3171e50c8a5a30ebc6a382018430820180300e0603551d0f0101ff0404030207803082016c060a2b06010401d6790201110482015c308201580202012c0a01010202012c0a010104094368616c6c656e6765040030818ebf831008020601902920cc83bf83110802060190c39f9483bf83120802060190c39f9483bf853d08020601902920cca4bf85455a045830563130302e0429636f6d2e616e64726f69642e6964656e746974792e7365637572655f617265615f746573745f61707002010131220420e180e58c9e4bfb40d5e68e528be1a668e70361537528b8eda19bf900863f11223081a9a1053103020102a203020103a30402020100a5053103020104aa03020101bf837803020103bf83790302010abf853e03020100bf85404c304a042000000000000000000000000000000000000000000000000000000000000000000101000a01020420c95b9d89c2adc6bed35d630cfb43e8f514a99e521a0944348009e6651d7c5414bf85410502030222e0bf8542050203031647bf854e0602040134b3c1bf854f0602040134b3c1300a06082a8648ce3d0403020349003046022100bb9878eabc1ea4bbf095d77aba6ebb93ea24988f3bdbc87b2894be22aa905767022100a1f10252af737d4d836b6a222422f0e037b23efbea3bed882ef7db8ebd16ac68".fromHex, - "308201d63082017ca003020102021007e821647460cd822f6160c85e8a8aba300a06082a8648ce3d040302302931133011060355040a130a476f6f676c65204c4c43311230100603550403130944726f696420434133301e170d3234303532333233323432305a170d3234303632303233323432305a303931293027060355040313203037653832313634373436306364383232663631363063383565386138616261310c300a060355040a13035445453059301306072a8648ce3d020106082a8648ce3d0301070342000402a3dd51ea8533eda9abad1b4dd4df5674abb01c839a21c7918f85d89eb77aaa3d570e522ba79ba40d26e21db20bf5a955c789711a9e1788b4592ea14c5487f8a3763074301d0603551d0e0416041421136b05cef61befcd0cd43dc8b15df83b6d3e5c301f0603551d230418301680141cc2bd40dba29c4bdc06a6a10d4694ffb2f5c02a300f0603551d130101ff040530030101ff300e0603551d0f0101ff0404030202043011060a2b06010401d67902011e0403a10110300a06082a8648ce3d0403020348003045022100e5c42005468e145cf200c4ba618351ee297fe9af5e228b258a57b7b45e29d9a702204ee2b68c0754019e743d60c0b013d62fc5914c4ac6088c04b484c27e74e0751b".fromHex, - "308201d63082015ca0030201020213408ad01b2be2d94e2ffdd454b3cb87bba93cd9300a06082a8648ce3d040303302931133011060355040a130a476f6f676c65204c4c43311230100603550403130944726f696420434132301e170d3234303532353230343535395a170d3234303731343230343535385a302931133011060355040a130a476f6f676c65204c4c43311230100603550403130944726f6964204341333059301306072a8648ce3d020106082a8648ce3d03010703420004b893145670be40c9d352400297edef3bc9a1fea89d0b4fb0226eb4363aa2cdf8b47cc5b8ce77036389ba4a1bf257fefc0fa40f667598393dab429cc032f2d9cea3633061300e0603551d0f0101ff040403020204300f0603551d130101ff040530030101ff301d0603551d0e041604141cc2bd40dba29c4bdc06a6a10d4694ffb2f5c02a301f0603551d23041830168014bbf836ad89ae6ce2e59e94f0d5b2d7d27ae47c41300a06082a8648ce3d040303036800306502305c2c09ba5a4320deb6c27f1d7adbfef8592fc5cbb9da4a3c551268d2798ba027f27e30f41fab084c29271ad27cf16ad60231009e6031b2fcfcc424234a36b3ec60153374c46d65a5e20191f7394f08f466d3fe36f896a9d24a00350059082b9eb2c525".fromHex, - "3082038030820168a003020102020a0388266760658996860d300d06092a864886f70d01010b0500301b311930170603550405131066393230303965383533623662303435301e170d3232303132363232343735325a170d3337303132323232343735325a302931133011060355040a130a476f6f676c65204c4c43311230100603550403130944726f6964204341323076301006072a8648ce3d020106052b8104002203620004ba9a716d9bc98303575deeaa40a89d5ea52dd68a13f0ce90fb2b16230a5db8cd846a5493f2ffc2cb624dd746aa4df5124e12616bfa02b46f85f53514be239c87a45a86ba6357205d868a4cf4c1439427e488290f08f1aed8e0cc8fb3bf6ca9e4a3663064301d0603551d0e04160414bbf836ad89ae6ce2e59e94f0d5b2d7d27ae47c41301f0603551d230418301680143661e1007c880509518b446c47ff1a4cc9ea4f1230120603551d130101ff040830060101ff020102300e0603551d0f0101ff040403020106300d06092a864886f70d01010b05000382020100817152214761f39baab24cd1e79723e919153e7bc01a6586af9312377eefc9c859b2af28650596fb7b22e5c7cd9ed825db520ecee516d0acc5776b58498b724c510c245cb61dc46f595e15eb294b7e4d00e7741de920f2fcb61b7d4e5807b9ebb97a35d2e3ab2b6e91c178280cc7211c68162bcdfad9641099a0ec4430f43db03eae0aa41b6e838a09139dd1f5b2c24f9c12563eb7865cc4637842d0da1202da7491db61a30f3a5055732eac448d1d81d4c3c2325c887e81b206093201685dda058dea955e43c459a0ee607cf990b82b27f26f64bff75c9453162da39ac204b8932027f62462db26231002345558bbbb75c3801567a30b58027e2099ae6ae0175781b59b51368c555559b1ea57294a43a4acc47ecb3a230d33c761aa97be73443b20cae0f23540f3badbc3330f268099859168e592a9153367620d9c9dce6822f1baf6b094cb746e25530bde74868b8239c80c41b527cff9c5c3d540916045fde6e571190788631b759eff8f69f89455412a44d7e4331b4ada62974db310543bee35762428eea0bb4bcc3627e4cc7867692868c22332a3503032dbe80e99975969c6a714dff4dd2c9d6ca5475746ff35845631ae156996e898a38ddfc207d9ea7ca5d8fefa7992217796a5013c2e73047675058ef0f3a747f410b497556dbee716e5f9f72a5a098eba9994e3e6f13492ed9272e8e3d060e70f63367ed3eeb905".fromHex, - "3082051c30820304a003020102020900d50ff25ba3f2d6b3300d06092a864886f70d01010b0500301b311930170603550405131066393230303965383533623662303435301e170d3139313132323230333735385a170d3334313131383230333735385a301b31193017060355040513106639323030396538353362366230343530820222300d06092a864886f70d01010105000382020f003082020a0282020100afb6c7822bb1a701ec2bb42e8bcc541663abef982f32c77f7531030c97524b1b5fe809fbc72aa9451f743cbd9a6f1335744aa55e77f6b6ac3535ee17c25e639517dd9c92e6374a53cbfe258f8ffbb6fd129378a22a4ca99c452d47a59f3201f44197ca1ccd7e762fb2f53151b6feb2fffd2b6fe4fe5bc6bd9ec34bfe08239daafceb8eb5a8ed2b3acd9c5e3a7790e1b51442793159859811ad9eb2a96bbdd7a57c93a91c41fccd27d67fd6f671aa0b815261ad384fa37944864604ddb3d8c4f920a19b1656c2f14ad6d03c56ec060899041c1ed1a5fe6d3440b556bad1d0a152589c53e55d370762f0122eef91861b1b0e6c4c80927499c0e9bec0b83e3bc1f93c72c049604bbd2f1345e62c3f8e26dbec06c94766f3c128239d4f4312fad8123887e06becf567583bf8355a81feeabaf99a83c8df3e2a322afc672bf120b135158b6821ceaf309b6eee77f98833b018daa10e451f06a374d50781f359082966bb778b9308942698e74e0bcd24628a01c2cc03e51f0b3e5b4ac1e4df9eaf9ff6a492a77c1483882885015b422ce67b80b88c9b48e13b607ab545c723ff8c44f8f2d368b9f6520d31145ebf9e862ad71df6a3bfd2450959d653740d97a12f368b13ef66d5d0a54a6e2f5d9a6fef446832bc67844725861f093dd0e6f3405da89643ef0f4d69b6420051fdb93049673e36950580d3cdf4fbd08bc58483952600630203010001a3633061301d0603551d0e041604143661e1007c880509518b446c47ff1a4cc9ea4f12301f0603551d230418301680143661e1007c880509518b446c47ff1a4cc9ea4f12300f0603551d130101ff040530030101ff300e0603551d0f0101ff040403020204300d06092a864886f70d01010b050003820201004e31a05cf28ba65dbdafa1ced70969ee5ca84104added8a306cf7f6dee50375d745ed992cb0242cce72dc9eed51191fe5ad52bad7dd3b25c099e13a491a3cdd487a5acce8766324c4ae46338246ae7b78a418acbb98a05c4c9d696eeaab609d0ba0ce1a31be98490df3f4c0ea9ddc9e82ffb0fcb3e9ebdd8cb952789f2b1411fac56c886426eb7296042735da50e11ac715f1818cf9fdc4e254a3763351b6a2440150861263a6e310be1a50de5c7e8ee880fdd4be5884a37128d18830bb3476bf4291e82d5c66a6494939e08480bfbc00f7d8a74d43e73737ebe5d8e4ec515302d4689692780dc7538ed7e9175be6139e74d43ad388b3050ffd5a9de5262000898c01f63c53dfe22209108fa4f65ba16c49ccbde0837d7c5844d54b7398ba0122e505b155c9313cfe26e72d87e22aa1616e6bdbf547ddff93df29e35a63b455fe1fc0ec95581f3f4f7bbe3bb828396a37ae3157582bc3764b9780a239efc0f75a1e2e6d941ceabac27ddeb01e2bd8421029bea34d51aee6c60271d5a95ebd00515a9c0013dd80bf87eea260b81c34f688e6eb1348af0d8ea1cac32acb9d93fa24aff030a84c8f2b0f569cc95080b20ac35ace0c6d8dbd4f6847719519d32450166eb4bf15b859044501adeaf436382c34b15e3b54c92e61b69c2bfc7264589172b3c93dbe35ce06d08fd5c01322ca0877b1d12743af1fad5940ea1bc02dd891c".fromHex, + "308202ce30820273a003020102020101300a06082a8648ce3d040302303931293027060355040313203037653832313634373436306364383232663631363063383565386138616261310c300a060355040a1303544545301e170d3234303631383032313533335a170d3234303731383032313533335a301f311d301b06035504031314416e64726f6964204b657973746f7265204b65793059301306072a8648ce3d020106082a8648ce3d03010703420004ac858c2a816562929c5c69bfd64aacaf7c2e84c0db4f0b71a6a1dd153a72265c1b91fb8608e39bedf168a56634966b6fd4c140796397ce3171e50c8a5a30ebc6a382018430820180300e0603551d0f0101ff0404030207803082016c060a2b06010401d6790201110482015c308201580202012c0a01010202012c0a010104094368616c6c656e6765040030818ebf831008020601902920cc83bf83110802060190c39f9483bf83120802060190c39f9483bf853d08020601902920cca4bf85455a045830563130302e0429636f6d2e616e64726f69642e6964656e746974792e7365637572655f617265615f746573745f61707002010131220420e180e58c9e4bfb40d5e68e528be1a668e70361537528b8eda19bf900863f11223081a9a1053103020102a203020103a30402020100a5053103020104aa03020101bf837803020103bf83790302010abf853e03020100bf85404c304a042000000000000000000000000000000000000000000000000000000000000000000101000a01020420c95b9d89c2adc6bed35d630cfb43e8f514a99e521a0944348009e6651d7c5414bf85410502030222e0bf8542050203031647bf854e0602040134b3c1bf854f0602040134b3c1300a06082a8648ce3d0403020349003046022100bb9878eabc1ea4bbf095d77aba6ebb93ea24988f3bdbc87b2894be22aa905767022100a1f10252af737d4d836b6a222422f0e037b23efbea3bed882ef7db8ebd16ac68".fromHex(), + "308201d63082017ca003020102021007e821647460cd822f6160c85e8a8aba300a06082a8648ce3d040302302931133011060355040a130a476f6f676c65204c4c43311230100603550403130944726f696420434133301e170d3234303532333233323432305a170d3234303632303233323432305a303931293027060355040313203037653832313634373436306364383232663631363063383565386138616261310c300a060355040a13035445453059301306072a8648ce3d020106082a8648ce3d0301070342000402a3dd51ea8533eda9abad1b4dd4df5674abb01c839a21c7918f85d89eb77aaa3d570e522ba79ba40d26e21db20bf5a955c789711a9e1788b4592ea14c5487f8a3763074301d0603551d0e0416041421136b05cef61befcd0cd43dc8b15df83b6d3e5c301f0603551d230418301680141cc2bd40dba29c4bdc06a6a10d4694ffb2f5c02a300f0603551d130101ff040530030101ff300e0603551d0f0101ff0404030202043011060a2b06010401d67902011e0403a10110300a06082a8648ce3d0403020348003045022100e5c42005468e145cf200c4ba618351ee297fe9af5e228b258a57b7b45e29d9a702204ee2b68c0754019e743d60c0b013d62fc5914c4ac6088c04b484c27e74e0751b".fromHex(), + "308201d63082015ca0030201020213408ad01b2be2d94e2ffdd454b3cb87bba93cd9300a06082a8648ce3d040303302931133011060355040a130a476f6f676c65204c4c43311230100603550403130944726f696420434132301e170d3234303532353230343535395a170d3234303731343230343535385a302931133011060355040a130a476f6f676c65204c4c43311230100603550403130944726f6964204341333059301306072a8648ce3d020106082a8648ce3d03010703420004b893145670be40c9d352400297edef3bc9a1fea89d0b4fb0226eb4363aa2cdf8b47cc5b8ce77036389ba4a1bf257fefc0fa40f667598393dab429cc032f2d9cea3633061300e0603551d0f0101ff040403020204300f0603551d130101ff040530030101ff301d0603551d0e041604141cc2bd40dba29c4bdc06a6a10d4694ffb2f5c02a301f0603551d23041830168014bbf836ad89ae6ce2e59e94f0d5b2d7d27ae47c41300a06082a8648ce3d040303036800306502305c2c09ba5a4320deb6c27f1d7adbfef8592fc5cbb9da4a3c551268d2798ba027f27e30f41fab084c29271ad27cf16ad60231009e6031b2fcfcc424234a36b3ec60153374c46d65a5e20191f7394f08f466d3fe36f896a9d24a00350059082b9eb2c525".fromHex(), + "3082038030820168a003020102020a0388266760658996860d300d06092a864886f70d01010b0500301b311930170603550405131066393230303965383533623662303435301e170d3232303132363232343735325a170d3337303132323232343735325a302931133011060355040a130a476f6f676c65204c4c43311230100603550403130944726f6964204341323076301006072a8648ce3d020106052b8104002203620004ba9a716d9bc98303575deeaa40a89d5ea52dd68a13f0ce90fb2b16230a5db8cd846a5493f2ffc2cb624dd746aa4df5124e12616bfa02b46f85f53514be239c87a45a86ba6357205d868a4cf4c1439427e488290f08f1aed8e0cc8fb3bf6ca9e4a3663064301d0603551d0e04160414bbf836ad89ae6ce2e59e94f0d5b2d7d27ae47c41301f0603551d230418301680143661e1007c880509518b446c47ff1a4cc9ea4f1230120603551d130101ff040830060101ff020102300e0603551d0f0101ff040403020106300d06092a864886f70d01010b05000382020100817152214761f39baab24cd1e79723e919153e7bc01a6586af9312377eefc9c859b2af28650596fb7b22e5c7cd9ed825db520ecee516d0acc5776b58498b724c510c245cb61dc46f595e15eb294b7e4d00e7741de920f2fcb61b7d4e5807b9ebb97a35d2e3ab2b6e91c178280cc7211c68162bcdfad9641099a0ec4430f43db03eae0aa41b6e838a09139dd1f5b2c24f9c12563eb7865cc4637842d0da1202da7491db61a30f3a5055732eac448d1d81d4c3c2325c887e81b206093201685dda058dea955e43c459a0ee607cf990b82b27f26f64bff75c9453162da39ac204b8932027f62462db26231002345558bbbb75c3801567a30b58027e2099ae6ae0175781b59b51368c555559b1ea57294a43a4acc47ecb3a230d33c761aa97be73443b20cae0f23540f3badbc3330f268099859168e592a9153367620d9c9dce6822f1baf6b094cb746e25530bde74868b8239c80c41b527cff9c5c3d540916045fde6e571190788631b759eff8f69f89455412a44d7e4331b4ada62974db310543bee35762428eea0bb4bcc3627e4cc7867692868c22332a3503032dbe80e99975969c6a714dff4dd2c9d6ca5475746ff35845631ae156996e898a38ddfc207d9ea7ca5d8fefa7992217796a5013c2e73047675058ef0f3a747f410b497556dbee716e5f9f72a5a098eba9994e3e6f13492ed9272e8e3d060e70f63367ed3eeb905".fromHex(), + "3082051c30820304a003020102020900d50ff25ba3f2d6b3300d06092a864886f70d01010b0500301b311930170603550405131066393230303965383533623662303435301e170d3139313132323230333735385a170d3334313131383230333735385a301b31193017060355040513106639323030396538353362366230343530820222300d06092a864886f70d01010105000382020f003082020a0282020100afb6c7822bb1a701ec2bb42e8bcc541663abef982f32c77f7531030c97524b1b5fe809fbc72aa9451f743cbd9a6f1335744aa55e77f6b6ac3535ee17c25e639517dd9c92e6374a53cbfe258f8ffbb6fd129378a22a4ca99c452d47a59f3201f44197ca1ccd7e762fb2f53151b6feb2fffd2b6fe4fe5bc6bd9ec34bfe08239daafceb8eb5a8ed2b3acd9c5e3a7790e1b51442793159859811ad9eb2a96bbdd7a57c93a91c41fccd27d67fd6f671aa0b815261ad384fa37944864604ddb3d8c4f920a19b1656c2f14ad6d03c56ec060899041c1ed1a5fe6d3440b556bad1d0a152589c53e55d370762f0122eef91861b1b0e6c4c80927499c0e9bec0b83e3bc1f93c72c049604bbd2f1345e62c3f8e26dbec06c94766f3c128239d4f4312fad8123887e06becf567583bf8355a81feeabaf99a83c8df3e2a322afc672bf120b135158b6821ceaf309b6eee77f98833b018daa10e451f06a374d50781f359082966bb778b9308942698e74e0bcd24628a01c2cc03e51f0b3e5b4ac1e4df9eaf9ff6a492a77c1483882885015b422ce67b80b88c9b48e13b607ab545c723ff8c44f8f2d368b9f6520d31145ebf9e862ad71df6a3bfd2450959d653740d97a12f368b13ef66d5d0a54a6e2f5d9a6fef446832bc67844725861f093dd0e6f3405da89643ef0f4d69b6420051fdb93049673e36950580d3cdf4fbd08bc58483952600630203010001a3633061301d0603551d0e041604143661e1007c880509518b446c47ff1a4cc9ea4f12301f0603551d230418301680143661e1007c880509518b446c47ff1a4cc9ea4f12300f0603551d130101ff040530030101ff300e0603551d0f0101ff040403020204300d06092a864886f70d01010b050003820201004e31a05cf28ba65dbdafa1ced70969ee5ca84104added8a306cf7f6dee50375d745ed992cb0242cce72dc9eed51191fe5ad52bad7dd3b25c099e13a491a3cdd487a5acce8766324c4ae46338246ae7b78a418acbb98a05c4c9d696eeaab609d0ba0ce1a31be98490df3f4c0ea9ddc9e82ffb0fcb3e9ebdd8cb952789f2b1411fac56c886426eb7296042735da50e11ac715f1818cf9fdc4e254a3763351b6a2440150861263a6e310be1a50de5c7e8ee880fdd4be5884a37128d18830bb3476bf4291e82d5c66a6494939e08480bfbc00f7d8a74d43e73737ebe5d8e4ec515302d4689692780dc7538ed7e9175be6139e74d43ad388b3050ffd5a9de5262000898c01f63c53dfe22209108fa4f65ba16c49ccbde0837d7c5844d54b7398ba0122e505b155c9313cfe26e72d87e22aa1616e6bdbf547ddff93df29e35a63b455fe1fc0ec95581f3f4f7bbe3bb828396a37ae3157582bc3764b9780a239efc0f75a1e2e6d941ceabac27ddeb01e2bd8421029bea34d51aee6c60271d5a95ebd00515a9c0013dd80bf87eea260b81c34f688e6eb1348af0d8ea1cac32acb9d93fa24aff030a84c8f2b0f569cc95080b20ac35ace0c6d8dbd4f6847719519d32450166eb4bf15b859044501adeaf436382c34b15e3b54c92e61b69c2bfc7264589172b3c93dbe35ce06d08fd5c01322ca0877b1d12743af1fad5940ea1bc02dd891c".fromHex(), ).map { X509Cert(it) } ) @@ -66,7 +66,7 @@ class X509CertTests { fun testCborRoundTrip() { // Check that each certificate is signed by the next one... for (cert in androidKeyCertChain.certificates) { - val cborEncoded = cert.toDataItem + val cborEncoded = cert.toDataItem() val certFromCbor = X509Cert.fromDataItem(cborEncoded) assertEquals(certFromCbor, cert) } @@ -95,7 +95,7 @@ class X509CertTests { val publicKey = cert.ecPublicKey as EcPublicKeyDoubleCoordinate assertEquals( androidKeyCertChainKeysRaw[n], - (publicKey.x + publicKey.y).toHex + (publicKey.x + publicKey.y).toHex() ) } else -> { diff --git a/identity/src/commonTest/kotlin/com/android/identity/document/DocumentStoreTest.kt b/identity/src/commonTest/kotlin/com/android/identity/document/DocumentStoreTest.kt index a67df31da..4d82e668c 100644 --- a/identity/src/commonTest/kotlin/com/android/identity/document/DocumentStoreTest.kt +++ b/identity/src/commonTest/kotlin/com/android/identity/document/DocumentStoreTest.kt @@ -204,8 +204,8 @@ class DocumentStoreTest { // We check that NameSpacedData is preserved across loads by simply comparing the // encoded data. assertEquals( - document.applicationData.getNameSpacedData("documentData").toDataItem, - loadedDocument.applicationData.getNameSpacedData("documentData").toDataItem + document.applicationData.getNameSpacedData("documentData").toDataItem(), + loadedDocument.applicationData.getNameSpacedData("documentData").toDataItem() ) } diff --git a/identity/src/commonTest/kotlin/com/android/identity/document/NameSpacedDataTest.kt b/identity/src/commonTest/kotlin/com/android/identity/document/NameSpacedDataTest.kt index c17673203..ccf09f18a 100644 --- a/identity/src/commonTest/kotlin/com/android/identity/document/NameSpacedDataTest.kt +++ b/identity/src/commonTest/kotlin/com/android/identity/document/NameSpacedDataTest.kt @@ -84,7 +84,7 @@ class NameSpacedDataTest { " }\n" + "}", Cbor.toDiagnostics( - foo.toDataItem, + foo.toDataItem(), setOf(DiagnosticOption.PRETTY_PRINT, DiagnosticOption.EMBEDDED_CBOR) ) ) @@ -100,7 +100,7 @@ class NameSpacedDataTest { " }\n" + "}", Cbor.toDiagnostics( - fooModified.toDataItem, + fooModified.toDataItem(), setOf(DiagnosticOption.PRETTY_PRINT, DiagnosticOption.EMBEDDED_CBOR) ) ) diff --git a/identity/src/commonTest/kotlin/com/android/identity/util/HexUtilTest.kt b/identity/src/commonTest/kotlin/com/android/identity/util/HexUtilTest.kt index cff9cf81e..134949e5e 100644 --- a/identity/src/commonTest/kotlin/com/android/identity/util/HexUtilTest.kt +++ b/identity/src/commonTest/kotlin/com/android/identity/util/HexUtilTest.kt @@ -49,11 +49,11 @@ class HexUtilTest { @Test fun extensions() { assertContentEquals( - "deadbeef".fromHex, + "deadbeef".fromHex(), byteArrayOf(0xde.toByte(), 0xad.toByte(), 0xbe.toByte(), 0xef.toByte()) ) assertEquals( - byteArrayOf(0xde.toByte(), 0xad.toByte(), 0xbe.toByte(), 0xef.toByte()).toHex, + byteArrayOf(0xde.toByte(), 0xad.toByte(), 0xbe.toByte(), 0xef.toByte()).toHex(), "deadbeef" ) } diff --git a/identity/src/iosMain/kotlin/com/android/identity/crypto/X509CertIos.kt b/identity/src/iosMain/kotlin/com/android/identity/crypto/X509CertIos.kt index 52d2718dd..1cd2eb54b 100644 --- a/identity/src/iosMain/kotlin/com/android/identity/crypto/X509CertIos.kt +++ b/identity/src/iosMain/kotlin/com/android/identity/crypto/X509CertIos.kt @@ -9,8 +9,8 @@ import kotlin.io.encoding.ExperimentalEncodingApi @OptIn(ExperimentalForeignApi::class) actual class X509Cert actual constructor(actual val encodedCertificate: ByteArray) { - actual val toDataItem: DataItem - get() = Bstr(encodedCertificate) + + actual fun toDataItem(): DataItem = Bstr(encodedCertificate) @OptIn(ExperimentalEncodingApi::class) actual fun toPem(): String { diff --git a/identity/src/iosMain/kotlin/com/android/identity/securearea/SecureEnclaveSecureArea.kt b/identity/src/iosMain/kotlin/com/android/identity/securearea/SecureEnclaveSecureArea.kt index 5d6bf3ea8..f1113d10c 100644 --- a/identity/src/iosMain/kotlin/com/android/identity/securearea/SecureEnclaveSecureArea.kt +++ b/identity/src/iosMain/kotlin/com/android/identity/securearea/SecureEnclaveSecureArea.kt @@ -82,7 +82,7 @@ class SecureEnclaveSecureArea( map.put("userAuthenticationTypes", SecureEnclaveUserAuthType.encodeSet(settings.userAuthenticationTypes)) map.put("curve", settings.ecCurve.coseCurveIdentifier) - map.put("publicKey", publicKey.toDataItem) + map.put("publicKey", publicKey.toDataItem()) map.put("keyBlob", keyBlob) storageEngine.put(PREFIX + alias, Cbor.encode(map.end().build())) } diff --git a/identity/src/jvmMain/kotlin/com/android/identity/crypto/X509CertJvm.kt b/identity/src/jvmMain/kotlin/com/android/identity/crypto/X509CertJvm.kt index 96a730c3e..dbf839d20 100644 --- a/identity/src/jvmMain/kotlin/com/android/identity/crypto/X509CertJvm.kt +++ b/identity/src/jvmMain/kotlin/com/android/identity/crypto/X509CertJvm.kt @@ -25,8 +25,7 @@ import kotlin.io.encoding.ExperimentalEncodingApi actual class X509Cert actual constructor(actual val encodedCertificate: ByteArray) { - actual val toDataItem: DataItem - get() = Bstr(encodedCertificate) + actual fun toDataItem(): DataItem = Bstr(encodedCertificate) @OptIn(ExperimentalEncodingApi::class) actual fun toPem(): String { diff --git a/identity/src/jvmMain/kotlin/com/android/identity/trustmanagement/TrustManagerUtil.kt b/identity/src/jvmMain/kotlin/com/android/identity/trustmanagement/TrustManagerUtil.kt index af31c6516..3585f64c2 100644 --- a/identity/src/jvmMain/kotlin/com/android/identity/trustmanagement/TrustManagerUtil.kt +++ b/identity/src/jvmMain/kotlin/com/android/identity/trustmanagement/TrustManagerUtil.kt @@ -46,7 +46,7 @@ internal object TrustManagerUtil { ?: return "" val octets = DEROctetString.getInstance(extensionValue).octets val subjectKeyIdentifier = SubjectKeyIdentifier.getInstance(octets) - return subjectKeyIdentifier.keyIdentifier.toHex + return subjectKeyIdentifier.keyIdentifier.toHex() } /** @@ -58,7 +58,7 @@ internal object TrustManagerUtil { ?: return "" val octets = DEROctetString.getInstance(extensionValue).octets val authorityKeyIdentifier = AuthorityKeyIdentifier.getInstance(octets) - return authorityKeyIdentifier.keyIdentifier.toHex + return authorityKeyIdentifier.keyIdentifier.toHex() } /** diff --git a/identity/src/jvmTest/kotlin/com/android/identity/cose/CoseTestsJvm.kt b/identity/src/jvmTest/kotlin/com/android/identity/cose/CoseTestsJvm.kt index b6ecb0774..6ad279e3c 100644 --- a/identity/src/jvmTest/kotlin/com/android/identity/cose/CoseTestsJvm.kt +++ b/identity/src/jvmTest/kotlin/com/android/identity/cose/CoseTestsJvm.kt @@ -35,7 +35,7 @@ class CoseTestsJvm { EcCurve.P256, BigInteger.valueOf(1).sec1EncodeFieldElementAsOctetString(32), BigInteger.valueOf(1).sec1EncodeFieldElementAsOctetString(32) - ).toCoseKey().toDataItem, + ).toCoseKey().toDataItem(), setOf(DiagnosticOption.PRETTY_PRINT) ) ) @@ -50,7 +50,7 @@ class CoseTestsJvm { BigInteger.valueOf(1).sec1EncodeFieldElementAsOctetString(32) ) val coseKey = key.toCoseKey( - mapOf(Pair(Cose.COSE_KEY_KID.toCoseLabel, "name@example.com".toByteArray().toDataItem)) + mapOf(Pair(Cose.COSE_KEY_KID.toCoseLabel, "name@example.com".toByteArray().toDataItem())) ) assertEquals( "{\n" + @@ -60,7 +60,7 @@ class CoseTestsJvm { " -3: h'0000000000000000000000000000000000000000000000000000000000000001',\n" + " 2: h'6e616d65406578616d706c652e636f6d'\n" + "}", - Cbor.toDiagnostics(coseKey.toDataItem, setOf(DiagnosticOption.PRETTY_PRINT)) + Cbor.toDiagnostics(coseKey.toDataItem(), setOf(DiagnosticOption.PRETTY_PRINT)) ) } @@ -110,7 +110,7 @@ class CoseTestsJvm { "23032312d31302d30315431333a33303a30325a584059e64205df1e2f708dd6db0847aed7" + "9fc7c0201d80fa55badcaf2e1bcf5902e1e5a62e4832044b890ad85aa53f129134775d733" + "754d7cb7a413766aeff13cb2e" - val coseSign1 = Cbor.decode(issuerAuth.fromHex).asCoseSign1 + val coseSign1 = Cbor.decode(issuerAuth.fromHex()).asCoseSign1 val signatureAlgorithm = coseSign1.protectedHeaders[Cose.COSE_LABEL_ALG.toCoseLabel]!!.asNumber assertEquals(signatureAlgorithm, Algorithm.ES256.coseAlgorithmIdentifier.toLong()) @@ -124,8 +124,8 @@ class CoseTestsJvm { assertEquals("C=US, CN=utopia iaca", cert.issuerX500Principal.toString()) assertEquals("C=US, CN=utopia ds", cert.subjectX500Principal.toString()) - val x = "ace7ab7340e5d9648c5a72a9a6f56745c7aad436a03a43efea77b5fa7b88f019".fromHex - val y = "7d57d8983e1b37d3a539f4d588365e38cbbf5b94d68c547b5bc8731dcd2f146b".fromHex + val x = "ace7ab7340e5d9648c5a72a9a6f56745c7aad436a03a43efea77b5fa7b88f019".fromHex() + val y = "7d57d8983e1b37d3a539f4d588365e38cbbf5b94d68c547b5bc8731dcd2f146b".fromHex() val publicKey = EcPublicKeyDoubleCoordinate(EcCurve.P256, x, y) assertEquals(publicKey, cert.publicKey.toEcPublicKey(EcCurve.P256)) diff --git a/processor/src/main/kotlin/com/android/identity/processor/CborSymbolProcessor.kt b/processor/src/main/kotlin/com/android/identity/processor/CborSymbolProcessor.kt index f2c3c3613..0c1f2cfc5 100644 --- a/processor/src/main/kotlin/com/android/identity/processor/CborSymbolProcessor.kt +++ b/processor/src/main/kotlin/com/android/identity/processor/CborSymbolProcessor.kt @@ -218,22 +218,22 @@ class CborSymbolProcessor( } "kotlin.Int" -> { codeBuilder.importQualifiedName(TO_DATAITEM_FUN) - return "$code.toLong().toDataItem" + return "$code.toLong().toDataItem()" } "kotlin.Long", "kotlin.Float", "kotlin.Double", "kotlin.Boolean" -> { codeBuilder.importQualifiedName(TO_DATAITEM_FUN) - return "$code.toDataItem" + return "$code.toDataItem()" } "kotlinx.datetime.Instant" -> { codeBuilder.importQualifiedName(TO_DATAITEM_DATETIMESTRING_FUN) - return "$code.toDataItemDateTimeString" + return "$code.toDataItemDateTimeString()" } "kotlinx.datetime.LocalDate" -> { codeBuilder.importQualifiedName(TO_DATAITEM_FULLDATE_FUN) - return "$code.toDataItemFullDate" + return "$code.toDataItemFullDate()" } DATA_ITEM_CLASS -> return code @@ -247,7 +247,7 @@ class CborSymbolProcessor( if (findAnnotation(declaration, ANNOTATION_SERIALIZABLE) != null) { codeBuilder.importFunctionName("toDataItem", declaration.packageName.asString()) } - "$code.toDataItem" + "$code.toDataItem()" } } } @@ -373,13 +373,12 @@ class CborSymbolProcessor( generateSerialization(this, classDeclaration) - line("val $baseName.toDataItem: DataItem") - block("get()") { + block("fun $baseName.toDataItem(): DataItem") { block("return when (this)") { for (subclass in subclasses) { importQualifiedName(subclass) val subclassName = subclass.simpleName.asString() - line("is $subclassName -> (this as $subclassName).toDataItem") + line("is $subclassName -> (this as $subclassName).toDataItem()") } } } @@ -422,8 +421,7 @@ class CborSymbolProcessor( var hadMergedMap = false - line("val $baseName.toDataItem: DataItem") - block("get()") { + block("fun $baseName.toDataItem(): DataItem") { importQualifiedName(CBOR_MAP_TYPE) line("val builder = CborMap.builder()") if (typeKey != null) { @@ -586,7 +584,7 @@ class CborSymbolProcessor( val baseName = classDeclaration.simpleName.asString() codeBuilder.block("fun $baseName.toCbor(): ByteArray") { - line("return Cbor.encode(toDataItem)") + line("return Cbor.encode(toDataItem())") } codeBuilder.emptyLine() diff --git a/processor/src/main/kotlin/com/android/identity/processor/FlowSymbolProcessor.kt b/processor/src/main/kotlin/com/android/identity/processor/FlowSymbolProcessor.kt index bb3b8596e..81b8c53e3 100644 --- a/processor/src/main/kotlin/com/android/identity/processor/FlowSymbolProcessor.kt +++ b/processor/src/main/kotlin/com/android/identity/processor/FlowSymbolProcessor.kt @@ -626,7 +626,7 @@ class FlowSymbolProcessor( importQualifiedName(CborSymbolProcessor.BSTR_TYPE) block("private fun serialize(state: $baseName?): DataItem") { - line("return state?.toDataItem ?: Bstr(byteArrayOf())") + line("return state?.toDataItem() ?: Bstr(byteArrayOf())") } emptyLine() @@ -654,7 +654,7 @@ class FlowSymbolProcessor( line("val notifications = env.getInterface(FlowNotifications::class)!!") val notification = CborSymbolProcessor.serializeValue( this, "notification", flowInfo.notificationType) - line("notifications.emit(\"${flowInfo.path}\", this.toDataItem, $notification)") + line("notifications.emit(\"${flowInfo.path}\", this.toDataItem(), $notification)") } } diff --git a/samples/preconsent-mdl/src/main/java/com/android/identity/preconsent_mdl/MainActivity.kt b/samples/preconsent-mdl/src/main/java/com/android/identity/preconsent_mdl/MainActivity.kt index 61cf8c207..ebceb3dac 100644 --- a/samples/preconsent-mdl/src/main/java/com/android/identity/preconsent_mdl/MainActivity.kt +++ b/samples/preconsent-mdl/src/main/java/com/android/identity/preconsent_mdl/MainActivity.kt @@ -121,8 +121,8 @@ class MainActivity : ComponentActivity() { .putEntryString(MDL_NAMESPACE, "family_name", "Mustermann") .putEntryByteString(MDL_NAMESPACE, "portrait", portrait) .putEntryNumber(MDL_NAMESPACE, "sex", 2) - .putEntry(MDL_NAMESPACE, "issue_date", Cbor.encode(now.toDataItemDateTimeString)) - .putEntry(MDL_NAMESPACE, "expiry_date", Cbor.encode(expiryDate.toDataItemDateTimeString)) + .putEntry(MDL_NAMESPACE, "issue_date", Cbor.encode(now.toDataItemDateTimeString())) + .putEntry(MDL_NAMESPACE, "expiry_date", Cbor.encode(expiryDate.toDataItemDateTimeString())) .putEntryString(MDL_NAMESPACE, "document_number", "1234567890") .putEntryString(MDL_NAMESPACE, "issuing_authority", "State of Utopia") .putEntryString(AAMVA_NAMESPACE, "DHS_compliance", "F") @@ -181,13 +181,13 @@ class MainActivity : ComponentActivity() { val taggedEncodedMso = Cbor.encode(Tagged(Tagged.ENCODED_CBOR, Bstr(mso))) val protectedHeaders = mapOf(Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - Algorithm.ES256.coseAlgorithmIdentifier.toDataItem + Algorithm.ES256.coseAlgorithmIdentifier.toDataItem() )) val unprotectedHeaders = mapOf(Pair( CoseNumberLabel(Cose.COSE_LABEL_X5CHAIN), X509CertChain( listOf(X509Cert(documentSigningKeyCert.encodedCertificate)) - ).toDataItem + ).toDataItem() )) val encodedIssuerAuth = Cbor.encode( Cose.coseSign1Sign( @@ -197,7 +197,7 @@ class MainActivity : ComponentActivity() { Algorithm.ES256, protectedHeaders, unprotectedHeaders - ).toDataItem + ).toDataItem() ) val issuerProvidedAuthenticationData = StaticAuthDataGenerator( diff --git a/samples/secure-area-test-app/src/androidMain/kotlin/com/android/identity/secure_area_test_app/ui/AndroidKeystoreSecureAreaScreenAndroid.kt b/samples/secure-area-test-app/src/androidMain/kotlin/com/android/identity/secure_area_test_app/ui/AndroidKeystoreSecureAreaScreenAndroid.kt index 22ac67b3d..e1b3134d1 100644 --- a/samples/secure-area-test-app/src/androidMain/kotlin/com/android/identity/secure_area_test_app/ui/AndroidKeystoreSecureAreaScreenAndroid.kt +++ b/samples/secure-area-test-app/src/androidMain/kotlin/com/android/identity/secure_area_test_app/ui/AndroidKeystoreSecureAreaScreenAndroid.kt @@ -547,7 +547,7 @@ private fun aksTestUnguarded( Logger.d( TAG, "Made signature with key without authentication" + - "r=${signature.r.toHex} s=${signature.s.toHex}", + "r=${signature.r.toHex()} s=${signature.s.toHex()}", ) showToast("Signed w/o authn (${t1 - t0} msec)") } catch (e: KeyLockedException) { @@ -570,7 +570,7 @@ private fun aksTestUnguarded( Logger.d( TAG, "Made signature with key after authentication: " + - "r=${signature.r.toHex} s=${signature.s.toHex}", + "r=${signature.r.toHex()} s=${signature.s.toHex()}", ) showToast("Signed after authn (${t1 - t0} msec)") }, diff --git a/samples/secure-area-test-app/src/commonMain/kotlin/com/android/identity/secure_area_test_app/ui/SoftwareSecureAreaScreen.kt b/samples/secure-area-test-app/src/commonMain/kotlin/com/android/identity/secure_area_test_app/ui/SoftwareSecureAreaScreen.kt index 38004406f..8b171e72c 100644 --- a/samples/secure-area-test-app/src/commonMain/kotlin/com/android/identity/secure_area_test_app/ui/SoftwareSecureAreaScreen.kt +++ b/samples/secure-area-test-app/src/commonMain/kotlin/com/android/identity/secure_area_test_app/ui/SoftwareSecureAreaScreen.kt @@ -292,7 +292,7 @@ private fun swTestUnguarded( Logger.d( TAG, "Made signature with key without authentication " + - "r=${signature.r.toHex} s=${signature.s.toHex}" + "r=${signature.r.toHex()} s=${signature.s.toHex()}" ) showToast("Signed w/o authn (${t1 - t0})") } catch (e: KeyLockedException) { diff --git a/samples/secure-area-test-app/src/iosMain/kotlin/com/android/identity/secure_area_test_app/ui/SecureEnclaveSecureAreaScreenIos.kt b/samples/secure-area-test-app/src/iosMain/kotlin/com/android/identity/secure_area_test_app/ui/SecureEnclaveSecureAreaScreenIos.kt index 1cde62663..90288127b 100644 --- a/samples/secure-area-test-app/src/iosMain/kotlin/com/android/identity/secure_area_test_app/ui/SecureEnclaveSecureAreaScreenIos.kt +++ b/samples/secure-area-test-app/src/iosMain/kotlin/com/android/identity/secure_area_test_app/ui/SecureEnclaveSecureAreaScreenIos.kt @@ -138,7 +138,7 @@ private fun seTestUnguarded( Logger.d( TAG, "Made signature with key " + - "r=${signature.r.toHex} s=${signature.s.toHex}", + "r=${signature.r.toHex()} s=${signature.s.toHex()}", ) showToast("Signed (${t1 - t0})") } else { diff --git a/wallet/src/main/java/com/android/identity/issuance/simple/SimpleIssuingAuthority.kt b/wallet/src/main/java/com/android/identity/issuance/simple/SimpleIssuingAuthority.kt index 6c3b557ab..7d48e460a 100644 --- a/wallet/src/main/java/com/android/identity/issuance/simple/SimpleIssuingAuthority.kt +++ b/wallet/src/main/java/com/android/identity/issuance/simple/SimpleIssuingAuthority.kt @@ -109,7 +109,7 @@ abstract class SimpleIssuingAuthority( fun toCbor(): ByteArray { return Cbor.encode( CborMap.builder() - .put("authenticationKey", authenticationKey.toCoseKey().toDataItem) + .put("authenticationKey", authenticationKey.toCoseKey().toDataItem()) .put("format", format.name) .put("data", data) .put("deadline", deadline.toEpochMilliseconds()) @@ -176,13 +176,13 @@ abstract class SimpleIssuingAuthority( ceMapBuilder.put(evidence.key, RawCbor(evidence.value.toCbor())) } val mapBuilder = CborMap.builder() - .put("registrationResponse", registrationResponse.toDataItem) + .put("registrationResponse", registrationResponse.toDataItem()) .put("proofingDeadline", proofingDeadline.toEpochMilliseconds()) .put("state", state.ordinal.toLong()) .put("collectedEvidence", ceMapBuilder.end().build()) .put("credentialRequests", credentialRequestsBuilder.end().build()) if (documentConfiguration != null) { - mapBuilder.put("documentConfiguration", documentConfiguration!!.toDataItem) + mapBuilder.put("documentConfiguration", documentConfiguration!!.toDataItem()) } return Cbor.encode(mapBuilder.end().build()) } diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedEuPidIssuingAuthority.kt b/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedEuPidIssuingAuthority.kt index 1746c30c8..2e2e51211 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedEuPidIssuingAuthority.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedEuPidIssuingAuthority.kt @@ -229,12 +229,12 @@ class SelfSignedEuPidIssuingAuthority( .putEntryString(EUPID_NAMESPACE, "given_name", firstName) .putEntryString(EUPID_NAMESPACE, "family_name", lastName) .putEntry(EUPID_NAMESPACE, "birth_date", - Cbor.encode(dateOfBirth.toDataItemFullDate)) + Cbor.encode(dateOfBirth.toDataItemFullDate())) .putEntryNumber(EUPID_NAMESPACE, "gender", sex) .putEntry(EUPID_NAMESPACE, "issuance_date", - Cbor.encode(issueDate.toDataItemDateTimeString)) + Cbor.encode(issueDate.toDataItemDateTimeString())) .putEntry(EUPID_NAMESPACE, "expiry_date", - Cbor.encode(expiryDate.toDataItemDateTimeString) + Cbor.encode(expiryDate.toDataItemDateTimeString()) ) .putEntryString(EUPID_NAMESPACE, "issuing_authority", resourceString(R.string.utopia_eu_pid_issuing_authority_name)) diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedIssuingAuthority.kt b/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedIssuingAuthority.kt index c7087ba0d..3a6fbbc58 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedIssuingAuthority.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedIssuingAuthority.kt @@ -196,13 +196,13 @@ abstract class SelfSignedIssuingAuthority( val taggedEncodedMso = Cbor.encode(Tagged(Tagged.ENCODED_CBOR, Bstr(mso))) val protectedHeaders = mapOf(Pair( CoseNumberLabel(Cose.COSE_LABEL_ALG), - Algorithm.ES256.coseAlgorithmIdentifier.toDataItem + Algorithm.ES256.coseAlgorithmIdentifier.toDataItem() )) val unprotectedHeaders = mapOf(Pair( CoseNumberLabel(Cose.COSE_LABEL_X5CHAIN), X509CertChain(listOf( X509Cert(documentSigningKeyCert.encodedCertificate)) - ).toDataItem + ).toDataItem() )) val encodedIssuerAuth = Cbor.encode( Cose.coseSign1Sign( @@ -212,7 +212,7 @@ abstract class SelfSignedIssuingAuthority( Algorithm.ES256, protectedHeaders, unprotectedHeaders - ).toDataItem + ).toDataItem() ) val issuerProvidedAuthenticationData = StaticAuthDataGenerator( diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedMdlIssuingAuthority.kt b/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedMdlIssuingAuthority.kt index 5ff60b8da..21d102dc5 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedMdlIssuingAuthority.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/SelfSignedMdlIssuingAuthority.kt @@ -358,7 +358,7 @@ class SelfSignedMdlIssuingAuthority( builder.put("passphrase", passphrase) } if (passphraseConstraints != null) { - builder.put("passphraseConstraints", passphraseConstraints.toDataItem) + builder.put("passphraseConstraints", passphraseConstraints.toDataItem()) } return CredentialConfiguration( challenge, @@ -439,14 +439,14 @@ class SelfSignedMdlIssuingAuthority( .putEntryString(MDL_NAMESPACE, "given_name", firstName) .putEntryString(MDL_NAMESPACE, "family_name", lastName) .putEntry(MDL_NAMESPACE, "birth_date", - Cbor.encode(dateOfBirth.toDataItemFullDate)) + Cbor.encode(dateOfBirth.toDataItemFullDate())) .putEntryByteString(MDL_NAMESPACE, "portrait", portrait) .putEntryByteString(MDL_NAMESPACE, "signature_usual_mark", signatureOrUsualMark) .putEntryNumber(MDL_NAMESPACE, "sex", sex) .putEntry(MDL_NAMESPACE, "issue_date", - Cbor.encode(issueDate.toDataItemDateTimeString)) + Cbor.encode(issueDate.toDataItemDateTimeString())) .putEntry(MDL_NAMESPACE, "expiry_date", - Cbor.encode(expiryDate.toDataItemDateTimeString) + Cbor.encode(expiryDate.toDataItemDateTimeString()) ) .putEntryString(MDL_NAMESPACE, "issuing_authority", resourceString(R.string.utopia_mdl_issuing_authority_name),)