Skip to content

Commit 1314cd1

Browse files
committed
Implement PartialEq explicitly for DecryptionKeys rather than FileDecryptionProperties
1 parent 8dbb24c commit 1314cd1

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

parquet/src/encryption/decrypt.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,21 @@ enum DecryptionKeys {
172172
ViaRetriever(Arc<dyn KeyRetriever>),
173173
}
174174

175+
impl PartialEq for DecryptionKeys {
176+
fn eq(&self, other: &Self) -> bool {
177+
match (self, other) {
178+
(DecryptionKeys::Explicit(keys), DecryptionKeys::Explicit(other_keys)) => {
179+
keys.footer_key == other_keys.footer_key
180+
&& keys.column_keys == other_keys.column_keys
181+
}
182+
(DecryptionKeys::ViaRetriever(_), DecryptionKeys::ViaRetriever(_)) => true,
183+
_ => false,
184+
}
185+
}
186+
}
187+
175188
/// FileDecryptionProperties hold keys and AAD data required to decrypt a Parquet file.
176-
#[derive(Clone)]
189+
#[derive(Clone, PartialEq)]
177190
pub struct FileDecryptionProperties {
178191
keys: DecryptionKeys,
179192
pub(crate) aad_prefix: Option<Vec<u8>>,
@@ -199,25 +212,6 @@ impl std::fmt::Debug for FileDecryptionProperties {
199212
}
200213
}
201214

202-
impl PartialEq for FileDecryptionProperties {
203-
// FileDecryptionProperties needs to implement PartialEq to allow
204-
// ParquetMetaData to implement PartialEq.
205-
// We cannot compare a key retriever, but this isn't derived from the metadata.
206-
fn eq(&self, other: &Self) -> bool {
207-
let keys_eq = match self.keys {
208-
DecryptionKeys::Explicit(ref keys) => {
209-
if let DecryptionKeys::Explicit(ref other_keys) = other.keys {
210-
keys == other_keys
211-
} else {
212-
false
213-
}
214-
}
215-
_ => true,
216-
};
217-
keys_eq && self.aad_prefix == other.aad_prefix
218-
}
219-
}
220-
221215
/// Builder for [`FileDecryptionProperties`]
222216
pub struct DecryptionPropertiesBuilder {
223217
footer_key: Option<Vec<u8>>,

0 commit comments

Comments
 (0)