Skip to content

Commit

Permalink
Fix DeviceAuth serialization error. (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
cobward authored Jan 3, 2025
1 parent 8495a24 commit dda3726
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
4 changes: 1 addition & 3 deletions src/definitions/device_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
14 changes: 4 additions & 10 deletions src/definitions/device_signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@ pub type DeviceSignedItems = NonEmptyMap<String, ciborium::Value>;
/// 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<CoseSign1>,
},
#[serde(rename_all = "camelCase")]
Mac { device_mac: MaybeTagged<CoseMac0> },
DeviceSignature(MaybeTagged<CoseSign1>),
DeviceMac(MaybeTagged<CoseMac0>),
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/presentation/authentication/mdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -82,7 +82,7 @@ pub fn device_authentication(
Ok(())
}
}
DeviceAuth::Mac { .. } => {
DeviceAuth::DeviceMac(_) => {
Err(Error::Unsupported)
// send not yet supported error
}
Expand Down
8 changes: 2 additions & 6 deletions src/presentation/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/definitions/device_response.cbor
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a46776657273696f6e63312e3069646f63756d656e747381a367646f6354797065636161616c6973737565725369676e6564a26a6e616d65537061636573a1616181d8185838a4686469676573744944182a6672616e646f6d412a71656c656d656e744964656e7469666965726234326c656c656d656e7456616c7565f66a69737375657241757468d28443a10126a10442313154546869732069732074686520636f6e74656e742e58408eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5a4c345cacb366c6465766963655369676e6564a26a6e616d65537061636573d81847a16161a16161f66a64657669636541757468a1634d6163a1696465766963654d6163d18443a10105a10442313154546869732069732074686520636f6e74656e742e58203f30c4a2c740c3a0d90310b48cd282bcdb29ab8073a32e287fa07e188d317e8a6e646f63756d656e744572726f727381a16161006673746174757300
A46776657273696F6E63312E3069646F63756D656E747381A367646F6354797065636161616C6973737565725369676E6564A26A6E616D65537061636573A1616181D8185838A4686469676573744944182A6672616E646F6D412A71656C656D656E744964656E7469666965726234326C656C656D656E7456616C7565F66A69737375657241757468D28443A10126A10442313154546869732069732074686520636F6E74656E742E58408EB33E4CA31D1C465AB05AAC34CC6B23D58FEF5C083106C4D25A91AEF0B0117E2AF9A291AA32E14AB834DC56ED2A223444547E01F11D3B0916E5A4C345CACB366C6465766963655369676E6564A26A6E616D65537061636573D81847A16161A16161F66A64657669636541757468A1696465766963654D6163D18443A10105A10442313154546869732069732074686520636F6E74656E742E58203F30C4A2C740C3A0D90310B48CD282BCDB29AB8073A32E287FA07E188D317E8A6E646F63756D656E744572726F727381A16161006673746174757300

0 comments on commit dda3726

Please sign in to comment.