gaborkaszab commented on code in PR #17545: URL: https://github.com/apache/iceberg/pull/17545#discussion_r3853114867
########## api/src/main/java/org/apache/iceberg/EncryptableFile.java: ########## @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg; + +import java.nio.ByteBuffer; +import org.apache.iceberg.encryption.EncryptionManager; + +/** + * A file that may be encrypted. If it is encrypted, its encrypted key metadata is tracked in the + * table metadata encryption keys and is referenced by a key ID. + */ +public interface EncryptableFile { Review Comment: Renamed the interface to `FileWithEncryptedKey` ########## api/src/main/java/org/apache/iceberg/EncryptedFile.java: ########## @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg; + +import java.nio.ByteBuffer; +import org.apache.iceberg.encryption.EncryptionManager; + +/** + * A file that may be encrypted. If it is encrypted, its encrypted key metadata is tracked in the + * table metadata encryption keys and is referenced by a key ID. + */ +public interface EncryptableFile { + + /** Location of the file. */ + String location(); + + /** + * The file key metadata can be encrypted. Returns ID of encryption key or null if it's not + * encrypted. + */ + String encryptionKeyID(); Review Comment: I went through this again, and I think I managed to come up with a solution that isn't a breaking change for custom implementations of `ManifestListFile`. See `EncryptionUtil.decryptKeyMetadata` functions where I introduced a variation that accepts the key ID from the various versions. ########## api/src/main/java/org/apache/iceberg/FileWithEncryptedKey.java: ########## @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg; + +import java.nio.ByteBuffer; +import org.apache.iceberg.encryption.EncryptionManager; + +/** + * A file that may be encrypted. If it is encrypted, its encrypted key metadata is tracked in the + * table metadata encryption keys and is referenced by a key ID. + */ +public interface EncryptedFile { + + /** Location of the file. */ + String location(); + + /** Returns the encryption key ID for this file, or null if the file is not encrypted. */ + String encryptionKeyID(); + + /** Decrypt and return the file key metadata */ + ByteBuffer decryptKeyMetadata(EncryptionManager em); Review Comment: Hmm, with this the only purpose of putting this functionality into `EncryptionManager` is that its implementation in core/ can delegate to `EncryptionUtil` to get around the issue that `EncryptingFileIO.newInputFile()` is in api/ and can't call the util method in core/. I'm not entirely comfortable with that design, while I'm not comfortable with the current one either. At least we keep existing api with the current one. ########## core/src/main/java/org/apache/iceberg/encryption/EncryptionUtil.java: ########## @@ -140,19 +141,33 @@ public static ByteBuffer setFileLength(ByteBuffer keyMetadata, long fileLength) * @param manifestList a ManifestListFile * @param em the table's EncryptionManager * @return a decrypted key metadata buffer + * @deprecated since 1.12.0. Will be removed in 1.13.0; use {@link + * #decryptKeyMetadata(EncryptedFile, EncryptionManager)} instead. */ + @Deprecated public static ByteBuffer decryptManifestListKeyMetadata( ManifestListFile manifestList, EncryptionManager em) { + return decryptKeyMetadata(manifestList, em); + } + + /** + * Decrypt the key metadata of an encryptable file. + * + * @param file an EncryptableFile Review Comment: Thanks for spotting! ########## core/src/main/java/org/apache/iceberg/encryption/EncryptionUtil.java: ########## @@ -140,19 +141,33 @@ public static ByteBuffer setFileLength(ByteBuffer keyMetadata, long fileLength) * @param manifestList a ManifestListFile * @param em the table's EncryptionManager * @return a decrypted key metadata buffer + * @deprecated since 1.12.0. Will be removed in 1.13.0; use {@link Review Comment: Giving this a second thought I think you're right. As long as we keep the ManifestListFile interface (until 2.0.0 as it's in api/) we have to keep the encryption/decryption methods for that class. Otherwise it might be a behavior change for custom implementation if we silently fall back to the method for `EncryptedFile`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
