Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethhealy committed Nov 20, 2024
1 parent 1a2d59a commit 962d5d0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 81 deletions.
79 changes: 0 additions & 79 deletions sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.opentdf.platform.sdk;

import com.google.gson.*;
// import com.google.gson.reflect.TypeToken;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.nimbusds.jose.*;
Expand All @@ -12,15 +11,10 @@
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;

// import io.opentdf.platform.sdk.Manifest.ManifestDeserializer;
import io.opentdf.platform.sdk.TDF.AssertionException;

import org.apache.commons.codec.binary.Hex;
import org.erdtman.jcs.JsonCanonicalizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.Reader;
Expand Down Expand Up @@ -462,92 +456,19 @@ private JWSVerifier createVerifier(AssertionConfig.AssertionKey assertionKey) th
}
}

// // Cpublic static Logger logger = LoggerFactory.getLogger(TDF.class);ustom deserializer for the assertions field
// private static class AssertionSerializer implements JsonDeserializer<Object>, JsonSerializer<Object> {
// public static Logger logger = LoggerFactory.getLogger(AssertionSerializer.class);
// @Override
// public List<Assertion> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
// logger.info("deserializing json assertions");
// logger.info(json.toString());
// if (json == null || json.isJsonNull()) {
// logger.info("found null");
// return new ArrayList<>(); // Replace null with an empty list
// }
// // Deserialize the list normally if it exists
// return new Gson().fromJson(json, typeOfT);
// }
// @Override
// public JsonElement serialize(Object src, Type typeOfSrc, JsonSerializationContext context) {
// return context.serialize(src, typeOfSrc);
// }
// }

// private static class PolicyBindingSerializer implements JsonDeserializer<Object>, JsonSerializer<Object> {
// @Override
// public Object deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
// throws JsonParseException {
// if (json.isJsonObject()) {
// return context.deserialize(json, Manifest.PolicyBinding.class);
// } else if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) {
// return json.getAsString();
// } else {
// throw new JsonParseException("Unexpected type for policyBinding");
// }
// }

// @Override
// public JsonElement serialize(Object src, Type typeOfSrc, JsonSerializationContext context) {
// return context.serialize(src, typeOfSrc);
// }
// }

public EncryptionInformation encryptionInformation;
public Payload payload;
// @JsonAdapter(AssertionSerializer.class)
public List<Assertion> assertions = new ArrayList<>();

// // Ensure assertions is never null after deserialization
// private Object readResolve() {
// if (assertions == null) {
// assertions = new ArrayList<>();
// }
// return this;
// }

// @JsonAdapter(ManifestDeserializer.class)
// class ManifestDeserializer implements JsonDeserializer<Manifest> {
// @Override
// public Manifest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
// JsonObject jsonObject = json.getAsJsonObject();
// Manifest manifest = new Manifest();

// // Handle the `assertions` field, replacing null with an empty list
// JsonElement assertionsElement = jsonObject.get("assertions");
// if (assertionsElement == null || assertionsElement.isJsonNull()) {
// manifest.assertions = new ArrayList<>();
// } else {
// // Deserialize the list normally
// manifest.assertions = new Gson().fromJson(assertionsElement, new TypeToken<List<Assertion>>() {}.getType()); }

// return manifest;
// }
// }

public static class ManifestDeserializer implements JsonDeserializer<Object> {
public static Logger logger = LoggerFactory.getLogger(ManifestDeserializer.class);
@Override
public Manifest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
logger.info("deserializing manifest");
// Let Gson handle the default deserialization of the object first
Manifest manifest = new Gson().fromJson(json, typeOfT);
logger.info("after gson");
// Now check if the `assertions` field is null and replace it with an empty list if necessary
if (manifest.assertions == null) {
logger.info("found null");
manifest.assertions = new ArrayList<>(); // Replace null with empty list
}
logger.info(manifest.assertions.toString());

return manifest;
}
}
Expand Down
2 changes: 0 additions & 2 deletions sdk/src/main/java/io/opentdf/platform/sdk/TDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,6 @@ public Reader loadTDF(SeekableByteChannel tdf, SDK.KAS kas,
}

// Validate assertions
logger.info("ASS:");
logger.info(manifest.assertions.toString());
for (var assertion : manifest.assertions) {
// Skip assertion verification if disabled
if (tdfReaderConfig.disableAssertionVerification) {
Expand Down

0 comments on commit 962d5d0

Please sign in to comment.