Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have sign_data and decrypt_data return a Buffer #34

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,10 @@ impl<'tx> Transaction<'tx> {
pub(crate) fn authenticated_command(
&self,
sign_in: &[u8],
out: &mut [u8],
out_len: &mut usize,
algorithm: u8,
key: u8,
decipher: bool,
) -> Result<(), Error> {
) -> Result<Buffer, Error> {
let in_len = sign_in.len();
let mut indata = [0u8; 1024];
let templ = [0, Ins::Authenticate.code(), algorithm, key];
Expand Down Expand Up @@ -380,15 +378,7 @@ impl<'tx> Transaction<'tx> {

offset += 1;
offset += get_length(&data[offset..], &mut len);

if len > *out_len {
error!("wrong size on output buffer");
return Err(Error::SizeError);
}

*out_len = len;
out[..len].copy_from_slice(&data[offset..(offset + len)]);
Ok(())
Ok(Buffer::new(data[offset..(offset + len)].into()))
}

/// Send/receive large amounts of data to/from the YubiKey, splitting long
Expand Down
12 changes: 4 additions & 8 deletions src/yubikey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,31 +357,27 @@ impl YubiKey {
pub fn sign_data(
&mut self,
raw_in: &[u8],
sign_out: &mut [u8],
out_len: &mut usize,
algorithm: u8,
key: SlotId,
) -> Result<(), Error> {
) -> Result<Buffer, Error> {
let txn = self.begin_transaction()?;

// don't attempt to reselect in crypt operations to avoid problems with PIN_ALWAYS
txn.authenticated_command(raw_in, sign_out, out_len, algorithm, key, false)
txn.authenticated_command(raw_in, algorithm, key, false)
}

/// Decrypt data using a PIV key
#[cfg(feature = "untested")]
pub fn decrypt_data(
&mut self,
input: &[u8],
out: &mut [u8],
out_len: &mut usize,
algorithm: u8,
key: SlotId,
) -> Result<(), Error> {
) -> Result<Buffer, Error> {
let txn = self.begin_transaction()?;

// don't attempt to reselect in crypt operations to avoid problems with PIN_ALWAYS
txn.authenticated_command(input, out, out_len, algorithm, key, true)
txn.authenticated_command(input, algorithm, key, true)
}

/// Verify device PIN.
Expand Down