diff options
author | juerg <juerg@google.com> | 2023-02-01 02:08:28 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-02-01 02:09:49 -0800 |
commit | 456d15c9a8fe826caed7249665cd9827237d6779 (patch) | |
tree | 7a7c0160699a4544bdd60e854458f4c10683debc /tools | |
parent | 5f08147cbfe9a6a00327b5401a4120bac7c89b20 (diff) | |
download | tink-456d15c9a8fe826caed7249665cd9827237d6779.tar.gz |
Let tinkey output a help message when "tinkey help" is called.
At the same time:
- add "destroy-key" to TINKEY.md
- output the KeyTemplates in sorted order.
PiperOrigin-RevId: 506251200
Diffstat (limited to 'tools')
4 files changed, 61 insertions, 9 deletions
diff --git a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/BUILD.bazel b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/BUILD.bazel index bcebc5028..21c2a8204 100644 --- a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/BUILD.bazel +++ b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/BUILD.bazel @@ -62,6 +62,7 @@ java_library( ":destroy_key_command", ":disable_key_command", ":enable_key_command", + ":help_command", ":list_key_templates_command", ":list_keyset_command", ":promote_key_command", @@ -299,3 +300,9 @@ java_library( "@tink_java//src/main/java/com/google/crypto/tink:key_templates", ], ) + +java_library( + name = "help_command", + srcs = ["HelpCommand.java"], + deps = [":command"], +) diff --git a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/HelpCommand.java b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/HelpCommand.java new file mode 100644 index 000000000..627d02b12 --- /dev/null +++ b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/HelpCommand.java @@ -0,0 +1,41 @@ +// Copyright 2023 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 specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package com.google.crypto.tink.tinkey; + +/** Outputs a help message. */ +public class HelpCommand implements Command { + @Override + public void run() throws Exception { + System.out.println("Tinkey supports the following commands:"); + System.out.println(" help: Prints this help message."); + System.out.println(" add-key: Generates and adds a new key to a keyset."); + System.out.println(" convert-keyset: Changes format, encrypts, decrypts a keyset."); + System.out.println(" create-keyset: Creates a new keyset."); + System.out.println(" create-public-keyset: Creates a public keyset from a private keyset."); + System.out.println(" list-key-templates: Lists all supported key templates."); + System.out.println(" delete-key: Deletes a specified key in a keyset."); + System.out.println( + " destroy-key: Destroys the key material of a specified key in a keyset."); + System.out.println(" disable-key: Disables a specified key in a keyset."); + System.out.println(" enable-key: Enables a specified key in a keyset."); + System.out.println(" list-keyset: Lists keys in a keyset."); + System.out.println(" promote-key: Promotes a specified key to primary."); + System.out.println( + " rotate-keyset: Deprecated. Rotate keysets in two steps using the commands" + + " 'add-key' and later 'promote-key'."); + } +} diff --git a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/ListKeyTemplatesCommand.java b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/ListKeyTemplatesCommand.java index d3199bb4d..b4eadeb49 100644 --- a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/ListKeyTemplatesCommand.java +++ b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/ListKeyTemplatesCommand.java @@ -17,6 +17,9 @@ package com.google.crypto.tink.tinkey; import com.google.crypto.tink.Registry; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** Creates a new {@link com.google.crypto.tink.proto.KeyTemplate}. */ public class ListKeyTemplatesCommand implements Command { @@ -24,10 +27,11 @@ public class ListKeyTemplatesCommand implements Command { @Override public void run() throws Exception { System.out.println("The following key templates are supported:"); - for (String name : Registry.keyTemplates()) { - System.out.println(name); - } - for (String name : TinkeyKeyTemplates.get().keySet()) { + List<String> keyTemplates = new ArrayList<>(); + keyTemplates.addAll(Registry.keyTemplates()); + keyTemplates.addAll(TinkeyKeyTemplates.get().keySet()); + Collections.sort(keyTemplates); + for (String name : keyTemplates) { System.out.println(name); } } diff --git a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/TinkeyCommands.java b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/TinkeyCommands.java index e2c6f1e7b..75ed9ed12 100644 --- a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/TinkeyCommands.java +++ b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/TinkeyCommands.java @@ -26,12 +26,12 @@ import org.kohsuke.args4j.spi.SubCommands; */ public final class TinkeyCommands { @Argument( - metaVar = "command", - required = true, - handler = SubCommandHandler.class, - usage = "Command to run" - ) + metaVar = "command", + required = true, + handler = SubCommandHandler.class, + usage = "Command to run") @SubCommands({ + @SubCommand(name = "help", impl = HelpCommand.class), @SubCommand(name = "add-key", impl = AddKeyCommand.class), @SubCommand(name = "convert-keyset", impl = ConvertKeysetCommand.class), @SubCommand(name = "create-keyset", impl = CreateKeysetCommand.class), |