add and use AES associated constant
This commit is contained in:
parent
fddad8965d
commit
49f7501c5f
4 changed files with 11 additions and 4 deletions
|
@ -28,6 +28,7 @@ pub enum CompressionMethod {
|
|||
///
|
||||
/// The actual compression method has to be taken from the AES extra data field
|
||||
/// or from `ZipFileData`.
|
||||
#[cfg(feature = "aes-crypto")]
|
||||
Aes,
|
||||
/// Compress the file using ZStandard
|
||||
#[cfg(feature = "zstd")]
|
||||
|
@ -77,6 +78,10 @@ impl CompressionMethod {
|
|||
pub const JPEG: Self = CompressionMethod::Unsupported(96);
|
||||
pub const WAVPACK: Self = CompressionMethod::Unsupported(97);
|
||||
pub const PPMD: Self = CompressionMethod::Unsupported(98);
|
||||
#[cfg(feature = "aes-crypto")]
|
||||
pub const AES: Self = CompressionMethod::Aes;
|
||||
#[cfg(not(feature = "aes-crypto"))]
|
||||
pub const AES: Self = CompressionMethod::Unsupported(99);
|
||||
}
|
||||
impl CompressionMethod {
|
||||
/// Converts an u16 to its corresponding CompressionMethod
|
||||
|
@ -96,9 +101,9 @@ impl CompressionMethod {
|
|||
8 => CompressionMethod::Deflated,
|
||||
#[cfg(feature = "bzip2")]
|
||||
12 => CompressionMethod::Bzip2,
|
||||
99 => CompressionMethod::Aes,
|
||||
#[cfg(feature = "zstd")]
|
||||
93 => CompressionMethod::Zstd,
|
||||
99 => CompressionMethod::AES,
|
||||
|
||||
v => CompressionMethod::Unsupported(v),
|
||||
}
|
||||
|
@ -121,7 +126,7 @@ impl CompressionMethod {
|
|||
CompressionMethod::Deflated => 8,
|
||||
#[cfg(feature = "bzip2")]
|
||||
CompressionMethod::Bzip2 => 12,
|
||||
CompressionMethod::Aes => 99,
|
||||
CompressionMethod::AES => 99,
|
||||
#[cfg(feature = "zstd")]
|
||||
CompressionMethod::Zstd => 93,
|
||||
|
||||
|
|
|
@ -669,7 +669,7 @@ pub(crate) fn central_header_to_zip_file<R: Read + io::Seek>(
|
|||
Err(e) => return Err(e),
|
||||
}
|
||||
|
||||
let aes_enabled = result.compression_method == CompressionMethod::Aes;
|
||||
let aes_enabled = result.compression_method == CompressionMethod::AES;
|
||||
if aes_enabled && result.aes_mode.is_none() {
|
||||
return Err(ZipError::InvalidArchive(
|
||||
"AES encryption without AES extra data field",
|
||||
|
|
|
@ -848,7 +848,7 @@ impl<W: Write + io::Seek> GenericZipWriter<W> {
|
|||
CompressionMethod::Bzip2 => {
|
||||
GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::default()))
|
||||
}
|
||||
CompressionMethod::Aes => {
|
||||
CompressionMethod::AES => {
|
||||
return Err(ZipError::UnsupportedArchive(
|
||||
"AES compression is not supported for writing",
|
||||
))
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![cfg(feature = "aes-crypto")]
|
||||
|
||||
use std::io::{self, Read};
|
||||
use zip::ZipArchive;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue