From 137901d41010f779cf9a02a7e9a189a939ac52cb Mon Sep 17 00:00:00 2001 From: Jacob Date: Fri, 3 Jan 2025 15:05:18 +0000 Subject: [PATCH] Fix DeviceAuth serialization error. --- src/definitions/device_response.rs | 4 +--- src/definitions/device_signed.rs | 14 ++++---------- src/presentation/authentication/mdoc.rs | 4 ++-- src/presentation/device.rs | 8 ++------ test/definitions/device_response.cbor | 2 +- 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/definitions/device_response.rs b/src/definitions/device_response.rs index 1d8bea8..a61f528 100644 --- a/src/definitions/device_response.rs +++ b/src/definitions/device_response.rs @@ -191,9 +191,7 @@ mod test { }, device_signed: DeviceSigned { namespaces: device_namespaces_bytes, - device_auth: DeviceAuth::Mac { - device_mac: cose_mac0, - }, + device_auth: DeviceAuth::DeviceMac(cose_mac0), }, errors: None, }; diff --git a/src/definitions/device_signed.rs b/src/definitions/device_signed.rs index 0b231e1..a07f002 100644 --- a/src/definitions/device_signed.rs +++ b/src/definitions/device_signed.rs @@ -34,14 +34,10 @@ pub type DeviceSignedItems = NonEmptyMap; /// This struct contains the device signature in the form of a [CoseSign1] object. /// The [CoseSign1] object represents a `COSE (CBOR Object Signing and Encryption) signature. #[derive(Clone, Debug, Deserialize, Serialize)] -// #[serde(untagged)] +#[serde(rename_all = "camelCase")] pub enum DeviceAuth { - #[serde(rename_all = "camelCase")] - Signature { - device_signature: MaybeTagged, - }, - #[serde(rename_all = "camelCase")] - Mac { device_mac: MaybeTagged }, + DeviceSignature(MaybeTagged), + DeviceMac(MaybeTagged), } #[derive(Debug, Clone, Copy, Serialize, Deserialize)] @@ -93,9 +89,7 @@ mod tests { cbor::from_slice(&bytes).expect("failed to parse COSE_Sign1 from bytes"); let bytes2 = cbor::to_vec(&cose_sign1).unwrap(); assert_eq!(bytes, bytes2); - let device_auth = DeviceAuth::Signature { - device_signature: cose_sign1, - }; + let device_auth = DeviceAuth::DeviceSignature(cose_sign1); let bytes = cbor::to_vec(&device_auth).unwrap(); println!("bytes {}", hex::encode(&bytes)); let roundtripped: DeviceAuth = cbor::from_slice(&bytes).unwrap(); diff --git a/src/presentation/authentication/mdoc.rs b/src/presentation/authentication/mdoc.rs index 01418f4..fe40193 100644 --- a/src/presentation/authentication/mdoc.rs +++ b/src/presentation/authentication/mdoc.rs @@ -62,7 +62,7 @@ pub fn device_authentication( let device_auth: &DeviceAuth = &document.device_signed.device_auth; match device_auth { - DeviceAuth::Signature { device_signature } => { + DeviceAuth::DeviceSignature(device_signature) => { let detached_payload = Tag24::new(DeviceAuthentication::new( session_transcript, document.doc_type.clone(), @@ -82,7 +82,7 @@ pub fn device_authentication( Ok(()) } } - DeviceAuth::Mac { .. } => { + DeviceAuth::DeviceMac(_) => { Err(Error::Unsupported) // send not yet supported error } diff --git a/src/presentation/device.rs b/src/presentation/device.rs index 1ce2e15..607e1ba 100644 --- a/src/presentation/device.rs +++ b/src/presentation/device.rs @@ -737,12 +737,8 @@ impl PreparedDocument { .. } = self; let device_auth = match prepared_cose { - PreparedCose::Sign1(inner) => DeviceAuth::Signature { - device_signature: inner.finalize(signature), - }, - PreparedCose::Mac0(inner) => DeviceAuth::Mac { - device_mac: inner.finalize(signature), - }, + PreparedCose::Sign1(inner) => DeviceAuth::DeviceSignature(inner.finalize(signature)), + PreparedCose::Mac0(inner) => DeviceAuth::DeviceMac(inner.finalize(signature)), }; let device_signed = DeviceSigned { namespaces: device_namespaces, diff --git a/test/definitions/device_response.cbor b/test/definitions/device_response.cbor index bda9f89..5db6eea 100644 --- a/test/definitions/device_response.cbor +++ b/test/definitions/device_response.cbor @@ -1 +1 @@ -a46776657273696f6e63312e3069646f63756d656e747381a367646f6354797065636161616c6973737565725369676e6564a26a6e616d65537061636573a1616181d8185838a4686469676573744944182a6672616e646f6d412a71656c656d656e744964656e7469666965726234326c656c656d656e7456616c7565f66a69737375657241757468d28443a10126a10442313154546869732069732074686520636f6e74656e742e58408eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5a4c345cacb366c6465766963655369676e6564a26a6e616d65537061636573d81847a16161a16161f66a64657669636541757468a1634d6163a1696465766963654d6163d18443a10105a10442313154546869732069732074686520636f6e74656e742e58203f30c4a2c740c3a0d90310b48cd282bcdb29ab8073a32e287fa07e188d317e8a6e646f63756d656e744572726f727381a16161006673746174757300 \ No newline at end of file +A46776657273696F6E63312E3069646F63756D656E747381A367646F6354797065636161616C6973737565725369676E6564A26A6E616D65537061636573A1616181D8185838A4686469676573744944182A6672616E646F6D412A71656C656D656E744964656E7469666965726234326C656C656D656E7456616C7565F66A69737375657241757468D28443A10126A10442313154546869732069732074686520636F6E74656E742E58408EB33E4CA31D1C465AB05AAC34CC6B23D58FEF5C083106C4D25A91AEF0B0117E2AF9A291AA32E14AB834DC56ED2A223444547E01F11D3B0916E5A4C345CACB366C6465766963655369676E6564A26A6E616D65537061636573D81847A16161A16161F66A64657669636541757468A1696465766963654D6163D18443A10105A10442313154546869732069732074686520636F6E74656E742E58203F30C4A2C740C3A0D90310B48CD282BCDB29AB8073A32E287FA07E188D317E8A6E646F63756D656E744572726F727381A16161006673746174757300 \ No newline at end of file