From 329168c9f3b1e23f440f0c39fca421e1e226c391 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 28 Dec 2021 01:20:05 +0100 Subject: OSTree: Use dictionary types where appropriate. Change-Id: I58be4cbcdd663350d7524ec5ce97f1d3be10d7e1 --- .../main/java/eu/mulk/jgvariant/ostree/Metadata.java | 19 ++++--------------- .../java/eu/mulk/jgvariant/ostree/SignedDelta.java | 17 +++-------------- .../eu/mulk/jgvariant/ostree/SummarySignature.java | 19 ++++--------------- 3 files changed, 11 insertions(+), 44 deletions(-) (limited to 'jgvariant-ostree/src/main/java') diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/Metadata.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/Metadata.java index cf838d3..8bb5255 100644 --- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/Metadata.java +++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/Metadata.java @@ -3,29 +3,18 @@ package eu.mulk.jgvariant.ostree; import eu.mulk.jgvariant.core.Decoder; import eu.mulk.jgvariant.core.Variant; import java.nio.charset.StandardCharsets; -import java.util.List; +import java.util.Map; /** * A wrapper for a list of metadata fields. * *

Reference: (embedded in other data types) */ -public record Metadata(List fields) { - - /** A metadata field with a key and a value. */ - public record Field(String key, Variant value) { - - private static final Decoder DECODER = - Decoder.ofStructure( - Field.class, Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant()); - - public static Decoder decoder() { - return DECODER; - } - } +public record Metadata(Map fields) { private static final Decoder DECODER = - Decoder.ofArray(Field.decoder()).map(Metadata::new); + Decoder.ofDictionary(Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant()) + .map(Metadata::new); public static Decoder decoder() { return DECODER; diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SignedDelta.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SignedDelta.java index 2fc5c25..303e344 100644 --- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SignedDelta.java +++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SignedDelta.java @@ -4,7 +4,7 @@ import eu.mulk.jgvariant.core.Decoder; import eu.mulk.jgvariant.core.Variant; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; -import java.util.List; +import java.util.Map; /** * A {@link DeltaSuperblock} signed with some sort of key. @@ -12,25 +12,14 @@ import java.util.List; *

Reference: {@code ostree-repo-static-delta-private.h#OSTREE_STATIC_DELTA_SIGNED_FORMAT} */ public record SignedDelta( - long magicNumber, ByteString superblock, List signatures) { - - /** A cryptographic signature. */ - public record Signature(String key, Variant data) { - private static final Decoder DECODER = - Decoder.ofStructure( - Signature.class, Decoder.ofString(StandardCharsets.US_ASCII), Decoder.ofVariant()); - - public static Decoder decoder() { - return DECODER; - } - } + long magicNumber, ByteString superblock, Map signatures) { private static final Decoder DECODER = Decoder.ofStructure( SignedDelta.class, Decoder.ofLong().withByteOrder(ByteOrder.BIG_ENDIAN), ByteString.decoder(), - Decoder.ofArray(Signature.decoder())); + Decoder.ofDictionary(Decoder.ofString(StandardCharsets.US_ASCII), Decoder.ofVariant())); public static Decoder decoder() { return DECODER; diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SummarySignature.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SummarySignature.java index a05b96d..13bb432 100644 --- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SummarySignature.java +++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SummarySignature.java @@ -3,7 +3,7 @@ package eu.mulk.jgvariant.ostree; import eu.mulk.jgvariant.core.Decoder; import eu.mulk.jgvariant.core.Variant; import java.nio.charset.StandardCharsets; -import java.util.List; +import java.util.Map; /** * A collection of cryptographic signatures for a {@link Summary}. @@ -12,22 +12,11 @@ import java.util.List; * *

Reference: {@code ostree-repo-static-delta-private.h#OSTREE_SUMMARY_SIG_GVARIANT_STRING} */ -public record SummarySignature(List signatures) { - - /** A cryptographic signature. */ - public record Signature(String key, Variant data) { - - private static final Decoder DECODER = - Decoder.ofStructure( - Signature.class, Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant()); - - public static Decoder decoder() { - return DECODER; - } - } +public record SummarySignature(Map signatures) { private static final Decoder DECODER = - Decoder.ofArray(Signature.decoder()).map(SummarySignature::new); + Decoder.ofDictionary(Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant()) + .map(SummarySignature::new); public static Decoder decoder() { return DECODER; -- cgit v1.2.3