summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-10-29 18:51:50 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-10-29 18:51:50 +0000
commit4a04f694bfc9eade9b2882b10ef4e157a8616c40 (patch)
treef78321592fa4a0348f917c6209295d0b5ca3ec31
parenta8fcfbeba24145f948b4b9ece4b799b997e86343 (diff)
parent868465084b0d578f02a54d071015bc78cd7a8430 (diff)
Merge "Remove BinaryFileOperations.java and its test from services/core/java/com/android/server/integrity/parser" into main am: 2237e8cac1 am: 868465084b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3324775 Change-Id: I94f80d5927222a05ef487f2749c5d2f023f13a6c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--services/core/java/com/android/server/integrity/parser/BinaryFileOperations.java78
-rw-r--r--services/tests/servicestests/src/com/android/server/integrity/parser/BinaryFileOperationsTest.java116
2 files changed, 0 insertions, 194 deletions
diff --git a/services/core/java/com/android/server/integrity/parser/BinaryFileOperations.java b/services/core/java/com/android/server/integrity/parser/BinaryFileOperations.java
deleted file mode 100644
index f09e035ecc78..000000000000
--- a/services/core/java/com/android/server/integrity/parser/BinaryFileOperations.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.integrity.parser;
-
-import static com.android.server.integrity.model.ComponentBitSize.IS_HASHED_BITS;
-import static com.android.server.integrity.model.ComponentBitSize.VALUE_SIZE_BITS;
-
-import android.content.integrity.IntegrityUtils;
-
-import com.android.server.integrity.model.BitInputStream;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-/**
- * Helper methods for reading standard data structures from {@link BitInputStream}.
- */
-public class BinaryFileOperations {
-
- /**
- * Read an string value with the given size and hash status from a {@code BitInputStream}.
- *
- * If the value is hashed, get the hex-encoding of the value. Serialized values are in raw form.
- * All hashed values are hex-encoded.
- */
- public static String getStringValue(BitInputStream bitInputStream) throws IOException {
- boolean isHashedValue = bitInputStream.getNext(IS_HASHED_BITS) == 1;
- int valueSize = bitInputStream.getNext(VALUE_SIZE_BITS);
- return getStringValue(bitInputStream, valueSize, isHashedValue);
- }
-
- /**
- * Read an string value with the given size and hash status from a {@code BitInputStream}.
- *
- * If the value is hashed, get the hex-encoding of the value. Serialized values are in raw form.
- * All hashed values are hex-encoded.
- */
- public static String getStringValue(
- BitInputStream bitInputStream, int valueSize, boolean isHashedValue)
- throws IOException {
- if (!isHashedValue) {
- StringBuilder value = new StringBuilder();
- while (valueSize-- > 0) {
- value.append((char) bitInputStream.getNext(/* numOfBits= */ 8));
- }
- return value.toString();
- }
- ByteBuffer byteBuffer = ByteBuffer.allocate(valueSize);
- while (valueSize-- > 0) {
- byteBuffer.put((byte) (bitInputStream.getNext(/* numOfBits= */ 8) & 0xFF));
- }
- return IntegrityUtils.getHexDigest(byteBuffer.array());
- }
-
- /** Read an integer value from a {@code BitInputStream}. */
- public static int getIntValue(BitInputStream bitInputStream) throws IOException {
- return bitInputStream.getNext(/* numOfBits= */ 32);
- }
-
- /** Read an boolean value from a {@code BitInputStream}. */
- public static boolean getBooleanValue(BitInputStream bitInputStream) throws IOException {
- return bitInputStream.getNext(/* numOfBits= */ 1) == 1;
- }
-}
diff --git a/services/tests/servicestests/src/com/android/server/integrity/parser/BinaryFileOperationsTest.java b/services/tests/servicestests/src/com/android/server/integrity/parser/BinaryFileOperationsTest.java
deleted file mode 100644
index 723b6c5af451..000000000000
--- a/services/tests/servicestests/src/com/android/server/integrity/parser/BinaryFileOperationsTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.integrity.parser;
-
-import static com.android.server.integrity.model.ComponentBitSize.VALUE_SIZE_BITS;
-import static com.android.server.integrity.parser.BinaryFileOperations.getBooleanValue;
-import static com.android.server.integrity.parser.BinaryFileOperations.getIntValue;
-import static com.android.server.integrity.parser.BinaryFileOperations.getStringValue;
-import static com.android.server.integrity.utils.TestUtils.getBits;
-import static com.android.server.integrity.utils.TestUtils.getBytes;
-import static com.android.server.integrity.utils.TestUtils.getValueBits;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.integrity.IntegrityUtils;
-
-import com.android.server.integrity.model.BitInputStream;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-@RunWith(JUnit4.class)
-public class BinaryFileOperationsTest {
-
- private static final String IS_NOT_HASHED = "0";
- private static final String IS_HASHED = "1";
- private static final String PACKAGE_NAME = "com.test.app";
- private static final String APP_CERTIFICATE = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
-
- @Test
- public void testGetStringValue() throws IOException {
- byte[] stringBytes =
- getBytes(
- IS_NOT_HASHED
- + getBits(PACKAGE_NAME.length(), VALUE_SIZE_BITS)
- + getValueBits(PACKAGE_NAME));
- BitInputStream inputStream = new BitInputStream(new ByteArrayInputStream(stringBytes));
-
- String resultString = getStringValue(inputStream);
-
- assertThat(resultString).isEqualTo(PACKAGE_NAME);
- }
-
- @Test
- public void testGetHashedStringValue() throws IOException {
- byte[] ruleBytes =
- getBytes(
- IS_HASHED
- + getBits(APP_CERTIFICATE.length(), VALUE_SIZE_BITS)
- + getValueBits(APP_CERTIFICATE));
- BitInputStream inputStream = new BitInputStream(new ByteArrayInputStream(ruleBytes));
-
- String resultString = getStringValue(inputStream);
-
- assertThat(resultString)
- .isEqualTo(IntegrityUtils.getHexDigest(
- APP_CERTIFICATE.getBytes(StandardCharsets.UTF_8)));
- }
-
- @Test
- public void testGetStringValue_withSizeAndHashingInfo() throws IOException {
- byte[] ruleBytes = getBytes(getValueBits(PACKAGE_NAME));
- BitInputStream inputStream = new BitInputStream(new ByteArrayInputStream(ruleBytes));
-
- String resultString = getStringValue(inputStream,
- PACKAGE_NAME.length(), /* isHashedValue= */false);
-
- assertThat(resultString).isEqualTo(PACKAGE_NAME);
- }
-
- @Test
- public void testGetIntValue() throws IOException {
- int randomValue = 15;
- byte[] ruleBytes = getBytes(getBits(randomValue, /* numOfBits= */ 32));
- BitInputStream inputStream = new BitInputStream(new ByteArrayInputStream(ruleBytes));
-
- assertThat(getIntValue(inputStream)).isEqualTo(randomValue);
- }
-
- @Test
- public void testGetBooleanValue_true() throws IOException {
- String booleanValue = "1";
- byte[] ruleBytes = getBytes(booleanValue);
- BitInputStream inputStream = new BitInputStream(new ByteArrayInputStream(ruleBytes));
-
- assertThat(getBooleanValue(inputStream)).isEqualTo(true);
- }
-
- @Test
- public void testGetBooleanValue_false() throws IOException {
- String booleanValue = "0";
- byte[] ruleBytes = getBytes(booleanValue);
- BitInputStream inputStream = new BitInputStream(new ByteArrayInputStream(ruleBytes));
-
- assertThat(getBooleanValue(inputStream)).isEqualTo(false);
- }
-}