nastra commented on code in PR #12927: URL: https://github.com/apache/iceberg/pull/12927#discussion_r2068365412
########## core/src/main/java/org/apache/iceberg/EncryptedKeyParser.java: ########## @@ -0,0 +1,75 @@ +/* + * 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 com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonNode; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Base64; +import java.util.Map; +import org.apache.iceberg.encryption.BaseEncryptedKey; +import org.apache.iceberg.encryption.EncryptedKey; +import org.apache.iceberg.util.ByteBuffers; +import org.apache.iceberg.util.JsonUtil; + +public class EncryptedKeyParser { + private static final String KEY_ID = "key-id"; + private static final String KEY_METADATA = "encrypted-key-metadata"; + private static final String ENCRYPTED_BY_ID = "encrypted-by-id"; + private static final String PROPERTIES = "properties"; + + public static String toJson(EncryptedKey key) { + return toJson(key, true); + } + + public static String toJson(EncryptedKey key, boolean pretty) { + return JsonUtil.generate(gen -> toJson(key, gen), pretty); + } + + static void toJson(EncryptedKey key, JsonGenerator generator) throws IOException { + generator.writeStartObject(); + + generator.writeStringField(KEY_ID, key.keyId()); + generator.writeStringField( + KEY_METADATA, + Base64.getEncoder().encodeToString(ByteBuffers.toByteArray(key.encryptedKeyMetadata()))); + generator.writeStringField(ENCRYPTED_BY_ID, key.encryptedById()); + + if (key.properties() != null) { Review Comment: in a bunch of other places we write optional properties only if they aren't empty -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org