Repository: CycloneDX/cyclonedx-core-java
Pull request #628 (2025-04-10 17:31:15)

Fix CryptoRef array type
This is a fix for https://github.com/CycloneDX/cyclonedx-core-java/issues/622.


Patch:
diff --git a/src/main/java/org/cyclonedx/model/component/crypto/CryptoRef.java b/src/main/java/org/cyclonedx/model/component/crypto/CryptoRef.java
deleted file mode 100644
index e1df02869..000000000
--- a/src/main/java/org/cyclonedx/model/component/crypto/CryptoRef.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.cyclonedx.model.component.crypto;
-
-import java.util.List;
-import java.util.Objects;
-
-public class CryptoRef
-{
-  private List<String> ref;
-
-  public List<String> getRef() {
-    return ref;
-  }
-
-  public void setRef(final List<String> ref) {
-    this.ref = ref;
-  }
-
-  @Override
-  public boolean equals(final Object object) {
-    if (this == object) {
-      return true;
-    }
-    if (!(object instanceof CryptoRef)) {
-      return false;
-    }
-    CryptoRef cryptoRef = (CryptoRef) object;
-    return Objects.equals(ref, cryptoRef.ref);
-  }
-
-  @Override
-  public int hashCode() {
-    return Objects.hashCode(ref);
-  }
-}
diff --git a/src/main/java/org/cyclonedx/model/component/crypto/Ikev2TransformTypes.java b/src/main/java/org/cyclonedx/model/component/crypto/Ikev2TransformTypes.java
new file mode 100644
index 000000000..50cff8bc3
--- /dev/null
+++ b/src/main/java/org/cyclonedx/model/component/crypto/Ikev2TransformTypes.java
@@ -0,0 +1,90 @@
+package org.cyclonedx.model.component.crypto;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+
+import java.util.List;
+
+public class Ikev2TransformTypes {
+
+  @JacksonXmlElementWrapper(useWrapping = false)
+  @JacksonXmlProperty(localName = "encr")
+  @JsonProperty("encr")
+  private List<String> encr;
+
+  @JacksonXmlElementWrapper(useWrapping = false)
+  @JacksonXmlProperty(localName = "prf")
+  @JsonProperty("prf")
+  private List<String> prf;
+
+  @JacksonXmlElementWrapper(useWrapping = false)
+  @JacksonXmlProperty(localName = "integ")
+  @JsonProperty("integ")
+  private List<String> integ;
+
+  @JacksonXmlElementWrapper(useWrapping = false)
+  @JacksonXmlProperty(localName = "ke")
+  @JsonProperty("ke")
+  private List<String> ke;
+
+  @JsonProperty("esn")
+  private Boolean esn;
+
+  @JacksonXmlElementWrapper(useWrapping = false)
+  @JacksonXmlProperty(localName = "auth")
+  @JsonProperty("auth")
+  private List<String> auth;
+
+  public Ikev2TransformTypes() {
+  }
+
+  public List<String> getEncr() {
+    return encr;
+  }
+
+  public void setEncr(List<String> encr) {
+    this.encr = encr;
+  }
+
+  public List<String> getPrf() {
+    return prf;
+  }
+
+  public void setPrf(List<String> prf) {
+    this.prf = prf;
+  }
+
+  public List<String> getInteg() {
+    return integ;
+  }
+
+  public void setInteg(List<String> integ) {
+    this.integ = integ;
+  }
+
+  public List<String> getKe() {
+    return ke;
+  }
+
+  public void setKe(List<String> ke) {
+    this.ke = ke;
+  }
+
+  public Boolean getEsn() {
+    return esn;
+  }
+
+  public void setEsn(Boolean esn) {
+    this.esn = esn;
+  }
+
+  public List<String> getAuth() {
+    return auth;
+  }
+
+  public void setAuth(List<String> auth) {
+    this.auth = auth;
+  }
+}
+
diff --git a/src/main/java/org/cyclonedx/model/component/crypto/ProtocolProperties.java b/src/main/java/org/cyclonedx/model/component/crypto/ProtocolProperties.java
index 4939f7c82..24926356a 100644
--- a/src/main/java/org/cyclonedx/model/component/crypto/ProtocolProperties.java
+++ b/src/main/java/org/cyclonedx/model/component/crypto/ProtocolProperties.java
@@ -1,7 +1,6 @@
 package org.cyclonedx.model.component.crypto;
 
 import java.util.List;
-import java.util.Map;
 import java.util.Objects;
 
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -23,9 +22,10 @@ public class ProtocolProperties
 
   private List<CipherSuite> cipherSuites;
 
-  private Map<String, CryptoRef> ikev2TransformTypes;
+  @JsonProperty("ikev2TransformTypes")
+  private Ikev2TransformTypes ikev2TransformTypes;
 
-  private CryptoRef cryptoRefArray;
+  private List<String> cryptoRefArray;
 
   public ProtocolType getType() {
     return type;
@@ -54,19 +54,22 @@ public class ProtocolProperties
     this.cipherSuites = cipherSuites;
   }
 
-  public Map<String, CryptoRef> getIkev2TransformTypes() {
+  public Ikev2TransformTypes getIkev2TransformTypes() {
     return ikev2TransformTypes;
   }
 
-  public void setIkev2TransformTypes(final Map<String, CryptoRef> ikev2TransformTypes) {
+  public void setIkev2TransformTypes(final Ikev2TransformTypes ikev2TransformTypes) {
     this.ikev2TransformTypes = ikev2TransformTypes;
   }
 
-  public CryptoRef getCryptoRefArray() {
+  @JacksonXmlElementWrapper(useWrapping = false)
+  @JacksonXmlProperty(localName = "cryptoRef")
+  @JsonProperty("cryptoRefArray")
+  public List<String> getCryptoRefArray() {
     return cryptoRefArray;
   }
 
-  public void setCryptoRefArray(final CryptoRef cryptoRefArray) {
+  public void setCryptoRefArray(final List<String> cryptoRefArray) {
     this.cryptoRefArray = cryptoRefArray;
   }
 


Test patch:
diff --git a/src/test/resources/1.6/valid-cryptography-full-1.6.json b/src/test/resources/1.6/valid-cryptography-full-1.6.json
index ac1344659..254d8433b 100644
--- a/src/test/resources/1.6/valid-cryptography-full-1.6.json
+++ b/src/test/resources/1.6/valid-cryptography-full-1.6.json
@@ -65,7 +65,16 @@
                 "0xC0"
               ]
             }
-          ]
+          ],
+          "ikev2TransformTypes" : {
+            "encr" : [ "bom-ref-to-encryption-algorithm", "bom-ref-to-encryption-algorithm1" ],
+            "prf" : [ "bom-ref-to-pseudorandom-function" ],
+            "integ" : [ "bom-ref-to-integrity-algorithm" ],
+            "ke" : [ "bom-ref-to-key-exchange-method" ],
+            "esn" : true,
+            "auth" : [ "bom-ref-to-authentication-method" ]
+          },
+          "cryptoRefArray" : [ "test", "test1" ]
         },
         "oid": "oid:1.2.3.4.5.6.7.8.9"
       }
diff --git a/src/test/resources/1.6/valid-cryptography-full-1.6.xml b/src/test/resources/1.6/valid-cryptography-full-1.6.xml
index 0e151a343..907ac04ba 100644
--- a/src/test/resources/1.6/valid-cryptography-full-1.6.xml
+++ b/src/test/resources/1.6/valid-cryptography-full-1.6.xml
@@ -61,6 +61,17 @@
                             </identifiers>
                         </cipherSuite>
                     </cipherSuites>
+                    <ikev2TransformTypes>
+                        <encr>bom-ref-to-encryption-algorithm</encr>
+                        <encr>bom-ref-to-encryption-algorithm1</encr>
+                        <prf>bom-ref-to-pseudorandom-function</prf>
+                        <integ>bom-ref-to-integrity-algorithm</integ>
+                        <ke>bom-ref-to-key-exchange-method</ke>
+                        <esn>true</esn>
+                        <auth>bom-ref-to-authentication-method</auth>
+                    </ikev2TransformTypes>
+                    <cryptoRef>test</cryptoRef>
+                    <cryptoRef>test1</cryptoRef>
                 </protocolProperties>
                 <oid>oid:1.2.3.4.5.6.7.8.9</oid>
             </cryptoProperties>