You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by gi...@apache.org on 2026/09/15 10:12:07 UTC
(iceberg-rust) 01/01: fix(encryption): return DataInvalid for invalid AES key sizes (#3226)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-3226-5c3d18f4ad22656f7aa13c03657190a0fd5a7d37
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
commit aa5ff7e004b01137010923aaac640532d214f94a
Author: Xander <za...@googlemail.com>
AuthorDate: Tue Sep 15 10:11:42 2026 +0000
fix(encryption): return DataInvalid for invalid AES key sizes (#3226)
`AesKeySize::from_key_length` and `AesKeySize::from_str` returned
`FeatureUnsupported` for anything outside 128/192/256-bit. AES defines no other
key sizes, so these are invalid input rather than something a later version
could support, and `FeatureUnsupported` here is indistinguishable from the
genuinely unsupported cases such as an unknown key metadata version.
`from_key_length` is reachable from `SecureKey::new`,
`StandardKeyMetadata::try_new` and the `encryption.data-key-length` table
property, all of which now surface `DataInvalid`. Messages change from
"Unsupported ..." to "Invalid ..." to match.
---
crates/iceberg/src/encryption/crypto.rs | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/crates/iceberg/src/encryption/crypto.rs b/crates/iceberg/src/encryption/crypto.rs
index 1a4be5354..babdb33bc 100644
--- a/crates/iceberg/src/encryption/crypto.rs
+++ b/crates/iceberg/src/encryption/crypto.rs
@@ -66,8 +66,8 @@ impl AesKeySize {
24 => Ok(Self::Bits192),
32 => Ok(Self::Bits256),
_ => Err(Error::new(
- ErrorKind::FeatureUnsupported,
- format!("Unsupported data key length: {len} (must be 16, 24, or 32)"),
+ ErrorKind::DataInvalid,
+ format!("Invalid data key length: {len} (must be 16, 24, or 32)"),
)),
}
}
@@ -82,8 +82,8 @@ impl FromStr for AesKeySize {
"192" | "AES_GCM_192" | "AES192_GCM" => Ok(Self::Bits192),
"256" | "AES_GCM_256" | "AES256_GCM" => Ok(Self::Bits256),
_ => Err(Error::new(
- ErrorKind::FeatureUnsupported,
- format!("Unsupported AES key size: {s}"),
+ ErrorKind::DataInvalid,
+ format!("Invalid AES key size: {s}"),
)),
}
}
@@ -295,6 +295,15 @@ mod tests {
);
assert!(AesKeySize::from_key_length(8).is_err());
+ for len in [0, 8, 15, 20, 33] {
+ let err = AesKeySize::from_key_length(len).unwrap_err();
+ assert_eq!(err.kind(), ErrorKind::DataInvalid, "for length {len}");
+ assert_eq!(
+ err.message(),
+ format!("Invalid data key length: {len} (must be 16, 24, or 32)")
+ );
+ }
+
assert_eq!(AesKeySize::from_str("128").unwrap(), AesKeySize::Bits128);
assert_eq!(
AesKeySize::from_str("AES_GCM_128").unwrap(),
@@ -304,7 +313,11 @@ mod tests {
AesKeySize::from_str("AES_GCM_256").unwrap(),
AesKeySize::Bits256
);
- assert!(AesKeySize::from_str("INVALID").is_err());
+ for size in ["", "127", "AES_GCM_512", "INVALID"] {
+ let err = AesKeySize::from_str(size).unwrap_err();
+ assert_eq!(err.kind(), ErrorKind::DataInvalid, "for size {size}");
+ assert_eq!(err.message(), format!("Invalid AES key size: {size}"));
+ }
}
#[test]