mirror of
https://gitlab.com/fabinfra/fabaccess/nfc_rs.git
synced 2025-03-13 15:21:43 +01:00
20 lines
690 B
Rust
20 lines
690 B
Rust
|
use crate::error::{Result, Error};
|
||
|
use simple_error::simple_error;
|
||
|
use block_modes::block_padding::{ZeroPadding, Padding};
|
||
|
|
||
|
pub fn extract_last_block(data: &[u8], blocksize: usize) -> Result<&[u8]> {
|
||
|
if data.len() % blocksize != 0 {
|
||
|
return Err(simple_error!("Data is not compatible with blocksize: data(length): {}, blocksize: {}.", data.len(), blocksize).into())
|
||
|
}
|
||
|
|
||
|
Ok(&data[(data.len() - blocksize)..])
|
||
|
}
|
||
|
|
||
|
pub fn expand_to_blocksize(data: &mut [u8], blocksize: usize) -> Result<&mut [u8]> {
|
||
|
// let diff = data.len() % blocksize;
|
||
|
|
||
|
match ZeroPadding::pad(data, data.len(), blocksize) {
|
||
|
Ok(x) => {Ok(x)}
|
||
|
Err(e) => {Err(Error::PadError(e))}
|
||
|
}
|
||
|
}
|