Skip to content

Commit

Permalink
Replace empty maps with an empty response
Browse files Browse the repository at this point in the history
Instead of sending an empty CBOR map as a response, we now always send
an empty response.  Previously, we had this as a special case for the
ClientPin response, but we need it for LargeBlobs too.  So a generic
implementation makes more sense and is easier to maintain.
  • Loading branch information
robin-nitrokey committed Nov 28, 2023
1 parent 785bcc5 commit 85eb709
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
17 changes: 8 additions & 9 deletions src/ctap2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,21 @@ impl Response {
let outcome = match self {
GetInfo(response) => cbor_serialize(response, data),
MakeCredential(response) => cbor_serialize(response, data),
ClientPin(response) => {
if response.is_empty() {
Ok([].as_slice())
} else {
cbor_serialize(response, data)
}
}
ClientPin(response) => cbor_serialize(response, data),
GetAssertion(response) | GetNextAssertion(response) => cbor_serialize(response, data),
CredentialManagement(response) => cbor_serialize(response, data),
LargeBlobs(response) => cbor_serialize(response, data),
Reset | Selection | Vendor => Ok([].as_slice()),
};
if let Ok(slice) = outcome {
*status = 0;
let l = slice.len();
buffer.resize_default(l + 1).ok();
// Instead of an empty CBOR map (0xA0), we return an empty response
if slice == [0xA0] {
buffer.resize_default(1).ok();
} else {
let l = slice.len();
buffer.resize_default(l + 1).ok();
}
} else {
*status = Error::Other as u8;
buffer.resize_default(1).ok();
Expand Down
6 changes: 0 additions & 6 deletions src/ctap2/client_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ pub struct Response {
pub retries: Option<u8>,
}

impl Response {
pub fn is_empty(&self) -> bool {
self.key_agreement.is_none() && self.pin_token.is_none() && self.retries.is_none()
}
}

#[cfg(test)]
mod tests {

Expand Down

0 comments on commit 85eb709

Please sign in to comment.