Skip to content

Commit

Permalink
Return error if credential ID is too long
Browse files Browse the repository at this point in the history
Instead of panicking, we now return a RequestTooLarge error if the
encrypted and serialized credential ID is longer than 255 bytes.

Fixes: trussed-dev#15
  • Loading branch information
robin-nitrokey committed Aug 1, 2022
1 parent e399a11 commit 184e667
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ impl Credential {
let nonce: [u8; 12] = self.nonce.as_slice().try_into().unwrap();
let encrypted_serialized_credential = EncryptedSerializedCredential(syscall!(trussed
.encrypt_chacha8poly1305(key_encryption_key, message, associated_data, Some(&nonce))));
let credential_id: CredentialId = encrypted_serialized_credential.try_into().unwrap();
let credential_id: CredentialId = encrypted_serialized_credential.try_into()
.map_err(|_| Error::RequestTooLarge)?;

Ok(credential_id)
}
Expand Down

0 comments on commit 184e667

Please sign in to comment.