Skip to content

Commit

Permalink
Fix DeviceAuth serialization error.
Browse files Browse the repository at this point in the history
  • Loading branch information
cobward committed Jan 3, 2025
1 parent b3a0317 commit 28805e1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 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

0 comments on commit 28805e1

Please sign in to comment.