Skip to content

Commit

Permalink
remove Kind use from AlgorithmParameterContext
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoqnc committed Sep 18, 2024
1 parent 352fdf8 commit f7d1caf
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,19 @@
*/
package com.ibm.engine.model.context;

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

public class AlgorithmParameterContext
implements IDetectionContext, ISupportKind<AlgorithmParameterContext.Kind> {

public enum Kind {
DH,
AEAD,
CCM,
GMSS,
IES,
KEY,
SABER,
NONE
}

@Nonnull private final Kind kind;

public AlgorithmParameterContext(@Nonnull Kind kind) {
this.kind = kind;
}
public class AlgorithmParameterContext extends DetectionContext {

public AlgorithmParameterContext() {
this.kind = Kind.NONE;
super(new HashMap<>());
}

@Nonnull
public Kind kind() {
return kind;
public AlgorithmParameterContext(@Nonnull Map<String, String> properties) {
super(properties);
}

@NotNull @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ private BcAEADParameters() {
.withMethodParameter("int")
.shouldBeDetectedAs(new MacSizeFactory<>(Size.UnitType.BIT))
.withMethodParameter(BYTE_ARRAY_TYPE)
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.AEAD))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand All @@ -65,8 +64,7 @@ private BcAEADParameters() {
.shouldBeDetectedAs(new MacSizeFactory<>(Size.UnitType.BIT))
.withMethodParameter(BYTE_ARRAY_TYPE)
.withMethodParameter(BYTE_ARRAY_TYPE)
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.AEAD))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ private BcCCMParameters() {
.shouldBeDetectedAs(new MacSizeFactory<>(Size.UnitType.BIT))
.withMethodParameter(BYTE_ARRAY_TYPE)
.withMethodParameter(BYTE_ARRAY_TYPE)
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.CCM))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ private BcGMSSParameters() {
.withMethodParameter("int")
.shouldBeDetectedAs(new KeySizeFactory<>(Size.UnitType.BIT))
.asChildOfParameterWithId(-1)
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.GMSS))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand All @@ -59,8 +58,7 @@ private BcGMSSParameters() {
.withMethodParameter("boolean")
.withMethodParameter("org.bouncycastle.pqc.legacy.crypto.gmss.GMSSParameters")
.addDependingDetectionRules(List.of(BASE_CONSTRUCTOR))
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.GMSS))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand All @@ -73,8 +71,7 @@ private BcGMSSParameters() {
.withMethodParameter(BYTE_ARRAY_TYPE)
.withMethodParameter("org.bouncycastle.pqc.legacy.crypto.gmss.GMSSParameters")
.addDependingDetectionRules(List.of(BASE_CONSTRUCTOR))
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.GMSS))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand All @@ -86,8 +83,7 @@ private BcGMSSParameters() {
.withMethodParameter(BYTE_ARRAY_TYPE)
.withMethodParameter("org.bouncycastle.pqc.legacy.crypto.gmss.GMSSParameters")
.addDependingDetectionRules(List.of(BASE_CONSTRUCTOR))
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.GMSS))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand All @@ -99,8 +95,7 @@ private BcGMSSParameters() {
.withMethodParameter(
"org.bouncycastle.pqc.legacy.crypto.gmss.GMSSPublicKeyParameters")
.addDependingDetectionRules(List.of(PUBLIC_KEY_CONSTRUCTOR))
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.GMSS))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand All @@ -127,8 +122,7 @@ private BcGMSSParameters() {
.addDependingDetectionRules(List.of(BASE_CONSTRUCTOR))
.withMethodParameter(
"org.bouncycastle.pqc.legacy.crypto.gmss.GMSSDigestProvider")
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.GMSS))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand Down Expand Up @@ -162,8 +156,7 @@ private BcGMSSParameters() {
.addDependingDetectionRules(List.of(BASE_CONSTRUCTOR))
.withMethodParameter(
"org.bouncycastle.pqc.legacy.crypto.gmss.GMSSDigestProvider")
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.GMSS))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ private BcIESParameters() {
.withMethodParameter("int")
.shouldBeDetectedAs(new MacSizeFactory<>(Size.UnitType.BIT))
.asChildOfParameterWithId(-1)
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.IES))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand All @@ -66,8 +65,7 @@ private BcIESParameters() {
.withMethodParameter("int")
.shouldBeDetectedAs(new KeySizeFactory<>(Size.UnitType.BIT))
.asChildOfParameterWithId(-1)
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.IES))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ private BcKeyParameter() {
.withMethodParameter("int")
.withMethodParameter("int")
.shouldBeDetectedAs(new KeySizeFactory<>(Size.UnitType.BIT))
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.KEY))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ private BcSABERParameters() {
*/
// .shouldBeDetectedAs(new BooleanFactory<>()) // captures `usingAes`
.withMethodParameter("boolean")
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.SABER))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Bc")
.withoutDependingDetectionRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public final class JcaDHGenParameterSpec {
.withMethodParameter("int")
.shouldBeDetectedAs(new KeySizeFactory<>(Size.UnitType.BIT))
.withMethodParameter("int")
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.DH))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Jca")
.withoutDependingDetectionRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public final class JcaDHParameterSpec {
.withMethodParameter(BIGINTEGER_TYPE)
.shouldBeDetectedAs(new KeySizeFactory<>(Size.UnitType.PRIME_P))
.withMethodParameter(BIGINTEGER_TYPE)
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.DH))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Jca")
.withoutDependingDetectionRules();

Expand All @@ -55,8 +54,7 @@ public final class JcaDHParameterSpec {
.shouldBeDetectedAs(new KeySizeFactory<>(Size.UnitType.PRIME_P))
.withMethodParameter(BIGINTEGER_TYPE)
.withMethodParameter("int")
.buildForContext(
new AlgorithmParameterContext(AlgorithmParameterContext.Kind.DH))
.buildForContext(new AlgorithmParameterContext())
.inBundle(() -> "Jca")
.withoutDependingDetectionRules();

Expand Down

0 comments on commit f7d1caf

Please sign in to comment.