rdblue commented on code in PR #6450: URL: https://github.com/apache/iceberg/pull/6450#discussion_r1218350263
########## core/src/main/java/org/apache/iceberg/encryption/KeyMetadata.java: ########## @@ -0,0 +1,134 @@ +/* + * 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.encryption; + +import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.apache.iceberg.types.Types.NestedField.required; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.ByteBuffer; +import java.util.Map; +import org.apache.avro.generic.IndexedRecord; +import org.apache.iceberg.Schema; +import org.apache.iceberg.avro.AvroSchemaUtil; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.types.Types; + +class KeyMetadata implements EncryptionKeyMetadata, IndexedRecord { + private static final byte V1 = 1; + private static final Schema SCHEMA_V1 = + new Schema( + required(0, "encryption_key", Types.BinaryType.get()), + optional(1, "aad_prefix", Types.BinaryType.get())); + private static final org.apache.avro.Schema AVRO_SCHEMA_V1 = + AvroSchemaUtil.convert(SCHEMA_V1, KeyMetadata.class.getCanonicalName()); + + private static final Map<Byte, Schema> schemaVersions = ImmutableMap.of(V1, SCHEMA_V1); + private static final Map<Byte, org.apache.avro.Schema> avroSchemaVersions = + ImmutableMap.of(V1, AVRO_SCHEMA_V1); + + private static final KeyMetadataEncoder keyMetadataEncoder = new KeyMetadataEncoder(V1); + private static final KeyMetadataDecoder keyMetadataDecoder = new KeyMetadataDecoder(V1); + + private ByteBuffer encryptionKey; + private ByteBuffer aadPrefix; + private org.apache.avro.Schema avroSchema; + + /** Used by Avro reflection to instantiate this class * */ + KeyMetadata(org.apache.avro.Schema avroSchema) { Review Comment: Since we don't support projection, let's remove this for now to avoid having the Schema class in the API. ########## core/src/main/java/org/apache/iceberg/encryption/KeyMetadata.java: ########## @@ -0,0 +1,134 @@ +/* + * 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.encryption; + +import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.apache.iceberg.types.Types.NestedField.required; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.ByteBuffer; +import java.util.Map; +import org.apache.avro.generic.IndexedRecord; +import org.apache.iceberg.Schema; +import org.apache.iceberg.avro.AvroSchemaUtil; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.types.Types; + +class KeyMetadata implements EncryptionKeyMetadata, IndexedRecord { + private static final byte V1 = 1; + private static final Schema SCHEMA_V1 = + new Schema( + required(0, "encryption_key", Types.BinaryType.get()), + optional(1, "aad_prefix", Types.BinaryType.get())); + private static final org.apache.avro.Schema AVRO_SCHEMA_V1 = + AvroSchemaUtil.convert(SCHEMA_V1, KeyMetadata.class.getCanonicalName()); + + private static final Map<Byte, Schema> schemaVersions = ImmutableMap.of(V1, SCHEMA_V1); + private static final Map<Byte, org.apache.avro.Schema> avroSchemaVersions = + ImmutableMap.of(V1, AVRO_SCHEMA_V1); + + private static final KeyMetadataEncoder keyMetadataEncoder = new KeyMetadataEncoder(V1); + private static final KeyMetadataDecoder keyMetadataDecoder = new KeyMetadataDecoder(V1); + + private ByteBuffer encryptionKey; + private ByteBuffer aadPrefix; + private org.apache.avro.Schema avroSchema; + + /** Used by Avro reflection to instantiate this class * */ + KeyMetadata(org.apache.avro.Schema avroSchema) { + this.avroSchema = avroSchema; + } + + KeyMetadata(ByteBuffer encryptionKey, ByteBuffer aadPrefix) { + this.encryptionKey = encryptionKey; + this.aadPrefix = aadPrefix; + this.avroSchema = AVRO_SCHEMA_V1; + } + + static Map<Byte, Schema> supportedSchemaVersions() { + return schemaVersions; + } + + static Map<Byte, org.apache.avro.Schema> supportedAvroSchemaVersions() { Review Comment: Why is this exposed? I don't think that we want to expose Avro classes in the API. -- 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]
