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