Skip to content

Commit 42592f1

Browse files
committed
Merge branch 'master' of github.com:open-eid/cdoc2-java-ref-impl
2 parents 30b6661 + e56017a commit 42592f1

File tree

36 files changed

+175
-147
lines changed

36 files changed

+175
-147
lines changed

cdoc2-cli/src/main/java/ee/cyber/cdoc2/cli/commands/CDocCreateCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
//S106 - Standard outputs should not be used directly to log anything
3232
//CLI needs to interact with standard outputs
33-
@SuppressWarnings("java:S106")
33+
@SuppressWarnings({"java:S106", "java:S125"})
3434
@Command(name = "create", aliases = {"c", "encrypt"}, showAtFileInUsageHelp = true)
3535
public class CDocCreateCmd implements Callable<Void> {
3636

cdoc2-cli/src/main/java/ee/cyber/cdoc2/cli/commands/CDocDecryptCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
//S106 Standard outputs should not be used directly to log anything
2828
//CLI needs to interact with standard outputs
29-
@SuppressWarnings("java:S106")
29+
@SuppressWarnings({"java:S106", "java:S125"})
3030
@Command(name = "decrypt", aliases = {"x", "extract"}, showAtFileInUsageHelp = true)
3131
public class CDocDecryptCmd implements Callable<Void> {
3232
// commented out until public key server is in live

cdoc2-cli/src/main/java/ee/cyber/cdoc2/cli/commands/CDocInfoCmd.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static ee.cyber.cdoc2.crypto.KeyLabelTools.keyLabelParamsForDisplaying;
2222

2323

24-
2524
//S106 Standard outputs should not be used directly to log anything
2625
//CLI needs to interact with standard outputs
2726
@SuppressWarnings("java:S106")
@@ -44,18 +43,15 @@ private void setProperty(Map<String, String> props) {
4443

4544
@Override
4645
public Void call() throws Exception {
47-
48-
4946
List<Recipient> recipients = Envelope.parseHeader(Files.newInputStream(cdocFile.toPath()));
5047
for (Recipient recipient: recipients) {
51-
5248
String type = getHumanReadableType(recipient);
5349

5450
Map<String, String> keyLabelParams
5551
= extractKeyLabelParams(recipient.getRecipientKeyLabel());
5652

57-
String server = (recipient instanceof ServerRecipient)
58-
? "(server: " + ((ServerRecipient) recipient).getKeyServerId() + ")"
53+
String server = (recipient instanceof ServerRecipient serverRecipient)
54+
? "(server: " + serverRecipient.getKeyServerId() + ")"
5955
: "";
6056

6157
System.out.println(
@@ -69,8 +65,8 @@ public Void call() throws Exception {
6965
String getHumanReadableType(Recipient recipient) {
7066
Objects.requireNonNull(recipient); //can't have null recipient, fail with exception
7167

72-
if (recipient instanceof PublicKeyRecipient) {
73-
return ((PublicKeyRecipient) recipient).getRecipientPubKey().getAlgorithm() + " PublicKey";
68+
if (recipient instanceof PublicKeyRecipient publicKeyRecipient) {
69+
return publicKeyRecipient.getRecipientPubKey().getAlgorithm() + " PublicKey";
7470
} else if (recipient instanceof SymmetricKeyRecipient) {
7571
return "SymmetricKey";
7672
} else if (recipient instanceof PBKDF2Recipient) {
@@ -81,4 +77,5 @@ String getHumanReadableType(Recipient recipient) {
8177
return recipient.getClass().toString();
8278
}
8379
}
80+
8481
}

cdoc2-cli/src/main/java/ee/cyber/cdoc2/cli/commands/CDocReEncryptCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
//S106 Standard outputs should not be used directly to log anything
3232
//CLI needs to interact with standard outputs
33-
@SuppressWarnings("java:S106")
33+
@SuppressWarnings({"java:S106", "java:S125"})
3434
@CommandLine.Command(name = "re-encrypt", aliases = {"re", "reencrypt"}, showAtFileInUsageHelp =
3535
true)
3636
public class CDocReEncryptCmd implements Callable<Void> {

cdoc2-cli/src/test/java/CDocCliTest.java renamed to cdoc2-cli/src/test/java/cli/CDocCliTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ee.cyber.cdoc2.cli.CDocCli;
1+
package cli;
22

33
import java.io.ByteArrayOutputStream;
44
import java.io.IOException;
@@ -21,6 +21,9 @@
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323
import picocli.CommandLine;
24+
25+
import ee.cyber.cdoc2.cli.CDocCli;
26+
2427
import static org.junit.jupiter.api.Assertions.assertEquals;
2528
import static org.junit.jupiter.api.Assertions.assertThrows;
2629
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -92,7 +95,7 @@ void testSuccessfulCreateDecryptDocWithPassword() throws IOException {
9295
}
9396

9497
@Test
95-
@Disabled
98+
@Disabled("Requires user interaction for inserting password 'myPlainTextPassword'")
9699
void testSuccessfulCreateDecryptDocWithPasswordWhenItIsInsertedInteractively()
97100
throws IOException {
98101
encrypt(PASSWORD_OPTION);
@@ -200,7 +203,6 @@ void shouldFailWithTheSameOutputDirectoryWhenReEncrypt(@TempDir Path tempPath) {
200203
);
201204
}
202205

203-
204206
@Test
205207
void infoShouldDisplayKeyLabelInDefaultFormatForPassword() throws IOException {
206208
encrypt(PASSWORD_OPTION);

cdoc2-cli/src/test/java/CryptoTest.java renamed to cdoc2-cli/src/test/java/cli/CryptoTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package cli;
2+
13
import org.junit.jupiter.api.Test;
24

35
import ee.cyber.cdoc2.crypto.Crypto;

cdoc2-client/src/main/java/ee/cyber/cdoc2/client/Cdoc2KeyCapsuleApiClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ protected void customizeClientBuilder(ClientBuilder clientBuilder) {
190190
return new Cdoc2KeyCapsuleApiClient(new Cdoc2KeyCapsulesApi(apiClient));
191191
}
192192

193+
@SuppressWarnings("java:S2139")
193194
private SSLContext createSslContext() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException,
194195
KeyStoreException, KeyManagementException {
195196
SSLContext sslContext;

cdoc2-example-app/src/main/java/ee/cyber/cdoc2/converter/ConverterCmd.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import java.util.Arrays;
1818
import java.util.concurrent.Callable;
1919

20-
@Command( name = "cdoc-convert"
21-
)
20+
@Command( name = "cdoc-convert")
21+
@SuppressWarnings("squid:S106")
2222
public class ConverterCmd implements Callable<Void> {
2323

2424
private static final Logger log = LoggerFactory.getLogger(ConverterCmd.class);
@@ -48,8 +48,6 @@ public class ConverterCmd implements Callable<Void> {
4848
@Option(names = { "-h", "--help" }, usageHelp = false, description = "display a help message")
4949
private boolean helpRequested = false;
5050

51-
52-
5351
public static void main(String... args) {
5452

5553
if (args.length == 0) {
@@ -61,7 +59,6 @@ public static void main(String... args) {
6159
System.exit(exitCode);
6260
}
6361

64-
6562
@Override
6663
public Void call() throws Exception {
6764

cdoc2-example-app/src/main/java/ee/cyber/cdoc2/converter/util/AutoRemovableDir.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
public class AutoRemovableDir implements AutoCloseable {
1010

11+
private static final Logger log = LoggerFactory.getLogger(AutoRemovableDir.class);
12+
1113
Path pathToRemove;
1214
public AutoRemovableDir(Path pathToRemove) {
1315
this.pathToRemove = pathToRemove;
@@ -27,6 +29,7 @@ private static void purgeDirectory(File dir) {
2729
if (file.isDirectory())
2830
purgeDirectory(file);
2931
file.delete();
32+
log.info("Directory " + dir + " was deleted");
3033
}
3134
}
3235
}

cdoc2-example-app/src/main/java/ee/cyber/cdoc2/converter/util/PasswordCheckUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static boolean isPwned(char[] passwd) throws NoSuchAlgorithmException, UR
5959

6060
byte[] bytes = StandardCharsets.UTF_8.encode(CharBuffer.wrap(passwd)).array();
6161

62+
@SuppressWarnings("java:S4790")
6263
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
6364
sha1.update(bytes);
6465
String digest = HexFormat.of().formatHex(sha1.digest()).toUpperCase();

0 commit comments

Comments
 (0)