parquet/file/
column_crypto_metadata.rs1use crate::errors::Result;
21use crate::format::{
22 ColumnCryptoMetaData as TColumnCryptoMetaData,
23 EncryptionWithColumnKey as TEncryptionWithColumnKey,
24 EncryptionWithFooterKey as TEncryptionWithFooterKey,
25};
26
27#[derive(Clone, Debug, PartialEq, Eq)]
29pub enum ColumnCryptoMetaData {
30 EncryptionWithFooterKey,
32 EncryptionWithColumnKey(EncryptionWithColumnKey),
34}
35
36#[derive(Clone, Debug, PartialEq, Eq)]
38pub struct EncryptionWithColumnKey {
39 pub path_in_schema: Vec<String>,
41 pub key_metadata: Option<Vec<u8>>,
43}
44
45pub fn try_from_thrift(
47 thrift_column_crypto_metadata: &TColumnCryptoMetaData,
48) -> Result<ColumnCryptoMetaData> {
49 let crypto_metadata = match thrift_column_crypto_metadata {
50 TColumnCryptoMetaData::ENCRYPTIONWITHFOOTERKEY(_) => {
51 ColumnCryptoMetaData::EncryptionWithFooterKey
52 }
53 TColumnCryptoMetaData::ENCRYPTIONWITHCOLUMNKEY(encryption_with_column_key) => {
54 ColumnCryptoMetaData::EncryptionWithColumnKey(EncryptionWithColumnKey {
55 path_in_schema: encryption_with_column_key.path_in_schema.clone(),
56 key_metadata: encryption_with_column_key.key_metadata.clone(),
57 })
58 }
59 };
60 Ok(crypto_metadata)
61}
62
63pub fn to_thrift(column_crypto_metadata: &ColumnCryptoMetaData) -> TColumnCryptoMetaData {
65 match column_crypto_metadata {
66 ColumnCryptoMetaData::EncryptionWithFooterKey => {
67 TColumnCryptoMetaData::ENCRYPTIONWITHFOOTERKEY(TEncryptionWithFooterKey {})
68 }
69 ColumnCryptoMetaData::EncryptionWithColumnKey(encryption_with_column_key) => {
70 TColumnCryptoMetaData::ENCRYPTIONWITHCOLUMNKEY(TEncryptionWithColumnKey {
71 path_in_schema: encryption_with_column_key.path_in_schema.clone(),
72 key_metadata: encryption_with_column_key.key_metadata.clone(),
73 })
74 }
75 }
76}
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81
82 #[test]
83 fn test_encryption_with_footer_key_from_thrift() {
84 let metadata = ColumnCryptoMetaData::EncryptionWithFooterKey;
85
86 assert_eq!(try_from_thrift(&to_thrift(&metadata)).unwrap(), metadata);
87 }
88
89 #[test]
90 fn test_encryption_with_column_key_from_thrift() {
91 let metadata = ColumnCryptoMetaData::EncryptionWithColumnKey(EncryptionWithColumnKey {
92 path_in_schema: vec!["abc".to_owned(), "def".to_owned()],
93 key_metadata: Some(vec![0, 1, 2, 3, 4, 5]),
94 });
95
96 assert_eq!(try_from_thrift(&to_thrift(&metadata)).unwrap(), metadata);
97 }
98}