-
Notifications
You must be signed in to change notification settings - Fork 81
Include AES_CBC_ENCRYPT_DATA mechanism #149
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||||
// Copyright 2021 Contributors to the Parsec project. | ||||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||||
//! AES mechanism types | ||||||||
|
||||||||
use cryptoki_sys::CK_AES_CBC_ENCRYPT_DATA_PARAMS; | ||||||||
use std::convert::TryInto; | ||||||||
use std::marker::PhantomData; | ||||||||
|
||||||||
/// AES CBC derivation parameters. | ||||||||
/// This structure wraps a CK_AES_CBC_ENCRYPT_DATA_PARAMS structure. | ||||||||
#[derive(Copy, Debug, Clone)] | ||||||||
#[repr(transparent)] | ||||||||
pub struct AesCBCEncryptDataParams<'a> { | ||||||||
inner: CK_AES_CBC_ENCRYPT_DATA_PARAMS, | ||||||||
_marker: PhantomData<&'a [u8]>, | ||||||||
} | ||||||||
impl<'a> AesCBCEncryptDataParams<'a> { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: line spacing may be good :) |
||||||||
/// Construct AES CBC ENCRYPT DATA parameters. | ||||||||
/// | ||||||||
/// # Arguments | ||||||||
/// | ||||||||
/// `iv` - The initialization vector. This must be non-empty. | ||||||||
/// `data` - The data to cipher. | ||||||||
/// | ||||||||
/// # Panics | ||||||||
/// | ||||||||
/// This function panics if the lenght of `data` does not | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
/// fit into an [Ulong]. | ||||||||
pub fn new(iv: [u8; 16], data: &'a [u8]) -> Self { | ||||||||
Self { | ||||||||
inner: CK_AES_CBC_ENCRYPT_DATA_PARAMS { | ||||||||
iv, | ||||||||
pData: data.as_ptr() as *mut _, | ||||||||
length: data | ||||||||
.len() | ||||||||
.try_into() | ||||||||
.expect("data length does not fit in CK_ULONG"), | ||||||||
}, | ||||||||
_marker: PhantomData, | ||||||||
} | ||||||||
} | ||||||||
/// The initialization vector. | ||||||||
pub fn iv(&self) -> &[u8] { | ||||||||
self.inner.iv.as_slice() | ||||||||
} | ||||||||
|
||||||||
/// The data | ||||||||
pub fn data(&self) -> &[u8] { | ||||||||
unsafe { std::slice::from_raw_parts(self.inner.pData, self.inner.length as _) } | ||||||||
} | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a newline here would be nice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.