Alex Buynytskyy | cd4d387 | 2020-02-08 17:50:50 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.os.incremental; |
| 18 | |
| 19 | import java.io.DataInputStream; |
| 20 | import java.io.DataOutputStream; |
| 21 | import java.io.IOException; |
| 22 | |
| 23 | /** |
| 24 | * V4 signature fields. |
| 25 | * Keep in sync with APKSig master copy. |
| 26 | * @hide |
| 27 | */ |
| 28 | public class V4Signature { |
| 29 | public final byte[] verityRootHash; |
| 30 | public final byte[] v3Digest; |
| 31 | public final byte[] pkcs7SignatureBlock; |
| 32 | |
| 33 | V4Signature(byte[] verityRootHash, byte[] v3Digest, byte[] pkcs7SignatureBlock) { |
| 34 | this.verityRootHash = verityRootHash; |
| 35 | this.v3Digest = v3Digest; |
| 36 | this.pkcs7SignatureBlock = pkcs7SignatureBlock; |
| 37 | } |
| 38 | |
| 39 | static byte[] readBytes(DataInputStream stream) throws IOException { |
| 40 | byte[] result = new byte[stream.readInt()]; |
| 41 | stream.read(result); |
| 42 | return result; |
| 43 | } |
| 44 | |
| 45 | static V4Signature readFrom(DataInputStream stream) throws IOException { |
| 46 | byte[] verityRootHash = readBytes(stream); |
| 47 | byte[] v3Digest = readBytes(stream); |
| 48 | byte[] pkcs7SignatureBlock = readBytes(stream); |
| 49 | return new V4Signature(verityRootHash, v3Digest, pkcs7SignatureBlock); |
| 50 | } |
| 51 | |
| 52 | static void writeBytes(DataOutputStream stream, byte[] bytes) throws IOException { |
| 53 | stream.writeInt(bytes.length); |
| 54 | stream.write(bytes); |
| 55 | } |
| 56 | |
| 57 | void writeTo(DataOutputStream stream) throws IOException { |
| 58 | writeBytes(stream, this.verityRootHash); |
| 59 | writeBytes(stream, this.v3Digest); |
| 60 | writeBytes(stream, this.pkcs7SignatureBlock); |
| 61 | } |
| 62 | } |