flyrain commented on a change in pull request #3471:
URL: https://github.com/apache/iceberg/pull/3471#discussion_r806182078



##########
File path: 
core/src/main/java/org/apache/iceberg/encryption/EnvelopeMetadata.java
##########
@@ -0,0 +1,142 @@
+/*
+ * 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 java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Objects;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/**
+ * Envelope encryption metadata used to encrypt and decrypt data.
+ * Information except plaintext KEK and DEK can be serialized and stored.
+ */
+public class EnvelopeMetadata implements EncryptionKeyMetadata {
+
+  private final String kekId;
+  private final String wrappedDek;
+  private final byte[] iv;
+  private final EncryptionAlgorithm algorithm;
+
+  // fields that are expected to be updated later
+  private byte[] kek;
+  private byte[] dek;
+
+  public EnvelopeMetadata(
+          String kekId,
+          String wrappedDek,
+          ByteBuffer iv,
+          EncryptionAlgorithm algorithm) {
+    this.kekId = Preconditions.checkNotNull(kekId,
+            "Cannot construct envelope metadata because KEK ID is not 
specified");
+    this.wrappedDek = wrappedDek;
+    this.iv = iv == null ? null : iv.array();
+    this.algorithm = Preconditions.checkNotNull(algorithm,
+              "Cannot construct envelope metadata because encryption algorithm 
is not specified");
+  }
+
+  public String kekId() {
+    return kekId;
+  }
+
+  public ByteBuffer kek() {
+    return kek == null ? null : ByteBuffer.wrap(kek);
+  }
+
+  public ByteBuffer dek() {
+    return dek == null ? null : ByteBuffer.wrap(dek);
+  }
+
+  public String wrappedDek() {
+    return wrappedDek;
+  }
+
+  public ByteBuffer iv() {
+    return iv == null ? null : ByteBuffer.wrap(iv);
+  }
+
+  public EncryptionAlgorithm algorithm() {
+    return algorithm;
+  }
+
+  public void setKek(ByteBuffer kekBuffer) {
+    this.kek = kekBuffer == null ? null : kekBuffer.array();
+  }
+
+  public void setDek(ByteBuffer dekBuffer) {
+    this.dek = dekBuffer == null ? null : dekBuffer.array();
+  }
+
+  @Override
+  public ByteBuffer buffer() {
+    return EnvelopeMetadataParser.toJson(this);
+  }
+
+  @Override
+  public EncryptionKeyMetadata copy() {
+    EnvelopeMetadata metadata = new EnvelopeMetadata(kekId(), wrappedDek(),
+            iv(), algorithm());
+    metadata.setDek(dek());
+    metadata.setKek(kek());
+    return metadata;
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+
+    if (other == null || getClass() != other.getClass()) {
+      return false;
+    }
+
+    EnvelopeMetadata metadata = (EnvelopeMetadata) other;
+    return  Objects.equals(kekId, metadata.kekId) &&

Review comment:
       Nit: extra space after `return`




-- 
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]

Reply via email to