diff --git a/src/main/java/com/google/crypto/tink/hybrid/internal/BUILD.bazel b/src/main/java/com/google/crypto/tink/hybrid/internal/BUILD.bazel index 2d19f4df4..64c6106c5 100644 --- a/src/main/java/com/google/crypto/tink/hybrid/internal/BUILD.bazel +++ b/src/main/java/com/google/crypto/tink/hybrid/internal/BUILD.bazel @@ -103,7 +103,6 @@ java_library( "//src/main/java/com/google/crypto/tink:hybrid_encrypt", "//src/main/java/com/google/crypto/tink/hybrid:hpke_parameters", "//src/main/java/com/google/crypto/tink/hybrid:hpke_public_key", - "//src/main/java/com/google/crypto/tink/subtle:bytes", "//src/main/java/com/google/crypto/tink/subtle:elliptic_curves", "//src/main/java/com/google/crypto/tink/util:bytes", "@maven//:com_google_errorprone_error_prone_annotations", @@ -379,7 +378,6 @@ android_library( "//src/main/java/com/google/crypto/tink:hybrid_encrypt-android", "//src/main/java/com/google/crypto/tink/hybrid:hpke_parameters-android", "//src/main/java/com/google/crypto/tink/hybrid:hpke_public_key-android", - "//src/main/java/com/google/crypto/tink/subtle:bytes-android", "//src/main/java/com/google/crypto/tink/subtle:elliptic_curves-android", "//src/main/java/com/google/crypto/tink/util:bytes-android", "@maven//:com_google_errorprone_error_prone_annotations", diff --git a/src/main/java/com/google/crypto/tink/internal/testing/BUILD.bazel b/src/main/java/com/google/crypto/tink/internal/testing/BUILD.bazel index 1e0225066..f383ca3b5 100644 --- a/src/main/java/com/google/crypto/tink/internal/testing/BUILD.bazel +++ b/src/main/java/com/google/crypto/tink/internal/testing/BUILD.bazel @@ -92,3 +92,15 @@ java_library( name = "big_integer_test_util", srcs = ["BigIntegerTestUtil.java"], ) + +java_library( + name = "test_files", + srcs = ["TestFiles.java"], + deps = ["//src/main/java/com/google/crypto/tink/testing:test_util"], +) + +android_library( + name = "test_files-android", + srcs = ["TestFiles.java"], + deps = ["//src/main/java/com/google/crypto/tink/testing:test_util-android"], +) diff --git a/src/main/java/com/google/crypto/tink/internal/testing/TestFiles.java b/src/main/java/com/google/crypto/tink/internal/testing/TestFiles.java new file mode 100644 index 000000000..829caf8bd --- /dev/null +++ b/src/main/java/com/google/crypto/tink/internal/testing/TestFiles.java @@ -0,0 +1,39 @@ +// Copyright 2024 Google LLC +// +// 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 specified language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package com.google.crypto.tink.internal.testing; + +import com.google.crypto.tink.testing.TestUtil; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; + +/** Helper functions for reading test files. */ +public final class TestFiles { + + /** Provides an InputStream to a test file. */ + public static InputStream openInputFile(String pathname) throws FileNotFoundException { + String path = pathname; + if (TestUtil.isAndroid()) { + // TODO(juerg): Use the PlatformTestStorage API on Android. + path = "/sdcard/googletest/test_runfiles/google3/" + path; // Special prefix for Android. + } + return new FileInputStream(new File(path)); + } + + private TestFiles() {} +} diff --git a/src/main/java/com/google/crypto/tink/testing/BUILD.bazel b/src/main/java/com/google/crypto/tink/testing/BUILD.bazel index 6787efa46..a730c65bb 100644 --- a/src/main/java/com/google/crypto/tink/testing/BUILD.bazel +++ b/src/main/java/com/google/crypto/tink/testing/BUILD.bazel @@ -120,7 +120,7 @@ java_library( name = "wycheproof_test_util", srcs = ["WycheproofTestUtil.java"], deps = [ - ":test_util", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files", "//src/main/java/com/google/crypto/tink/subtle:elliptic_curves", "//src/main/java/com/google/crypto/tink/subtle:enums", "@maven//:com_google_code_gson_gson", @@ -131,7 +131,7 @@ android_library( name = "wycheproof_test_util-android", srcs = ["WycheproofTestUtil.java"], deps = [ - ":test_util-android", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files-android", "//src/main/java/com/google/crypto/tink/subtle:elliptic_curves-android", "//src/main/java/com/google/crypto/tink/subtle:enums-android", "@maven//:com_google_code_gson_gson", diff --git a/src/main/java/com/google/crypto/tink/testing/WycheproofTestUtil.java b/src/main/java/com/google/crypto/tink/testing/WycheproofTestUtil.java index 672119a58..1e5edb11c 100644 --- a/src/main/java/com/google/crypto/tink/testing/WycheproofTestUtil.java +++ b/src/main/java/com/google/crypto/tink/testing/WycheproofTestUtil.java @@ -16,14 +16,13 @@ package com.google.crypto.tink.testing; +import com.google.crypto.tink.internal.testing.TestFiles; import com.google.crypto.tink.subtle.EllipticCurves; import com.google.crypto.tink.subtle.Enums.HashType; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; @@ -91,15 +90,9 @@ private static byte[] readAll(InputStream inputStream) throws IOException { /** Gets JsonObject from file. */ public static JsonObject readJson(String path) throws Exception { - String filePath = path; - if (TestUtil.isAndroid()) { - // TODO(b/67385998): make this work outside google3. - filePath = "/sdcard/googletest/test_runfiles/google3/" + path; - } JsonObject result; - try (FileInputStream fileInputStream = new FileInputStream(new File(filePath))) { - result = - JsonParser.parseString(new String(readAll(fileInputStream), UTF_8)).getAsJsonObject(); + try (InputStream inputStream = TestFiles.openInputFile(path)) { + result = JsonParser.parseString(new String(readAll(inputStream), UTF_8)).getAsJsonObject(); } String algorithm = result.get("algorithm").getAsString(); String generatorVersion = result.get("generatorVersion").getAsString(); diff --git a/src/test/java/com/google/crypto/tink/hybrid/internal/AesGcmHpkeAeadTest.java b/src/test/java/com/google/crypto/tink/hybrid/internal/AesGcmHpkeAeadTest.java index 8438aef01..4cacd8bee 100644 --- a/src/test/java/com/google/crypto/tink/hybrid/internal/AesGcmHpkeAeadTest.java +++ b/src/test/java/com/google/crypto/tink/hybrid/internal/AesGcmHpkeAeadTest.java @@ -19,16 +19,15 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertThrows; -import com.google.common.io.Files; import com.google.common.truth.Expect; +import com.google.crypto.tink.internal.testing.TestFiles; import com.google.crypto.tink.testing.HpkeTestEncryption; import com.google.crypto.tink.testing.HpkeTestId; import com.google.crypto.tink.testing.HpkeTestSetup; import com.google.crypto.tink.testing.HpkeTestUtil; import com.google.crypto.tink.testing.HpkeTestVector; -import com.google.crypto.tink.testing.TestUtil; -import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.security.GeneralSecurityException; import java.security.InvalidAlgorithmParameterException; import java.util.List; @@ -49,10 +48,8 @@ public final class AesGcmHpkeAeadTest { @BeforeClass public static void setUpTestVectors() throws IOException { String path = "testdata/testvectors/hpke_boringssl.json"; - if (TestUtil.isAndroid()) { - path = "/sdcard/googletest/test_runfiles/google3/" + path; // Special prefix for Android. - } - testVectors = HpkeTestUtil.parseTestVectors(Files.newReader(new File(path), UTF_8)); + testVectors = + HpkeTestUtil.parseTestVectors(new InputStreamReader(TestFiles.openInputFile(path), UTF_8)); } private HpkeTestVector getTestVector(byte[] mode, byte[] kemId, byte[] kdfId, byte[] aeadId) { diff --git a/src/test/java/com/google/crypto/tink/hybrid/internal/BUILD.bazel b/src/test/java/com/google/crypto/tink/hybrid/internal/BUILD.bazel index 4ae5c61ba..4d36b833c 100644 --- a/src/test/java/com/google/crypto/tink/hybrid/internal/BUILD.bazel +++ b/src/test/java/com/google/crypto/tink/hybrid/internal/BUILD.bazel @@ -10,9 +10,8 @@ java_test( deps = [ "//src/main/java/com/google/crypto/tink/hybrid/internal:aes_gcm_hpke_aead", "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_util", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files", "//src/main/java/com/google/crypto/tink/testing:hpke_test_util", - "//src/main/java/com/google/crypto/tink/testing:test_util", - "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], @@ -26,9 +25,8 @@ java_test( deps = [ "//src/main/java/com/google/crypto/tink/hybrid/internal:chacha20_poly1305_hpke_aead", "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_util", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files", "//src/main/java/com/google/crypto/tink/testing:hpke_test_util", - "//src/main/java/com/google/crypto/tink/testing:test_util", - "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], @@ -42,12 +40,11 @@ java_test( deps = [ "//src/main/java/com/google/crypto/tink/hybrid/internal:hkdf_hpke_kdf", "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_util", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files", "//src/main/java/com/google/crypto/tink/subtle:bytes", "//src/main/java/com/google/crypto/tink/subtle:hex", "//src/main/java/com/google/crypto/tink/subtle:x25519", "//src/main/java/com/google/crypto/tink/testing:hpke_test_util", - "//src/main/java/com/google/crypto/tink/testing:test_util", - "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], @@ -71,12 +68,11 @@ java_test( "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_kem_private_key", "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_primitive_factory", "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_util", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files", "//src/main/java/com/google/crypto/tink/subtle:random", "//src/main/java/com/google/crypto/tink/testing:hpke_test_util", - "//src/main/java/com/google/crypto/tink/testing:test_util", "//src/main/java/com/google/crypto/tink/util:bytes", "//src/main/java/com/google/crypto/tink/util:secret_bytes", - "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], @@ -121,11 +117,10 @@ java_test( "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_kem_key_factory", "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_kem_private_key", "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_util", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files", "//src/main/java/com/google/crypto/tink/testing:hpke_test_util", - "//src/main/java/com/google/crypto/tink/testing:test_util", "//src/main/java/com/google/crypto/tink/util:bytes", "//src/main/java/com/google/crypto/tink/util:secret_bytes", - "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], @@ -193,12 +188,11 @@ java_test( "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_util", "//src/main/java/com/google/crypto/tink/hybrid/internal:nist_curves_hpke_kem", "//src/main/java/com/google/crypto/tink/hybrid/internal:nist_curves_hpke_kem_private_key", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files", "//src/main/java/com/google/crypto/tink/subtle:elliptic_curves", "//src/main/java/com/google/crypto/tink/testing:hpke_test_util", - "//src/main/java/com/google/crypto/tink/testing:test_util", "//src/main/java/com/google/crypto/tink/util:bytes", "//src/main/java/com/google/crypto/tink/util:secret_bytes", - "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], @@ -229,9 +223,8 @@ java_test( "//src/main/java/com/google/crypto/tink/hybrid/internal:hpke_util", "//src/main/java/com/google/crypto/tink/hybrid/internal:x25519_hpke_kem", "//src/main/java/com/google/crypto/tink/hybrid/internal:x25519_hpke_kem_private_key", + "//src/main/java/com/google/crypto/tink/internal/testing:test_files", "//src/main/java/com/google/crypto/tink/testing:hpke_test_util", - "//src/main/java/com/google/crypto/tink/testing:test_util", - "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], diff --git a/src/test/java/com/google/crypto/tink/hybrid/internal/ChaCha20Poly1305HpkeAeadTest.java b/src/test/java/com/google/crypto/tink/hybrid/internal/ChaCha20Poly1305HpkeAeadTest.java index 59308e7a6..6c4f0c062 100644 --- a/src/test/java/com/google/crypto/tink/hybrid/internal/ChaCha20Poly1305HpkeAeadTest.java +++ b/src/test/java/com/google/crypto/tink/hybrid/internal/ChaCha20Poly1305HpkeAeadTest.java @@ -19,16 +19,15 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertThrows; -import com.google.common.io.Files; import com.google.common.truth.Expect; +import com.google.crypto.tink.internal.testing.TestFiles; import com.google.crypto.tink.testing.HpkeTestEncryption; import com.google.crypto.tink.testing.HpkeTestId; import com.google.crypto.tink.testing.HpkeTestSetup; import com.google.crypto.tink.testing.HpkeTestUtil; import com.google.crypto.tink.testing.HpkeTestVector; -import com.google.crypto.tink.testing.TestUtil; -import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.security.GeneralSecurityException; import java.security.InvalidAlgorithmParameterException; import java.util.List; @@ -49,10 +48,8 @@ public final class ChaCha20Poly1305HpkeAeadTest { @BeforeClass public static void setUpTestVectors() throws IOException { String path = "testdata/testvectors/hpke_boringssl.json"; - if (TestUtil.isAndroid()) { - path = "/sdcard/googletest/test_runfiles/google3/" + path; // Special prefix for Android. - } - testVectors = HpkeTestUtil.parseTestVectors(Files.newReader(new File(path), UTF_8)); + testVectors = + HpkeTestUtil.parseTestVectors(new InputStreamReader(TestFiles.openInputFile(path), UTF_8)); } private HpkeTestVector getTestVector(byte[] mode, byte[] kemId, byte[] kdfId, byte[] aeadId) { diff --git a/src/test/java/com/google/crypto/tink/hybrid/internal/HkdfHpkeKdfTest.java b/src/test/java/com/google/crypto/tink/hybrid/internal/HkdfHpkeKdfTest.java index 3812eb3bf..c9b8797ee 100644 --- a/src/test/java/com/google/crypto/tink/hybrid/internal/HkdfHpkeKdfTest.java +++ b/src/test/java/com/google/crypto/tink/hybrid/internal/HkdfHpkeKdfTest.java @@ -19,8 +19,8 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertThrows; -import com.google.common.io.Files; import com.google.common.truth.Expect; +import com.google.crypto.tink.internal.testing.TestFiles; import com.google.crypto.tink.subtle.Bytes; import com.google.crypto.tink.subtle.Hex; import com.google.crypto.tink.subtle.X25519; @@ -28,9 +28,8 @@ import com.google.crypto.tink.testing.HpkeTestSetup; import com.google.crypto.tink.testing.HpkeTestUtil; import com.google.crypto.tink.testing.HpkeTestVector; -import com.google.crypto.tink.testing.TestUtil; -import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.security.GeneralSecurityException; import java.security.NoSuchAlgorithmException; import java.util.Map; @@ -54,10 +53,8 @@ public final class HkdfHpkeKdfTest { @BeforeClass public static void setUpTestVectors() throws IOException { String path = "testdata/testvectors/hpke_boringssl.json"; - if (TestUtil.isAndroid()) { - path = "/sdcard/googletest/test_runfiles/google3/" + path; // Special prefix for Android. - } - testVectors = HpkeTestUtil.parseTestVectors(Files.newReader(new File(path), UTF_8)); + testVectors = + HpkeTestUtil.parseTestVectors(new InputStreamReader(TestFiles.openInputFile(path), UTF_8)); } private HpkeTestSetup getTestSetup(byte[] mode, byte[] kemId, byte[] kdfId, byte[] aeadId) { diff --git a/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeContextTest.java b/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeContextTest.java index b5478a8ad..b7d5b236a 100644 --- a/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeContextTest.java +++ b/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeContextTest.java @@ -18,23 +18,22 @@ import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.common.io.Files; import com.google.common.truth.Expect; import com.google.crypto.tink.InsecureSecretKeyAccess; import com.google.crypto.tink.hybrid.HpkeParameters; import com.google.crypto.tink.hybrid.HpkePrivateKey; import com.google.crypto.tink.hybrid.HpkePublicKey; +import com.google.crypto.tink.internal.testing.TestFiles; import com.google.crypto.tink.subtle.Random; import com.google.crypto.tink.testing.HpkeTestEncryption; import com.google.crypto.tink.testing.HpkeTestId; import com.google.crypto.tink.testing.HpkeTestSetup; import com.google.crypto.tink.testing.HpkeTestUtil; import com.google.crypto.tink.testing.HpkeTestVector; -import com.google.crypto.tink.testing.TestUtil; import com.google.crypto.tink.util.Bytes; import com.google.crypto.tink.util.SecretBytes; -import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.security.GeneralSecurityException; import java.util.Map; import org.junit.BeforeClass; @@ -53,10 +52,8 @@ public final class HpkeContextTest { @BeforeClass public static void setUpTestVectors() throws IOException { String path = "testdata/testvectors/hpke_boringssl.json"; - if (TestUtil.isAndroid()) { - path = "/sdcard/googletest/test_runfiles/google3/" + path; // Special prefix for Android. - } - testVectors = HpkeTestUtil.parseTestVectors(Files.newReader(new File(path), UTF_8)); + testVectors = + HpkeTestUtil.parseTestVectors(new InputStreamReader(TestFiles.openInputFile(path), UTF_8)); } private HpkeTestVector getTestVector(byte[] mode, byte[] kemId, byte[] kdfId, byte[] aeadId) { diff --git a/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeKemKeyFactoryTest.java b/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeKemKeyFactoryTest.java index c54ce5207..2e55c3bd1 100644 --- a/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeKemKeyFactoryTest.java +++ b/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeKemKeyFactoryTest.java @@ -18,21 +18,20 @@ import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.common.io.Files; import com.google.common.truth.Expect; import com.google.crypto.tink.InsecureSecretKeyAccess; import com.google.crypto.tink.hybrid.HpkeParameters; import com.google.crypto.tink.hybrid.HpkePrivateKey; import com.google.crypto.tink.hybrid.HpkePublicKey; +import com.google.crypto.tink.internal.testing.TestFiles; import com.google.crypto.tink.testing.HpkeTestId; import com.google.crypto.tink.testing.HpkeTestSetup; import com.google.crypto.tink.testing.HpkeTestUtil; import com.google.crypto.tink.testing.HpkeTestVector; -import com.google.crypto.tink.testing.TestUtil; import com.google.crypto.tink.util.Bytes; import com.google.crypto.tink.util.SecretBytes; -import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.security.GeneralSecurityException; import java.util.Map; import org.junit.BeforeClass; @@ -52,10 +51,8 @@ public final class HpkeKemKeyFactoryTest { @BeforeClass public static void setUpTestVectors() throws IOException { String path = "testdata/testvectors/hpke_boringssl.json"; - if (TestUtil.isAndroid()) { - path = "/sdcard/googletest/test_runfiles/google3/" + path; // Special prefix for Android. - } - testVectors = HpkeTestUtil.parseTestVectors(Files.newReader(new File(path), UTF_8)); + testVectors = + HpkeTestUtil.parseTestVectors(new InputStreamReader(TestFiles.openInputFile(path), UTF_8)); } private HpkePrivateKey createHpkePrivateKey(byte[] kemIdBytes, HpkeParameters.KemId kemId) diff --git a/src/test/java/com/google/crypto/tink/hybrid/internal/NistCurvesHpkeKemTest.java b/src/test/java/com/google/crypto/tink/hybrid/internal/NistCurvesHpkeKemTest.java index 8fa4d8a6c..94be6d12a 100644 --- a/src/test/java/com/google/crypto/tink/hybrid/internal/NistCurvesHpkeKemTest.java +++ b/src/test/java/com/google/crypto/tink/hybrid/internal/NistCurvesHpkeKemTest.java @@ -19,23 +19,22 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertThrows; -import com.google.common.io.Files; import com.google.common.truth.Expect; import com.google.crypto.tink.InsecureSecretKeyAccess; import com.google.crypto.tink.hybrid.HpkeParameters; import com.google.crypto.tink.hybrid.HpkePrivateKey; import com.google.crypto.tink.hybrid.HpkePublicKey; +import com.google.crypto.tink.internal.testing.TestFiles; import com.google.crypto.tink.subtle.EllipticCurves; import com.google.crypto.tink.subtle.EllipticCurves.PointFormatType; import com.google.crypto.tink.testing.HpkeTestId; import com.google.crypto.tink.testing.HpkeTestSetup; import com.google.crypto.tink.testing.HpkeTestUtil; import com.google.crypto.tink.testing.HpkeTestVector; -import com.google.crypto.tink.testing.TestUtil; import com.google.crypto.tink.util.Bytes; import com.google.crypto.tink.util.SecretBytes; -import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.security.GeneralSecurityException; import java.security.KeyPair; import java.security.interfaces.ECPrivateKey; @@ -59,10 +58,8 @@ public final class NistCurvesHpkeKemTest { @BeforeClass public static void setUpTestVectors() throws IOException { String path = "testdata/testvectors/hpke_boringssl.json"; - if (TestUtil.isAndroid()) { - path = "/sdcard/googletest/test_runfiles/google3/" + path; // Special prefix for Android. - } - testVectors = HpkeTestUtil.parseTestVectors(Files.newReader(new File(path), UTF_8)); + testVectors = + HpkeTestUtil.parseTestVectors(new InputStreamReader(TestFiles.openInputFile(path), UTF_8)); } private static final class HpkeKemParams { diff --git a/src/test/java/com/google/crypto/tink/hybrid/internal/X25519HpkeKemTest.java b/src/test/java/com/google/crypto/tink/hybrid/internal/X25519HpkeKemTest.java index d76f922a5..8928e6ab4 100644 --- a/src/test/java/com/google/crypto/tink/hybrid/internal/X25519HpkeKemTest.java +++ b/src/test/java/com/google/crypto/tink/hybrid/internal/X25519HpkeKemTest.java @@ -19,15 +19,14 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertThrows; -import com.google.common.io.Files; import com.google.common.truth.Expect; +import com.google.crypto.tink.internal.testing.TestFiles; import com.google.crypto.tink.testing.HpkeTestId; import com.google.crypto.tink.testing.HpkeTestSetup; import com.google.crypto.tink.testing.HpkeTestUtil; import com.google.crypto.tink.testing.HpkeTestVector; -import com.google.crypto.tink.testing.TestUtil; -import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.security.GeneralSecurityException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -52,10 +51,8 @@ public final class X25519HpkeKemTest { @BeforeClass public static void setUpTestVectors() throws IOException { String path = "testdata/testvectors/hpke_boringssl.json"; - if (TestUtil.isAndroid()) { - path = "/sdcard/googletest/test_runfiles/google3/" + path; // Special prefix for Android. - } - testVectors = HpkeTestUtil.parseTestVectors(Files.newReader(new File(path), UTF_8)); + testVectors = + HpkeTestUtil.parseTestVectors(new InputStreamReader(TestFiles.openInputFile(path), UTF_8)); } private HpkeTestId getDefaultTestId(byte[] mode) {