diff options
author | tholenst <tholenst@google.com> | 2023-06-12 04:21:35 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-06-12 04:22:39 -0700 |
commit | 3745725ef1901f96229b959462e2192aa7b19b1c (patch) | |
tree | 61c99620f3b801779057e292f1270f78bb481b2f /tools | |
parent | 922f215c2cb0745cc00d684dae957b2d3543b0f9 (diff) | |
download | tink-3745725ef1901f96229b959462e2192aa7b19b1c.tar.gz |
Use TinkProtoKeysetFormat instead of readers in CliUtil.
PiperOrigin-RevId: 539610471
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/BUILD.bazel | 5 | ||||
-rw-r--r-- | tools/testing/java/com/google/crypto/tink/testing/CliUtil.java | 18 |
2 files changed, 12 insertions, 11 deletions
diff --git a/tools/testing/BUILD.bazel b/tools/testing/BUILD.bazel index 237998aa4..12b9a516b 100644 --- a/tools/testing/BUILD.bazel +++ b/tools/testing/BUILD.bazel @@ -9,10 +9,9 @@ java_library( "java/com/google/crypto/tink/testing/CliUtil.java", ], deps = [ - "@tink_java//src/main/java/com/google/crypto/tink:binary_keyset_reader", - "@tink_java//src/main/java/com/google/crypto/tink:binary_keyset_writer", - "@tink_java//src/main/java/com/google/crypto/tink:cleartext_keyset_handle", + "@tink_java//src/main/java/com/google/crypto/tink:insecure_secret_key_access", "@tink_java//src/main/java/com/google/crypto/tink:registry_cluster", + "@tink_java//src/main/java/com/google/crypto/tink:tink_proto_keyset_format", "@tink_java//src/main/java/com/google/crypto/tink/config:tink_config", "@tink_java//src/main/java/com/google/crypto/tink/daead:deterministic_aead_config", "@tink_java//src/main/java/com/google/crypto/tink/hybrid:hybrid_config", diff --git a/tools/testing/java/com/google/crypto/tink/testing/CliUtil.java b/tools/testing/java/com/google/crypto/tink/testing/CliUtil.java index 617e6c128..cd9e051c1 100644 --- a/tools/testing/java/com/google/crypto/tink/testing/CliUtil.java +++ b/tools/testing/java/com/google/crypto/tink/testing/CliUtil.java @@ -16,10 +16,9 @@ package com.google.crypto.tink.testing; -import com.google.crypto.tink.BinaryKeysetReader; -import com.google.crypto.tink.BinaryKeysetWriter; -import com.google.crypto.tink.CleartextKeysetHandle; +import com.google.crypto.tink.InsecureSecretKeyAccess; import com.google.crypto.tink.KeysetHandle; +import com.google.crypto.tink.TinkProtoKeysetFormat; import com.google.crypto.tink.daead.DeterministicAeadConfig; import com.google.crypto.tink.hybrid.HybridConfig; import com.google.crypto.tink.keyderivation.KeyDerivationConfig; @@ -33,6 +32,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; +import java.nio.file.Files; import java.nio.file.Paths; import java.security.GeneralSecurityException; @@ -47,15 +47,17 @@ public final class CliUtil { public static KeysetHandle readKeyset(String filename) throws GeneralSecurityException, IOException { System.out.println("Reading the keyset..."); - return CleartextKeysetHandle.read( - BinaryKeysetReader.withInputStream(new FileInputStream(filename))); + return TinkProtoKeysetFormat.parseKeyset( + Files.readAllBytes(Paths.get(filename)), InsecureSecretKeyAccess.get()); } /** Writes a keyset to the specified file. In case of errors throws an exception. */ - public static void writeKeyset(KeysetHandle handle, String filename) throws IOException { + public static void writeKeyset(KeysetHandle handle, String filename) + throws IOException, GeneralSecurityException { System.out.println("Writing the keyset..."); - CleartextKeysetHandle.write( - handle, BinaryKeysetWriter.withOutputStream(new FileOutputStream(filename))); + byte[] serializedKeyset = + TinkProtoKeysetFormat.serializeKeyset(handle, InsecureSecretKeyAccess.get()); + Files.write(Paths.get(filename), serializedKeyset); } /** |