From 88af928b20639edbf127a8327694559b5c0c93aa Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 25 Mar 2023 10:45:39 +0800 Subject: [PATCH] feat: update age cli --- .../tinyencrypt/config/TinyEncryptConstant.java | 2 +- .../hatter/tools/tinyencrypt/util/AgeCliUtil.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/hatter/tools/tinyencrypt/config/TinyEncryptConstant.java b/src/main/java/me/hatter/tools/tinyencrypt/config/TinyEncryptConstant.java index 5d61d85..4d34b1f 100644 --- a/src/main/java/me/hatter/tools/tinyencrypt/config/TinyEncryptConstant.java +++ b/src/main/java/me/hatter/tools/tinyencrypt/config/TinyEncryptConstant.java @@ -1,7 +1,7 @@ package me.hatter.tools.tinyencrypt.config; public class TinyEncryptConstant { - public static final String VERSION = "0.6.3"; + public static final String VERSION = "0.6.4"; public static final String ENC_FILE_EXT = ".tinyenc"; } diff --git a/src/main/java/me/hatter/tools/tinyencrypt/util/AgeCliUtil.java b/src/main/java/me/hatter/tools/tinyencrypt/util/AgeCliUtil.java index f68bd5b..4ee355a 100644 --- a/src/main/java/me/hatter/tools/tinyencrypt/util/AgeCliUtil.java +++ b/src/main/java/me/hatter/tools/tinyencrypt/util/AgeCliUtil.java @@ -1,6 +1,7 @@ package me.hatter.tools.tinyencrypt.util; import me.hatter.tools.commons.assertion.AssertUtil; +import me.hatter.tools.commons.exception.JumpOutException; import me.hatter.tools.commons.io.RFile; import me.hatter.tools.commons.log.LogTool; import me.hatter.tools.commons.log.LogTools; @@ -25,13 +26,14 @@ public class AgeCliUtil { AssertUtil.isFalse(ageEnvelop.contains("'"), "Age-envelop cannot contains `'`"); AssertUtil.isTrue(ageEnvelop.matches("^[\\-/+=\\n\\r\\sa-zA-Z0-9]+$"), "Age-envelop illegal"); - final RFile recipientAgeFileWithoutSerial = RFile.fromUserHome(".tinyencrypt/" + ageRecipient + ".age"); - final RFile recipientAgeFileWithSerial = serialOpt.map(s -> RFile.fromUserHome(".tinyencrypt/" + ageRecipient + ".age." + s)).orElse(null); + final RFile recipientAgeFile = serialOpt.map(s -> { + final RFile recipientAgeFileWithSerial = RFile.fromUserHome(".tinyencrypt/" + ageRecipient + ".age." + s); + return recipientAgeFileWithSerial.isFile() ? recipientAgeFileWithSerial : null; + }).orElseGet(() -> RFile.fromUserHome(".tinyencrypt/" + ageRecipient + ".age")); - final RFile recipientAgeFile = ((recipientAgeFileWithSerial != null) && recipientAgeFileWithSerial.isFile()) - ? recipientAgeFileWithSerial : recipientAgeFileWithoutSerial; - - AssertUtil.isTrue(recipientAgeFile.isFile(), "Age key file required"); + if (!recipientAgeFile.isFile()) { + throw new JumpOutException("Age key file required: " + recipientAgeFile.file().getAbsolutePath()); + } final ProcessBuilder pb = new ProcessBuilder( "sh",