use std::io::Write;
use crate::errors::{ParquetError, Result};
use crate::file::metadata::HeapSize;
use crate::parquet_thrift::{
ElementType, FieldType, ReadThrift, ThriftCompactInputProtocol, ThriftCompactOutputProtocol,
WriteThrift, WriteThriftField, read_thrift_vec,
};
use crate::{thrift_struct, thrift_union};
thrift_struct!(
pub struct EncryptionWithColumnKey {
1: required list<string> path_in_schema
2: optional binary key_metadata
}
);
impl HeapSize for EncryptionWithColumnKey {
fn heap_size(&self) -> usize {
self.path_in_schema.heap_size() + self.key_metadata.heap_size()
}
}
thrift_union!(
union ColumnCryptoMetaData {
1: ENCRYPTION_WITH_FOOTER_KEY
2: (EncryptionWithColumnKey) ENCRYPTION_WITH_COLUMN_KEY
}
);
impl HeapSize for ColumnCryptoMetaData {
fn heap_size(&self) -> usize {
match self {
Self::ENCRYPTION_WITH_FOOTER_KEY => 0,
Self::ENCRYPTION_WITH_COLUMN_KEY(path) => path.heap_size(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::parquet_thrift::tests::test_roundtrip;
#[test]
fn test_column_crypto_roundtrip() {
test_roundtrip(ColumnCryptoMetaData::ENCRYPTION_WITH_FOOTER_KEY);
let path_in_schema = vec!["foo".to_owned(), "bar".to_owned(), "really".to_owned()];
let key_metadata = vec![1u8; 32];
test_roundtrip(ColumnCryptoMetaData::ENCRYPTION_WITH_COLUMN_KEY(
EncryptionWithColumnKey {
path_in_schema: path_in_schema.clone(),
key_metadata: None,
},
));
test_roundtrip(ColumnCryptoMetaData::ENCRYPTION_WITH_COLUMN_KEY(
EncryptionWithColumnKey {
path_in_schema,
key_metadata: Some(key_metadata),
},
));
}
}