Skip to content

Commit

Permalink
code formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Nicklas Körtge <nicklas.koertge1@ibm.com>
  • Loading branch information
n1ckl0sk0rtge committed Aug 5, 2024
1 parent be0aead commit f629c80
Show file tree
Hide file tree
Showing 39 changed files with 108 additions and 154 deletions.
17 changes: 9 additions & 8 deletions enricher/src/main/java/com/ibm/enricher/Enricher.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
package com.ibm.enricher;

import com.ibm.mapper.model.INode;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.Collection;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

/**
* This enricher instance operates on a language-agnostic level, meaning it will enrich the given
Expand All @@ -42,11 +41,13 @@ public class Enricher implements IEnricher {
public static Collection<INode> enrich(@Nonnull final Collection<INode> nodes) {
final Enricher enricher = new Enricher();
return nodes.stream()
.map(node -> {
final INode enriched = enricher.enrich(node);
enrich(enriched.getChildren().values()).forEach(enriched::append);
return enriched;
}).toList();
.map(
node -> {
final INode enriched = enricher.enrich(node);
enrich(enriched.getChildren().values()).forEach(enriched::append);
return enriched;
})
.toList();
}

/**
Expand Down
1 change: 0 additions & 1 deletion enricher/src/main/java/com/ibm/enricher/IEnricher.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.ibm.enricher;

import com.ibm.mapper.model.INode;

import javax.annotation.Nonnull;

public interface IEnricher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
import com.ibm.mapper.model.algorithms.AES;
import com.ibm.mapper.model.mode.CCM;
import com.ibm.mapper.model.mode.GCM;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

public class AESEnricher implements IEnricher {
private static final String BASE_OID = "2.16.840.1.101.3.4.1";
Expand Down Expand Up @@ -67,12 +66,13 @@ private INode enrich(@NotNull AES aes) {
@Nullable final Mode mode = aes.getMode().orElse(null);
// default key length
if (keyLength == null) {
switch (aes.getDetectionContext().bundle().getIdentifier()) {
case "Jca": {
keyLength = new KeyLength(128, aes.getDetectionContext());
aes.append(keyLength);
}
}
switch (aes.getDetectionContext().bundle().getIdentifier()) {
case "Jca":
{
keyLength = new KeyLength(128, aes.getDetectionContext());
aes.append(keyLength);
}
}
}
// add oid
final Oid oid = new Oid(buildOid(keyLength, mode), aes.getDetectionContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package com.ibm.enricher.algorithm;

import static org.assertj.core.api.Assertions.assertThat;

import com.ibm.enricher.TestBase;
import com.ibm.mapper.model.AuthenticatedEncryption;
import com.ibm.mapper.model.BlockCipher;
Expand All @@ -29,23 +31,16 @@
import com.ibm.mapper.model.mode.GCM;
import com.ibm.mapper.model.padding.PKCS1;
import com.ibm.mapper.utils.DetectionLocation;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;

class AESEnricherTest extends TestBase {

@Test
void oid() {
DetectionLocation testDetectionLocation =
new DetectionLocation("testfile", 1, 1, List.of("test"), () -> "SSL");
final AES aes =
new AES(
256,
new ECB(testDetectionLocation),
testDetectionLocation);
final AES aes = new AES(256, new ECB(testDetectionLocation), testDetectionLocation);
this.logBefore(aes);

final AESEnricher aesEnricher = new AESEnricher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
import com.ibm.mapper.reorganizer.Reorganizer;
import com.ibm.mapper.utils.Utils;
import com.ibm.plugin.translation.translator.JavaTranslator;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.Unmodifiable;
import org.sonar.plugins.java.api.JavaCheck;
import org.sonar.plugins.java.api.JavaFileScannerContext;
import org.sonar.plugins.java.api.semantic.Symbol;
import org.sonar.plugins.java.api.tree.Tree;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public final class JavaTranslationProcess
extends ITranslationProcess<JavaCheck, Tree, Symbol, JavaFileScannerContext> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
import com.ibm.plugin.translation.translator.contexts.JavaProtocolContextTranslator;
import com.ibm.plugin.translation.translator.contexts.JavaSecretKeyContextTranslator;
import com.ibm.plugin.translation.translator.contexts.JavaSignatureContextTranslator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -62,14 +69,6 @@
import org.sonar.plugins.java.api.tree.SyntaxToken;
import org.sonar.plugins.java.api.tree.Tree;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public final class JavaTranslator
extends ITranslator<JavaCheck, Tree, Symbol, JavaFileScannerContext> {

Expand Down
7 changes: 3 additions & 4 deletions mapper/src/main/java/com/ibm/mapper/ITranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
import com.ibm.engine.rule.IBundle;
import com.ibm.mapper.model.INode;
import com.ibm.mapper.utils.DetectionLocation;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class ITranslator<R, T, S, P> {

Expand All @@ -47,5 +46,5 @@ protected abstract Optional<INode> translate(
@Nonnull final String filePath);

@Nullable protected abstract DetectionLocation getDetectionContextFrom(
@Nonnull T location, @Nonnull final IBundle bundle, @Nonnull String filePath);
@Nonnull T location, @Nonnull final IBundle bundle, @Nonnull String filePath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
import com.ibm.mapper.model.padding.PKCS1;
import com.ibm.mapper.model.padding.PKCS5;
import com.ibm.mapper.utils.DetectionLocation;

import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Optional;

public class JcaPaddingMapper implements IMapper {

Expand Down
2 changes: 1 addition & 1 deletion mapper/src/main/java/com/ibm/mapper/model/Cipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
package com.ibm.mapper.model;

import javax.annotation.Nonnull;
import java.util.Optional;
import javax.annotation.Nonnull;

public class Cipher extends Algorithm implements ICipher, AuthenticatedEncryption {

Expand Down
5 changes: 2 additions & 3 deletions mapper/src/main/java/com/ibm/mapper/model/MessageDigest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
*/
package com.ibm.mapper.model;

import javax.annotation.Nonnull;
import java.util.Optional;
import javax.annotation.Nonnull;

public class MessageDigest extends Algorithm {
public MessageDigest(@Nonnull Algorithm algorithm) {
super(algorithm, MessageDigest.class);
}

public MessageDigest(@Nonnull Algorithm algorithm,
@Nonnull DigestSize digestSize) {
public MessageDigest(@Nonnull Algorithm algorithm, @Nonnull DigestSize digestSize) {
super(algorithm, MessageDigest.class);
this.append(digestSize);
}
Expand Down
3 changes: 1 addition & 2 deletions mapper/src/main/java/com/ibm/mapper/model/Padding.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
package com.ibm.mapper.model;

import com.ibm.mapper.utils.DetectionLocation;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Objects;
import javax.annotation.Nonnull;

public class Padding extends Property {
@Nonnull private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class AES extends BlockCipher {
private static final String NAME = "AES";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class AESWrap extends BlockCipher {
private static final String NAME = "AESWrap";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class Aria extends BlockCipher {
private static final String NAME = "Aria";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class Blowfish extends BlockCipher {
private static final String NAME = "Blowfish";
Expand All @@ -43,9 +42,7 @@ public Blowfish(int keyLength, @NotNull DetectionLocation detectionLocation) {
}

public Blowfish(
int keyLength,
@Nonnull Mode mode,
@NotNull DetectionLocation detectionLocation) {
int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(new Algorithm(NAME, detectionLocation));
this.append(new KeyLength(keyLength, detectionLocation));
this.append(mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class Camellia extends BlockCipher {
private static final String NAME = "Camellia";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.model.StreamCipher;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class ChaCha20 extends StreamCipher {
private static final String NAME = "ChaCha20";
Expand All @@ -42,9 +41,7 @@ public ChaCha20(int keyLength, @NotNull DetectionLocation detectionLocation) {
}

public ChaCha20(
int keyLength,
@Nonnull Padding padding,
@NotNull DetectionLocation detectionLocation) {
int keyLength, @Nonnull Padding padding, @NotNull DetectionLocation detectionLocation) {
super(new Algorithm(NAME, detectionLocation));
this.append(new KeyLength(keyLength, detectionLocation));
this.append(padding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class DES extends BlockCipher {
private static final String NAME = "DES";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class DESedeWrap extends BlockCipher {
private static final String NAME = "DESedeWrap"; // TripleDESWrap
Expand All @@ -43,9 +42,7 @@ public DESedeWrap(int keyLength, @NotNull DetectionLocation detectionLocation) {
}

public DESedeWrap(
int keyLength,
@Nonnull Mode mode,
@NotNull DetectionLocation detectionLocation) {
int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(new Algorithm(NAME, detectionLocation));
this.append(new KeyLength(keyLength, detectionLocation));
this.append(mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class RC2 extends BlockCipher {
private static final String NAME = "RC2"; // ARC2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.model.StreamCipher;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class RC4 extends StreamCipher {
private static final String NAME = "RC4"; // ARC4, ARCFOUR
Expand Down
8 changes: 2 additions & 6 deletions mapper/src/main/java/com/ibm/mapper/model/algorithms/RC5.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import com.ibm.mapper.model.Mode;
import com.ibm.mapper.model.Padding;
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public final class RC5 extends BlockCipher {
private static final String NAME = "RC5"; // ARC2
Expand All @@ -42,10 +41,7 @@ public RC5(int keyLength, @NotNull DetectionLocation detectionLocation) {
this.append(new KeyLength(keyLength, detectionLocation));
}

public RC5(
int keyLength,
@Nonnull Mode mode,
@NotNull DetectionLocation detectionLocation) {
public RC5(int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(new Algorithm(NAME, detectionLocation));
this.append(new KeyLength(keyLength, detectionLocation));
this.append(mode);
Expand Down
Loading

0 comments on commit f629c80

Please sign in to comment.