Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 1 | package eu.mulk.jgvariant.ostree; |
| 2 | |
| 3 | import eu.mulk.jgvariant.core.Decoder; |
| 4 | import eu.mulk.jgvariant.core.Variant; |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 5 | import java.nio.ByteBuffer; |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 6 | import java.nio.ByteOrder; |
| 7 | import java.nio.charset.StandardCharsets; |
Matthias Andreas Benkard | 329168c | 2021-12-28 01:20:05 +0100 | [diff] [blame] | 8 | import java.util.Map; |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * A {@link DeltaSuperblock} signed with some sort of key. |
| 12 | * |
| 13 | * <p>Reference: {@code ostree-repo-static-delta-private.h#OSTREE_STATIC_DELTA_SIGNED_FORMAT} |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 14 | * |
| 15 | * @param magicNumber the value {@link #MAGIC}. |
| 16 | * @param superblock the {@link DeltaSuperblock}. |
| 17 | * @param signatures a list of signatures, indexed by type. |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 18 | */ |
| 19 | public record SignedDelta( |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 20 | long magicNumber, DeltaSuperblock superblock, Map<String, Variant> signatures) { |
| 21 | |
| 22 | /** The value of {@link #magicNumber()}. */ |
| 23 | public static final long MAGIC = 0x4F53_5453_474E_4454L; |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 24 | |
| 25 | private static final Decoder<SignedDelta> DECODER = |
| 26 | Decoder.ofStructure( |
| 27 | SignedDelta.class, |
| 28 | Decoder.ofLong().withByteOrder(ByteOrder.BIG_ENDIAN), |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 29 | ByteString.decoder().map(SignedDelta::decodeSuperblock), |
Matthias Andreas Benkard | 329168c | 2021-12-28 01:20:05 +0100 | [diff] [blame] | 30 | Decoder.ofDictionary(Decoder.ofString(StandardCharsets.US_ASCII), Decoder.ofVariant())); |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 31 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 32 | private static DeltaSuperblock decodeSuperblock(ByteString byteString) { |
| 33 | return DeltaSuperblock.decoder().decode(ByteBuffer.wrap(byteString.bytes())); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Acquires a {@link Decoder} for the enclosing type. |
| 38 | * |
| 39 | * @return a possibly shared {@link Decoder}. |
| 40 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 41 | public static Decoder<SignedDelta> decoder() { |
| 42 | return DECODER; |
| 43 | } |
| 44 | } |