-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Problem
Currently, to get the resulting buffer after encoding CommandBuilder, length needs to be calculated separately.
let len = builder.required_len();
builder.serialize_into(&mut &mut buf[..]).unwrap();
&buf[..len]Solution
It would be nice if serialize_into returned length too:
let len = builder.serialize_into(&mut &mut buf[..]).unwrap();
&buf[..len]Proposal
Even better - let's encode directly to slice like der::Encode:
https://docs.rs/der/0.8.0-rc.10/der/trait.Encode.html#method.encode_to_slice
fn encode_to_slice<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]>[Spoiler] Encoding with iso7816 0.2.0
use iso7816::command::{CommandBuilder, ExpectedLen, class::Class};
fn main() {
let mut buf = [0u8; 16];
let read_binary = {
let builder = CommandBuilder::<()>::new(
Class::from_byte(0x00).unwrap(),
iso7816::Instruction::ReadBinary,
0x00,
0x00,
(),
ExpectedLen::Ne(65535),
)
.force_extended();
let len = builder.required_len();
builder.serialize_into(&mut &mut buf[..]).unwrap();
&buf[..len]
};
println!("read binary (extended) C-APDU: {:?}", read_binary);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels