From a2068b518a880600b18ce1ca29540fa680fa86f2 Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Tue, 8 Dec 2020 09:52:24 +0100 Subject: Add fields for signature and certificate in source model. Signed-off-by: Bartosz Gardziejewski Change-Id: I0783dd9f78c0138fba871d0977e4cd8305891872 Issue-ID: VNFSDK-714 --- .../org/onap/cvc/csar/parser/ManifestConsts.java | 2 + .../org/onap/cvc/csar/parser/SourcesParser.java | 79 +++++++++++++++++----- 2 files changed, 64 insertions(+), 17 deletions(-) (limited to 'csarvalidation/src/main/java/org/onap') diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/parser/ManifestConsts.java b/csarvalidation/src/main/java/org/onap/cvc/csar/parser/ManifestConsts.java index afa0e2d..59131de 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/parser/ManifestConsts.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/parser/ManifestConsts.java @@ -24,6 +24,8 @@ final class ManifestConsts { static final String SOURCE_TAG_SECTION = "source"; static final String ALGORITHM = "algorithm"; static final String HASH = "hash"; + static final String SIGNATURE = "signature"; + static final String CERTIFICATE = "certificate"; static final String NON_MANO_ARTIFACT_SETS_TAG_SECTION = "non_mano_artifact_sets"; static final String PRODUCT_NAME = "pnfd_name"; static final String PROVIDER_ID = "pnfd_provider"; diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/parser/SourcesParser.java b/csarvalidation/src/main/java/org/onap/cvc/csar/parser/SourcesParser.java index 9cbef8a..b25fc40 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/parser/SourcesParser.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/parser/SourcesParser.java @@ -54,6 +54,10 @@ public class SourcesParser { handleAlgorithmLine(errors, source, lineNumber, manifestLine); } else if (!isSpecialTagReached && manifestLine.startsWith(HASH)) { handleHashLine(errors, source, lineNumber, manifestLine); + } else if (!isSpecialTagReached && manifestLine.startsWith(SIGNATURE)) { + handleSignatureLine(errors, source, lineNumber, manifestLine); + } else if (!isSpecialTagReached && manifestLine.startsWith(CERTIFICATE)) { + handleCertificateLine(errors, source, lineNumber, manifestLine); } } @@ -62,8 +66,8 @@ public class SourcesParser { private boolean isContainSpecialTag(String line, ManifestLine manifestLine) { return manifestLine.startsWith(METADATA_SECTION_TAG_SECTION) - || manifestLine.startsWith(NON_MANO_ARTIFACT_SETS_TAG_SECTION) - || line.contains(CMS); + || manifestLine.startsWith(NON_MANO_ARTIFACT_SETS_TAG_SECTION) + || line.contains(CMS); } private Source handleSourceLine(List sources, List errors, int lineNumber, ManifestLine manifestLine) { @@ -80,14 +84,30 @@ public class SourcesParser { private void handleAlgorithmLine(List errors, Source source, int lineNumber, ManifestLine manifestLine) { String algorithm = parseSourceSectionLine(manifestLine, lineNumber, errors); - if (source != null) + if (source != null) { source.setAlgorithm(algorithm); + } } private void handleHashLine(List errors, Source source, int lineNumber, ManifestLine manifestLine) { String hash = parseSourceSectionLine(manifestLine, lineNumber, errors); - if (source != null) + if (source != null) { source.setHash(hash); + } + } + + private void handleSignatureLine(List errors, Source source, int lineNumber, ManifestLine manifestLine) { + String signature = parseSourceSectionLine(manifestLine, lineNumber, errors); + if (source != null) { + source.setSignature(signature); + } + } + + private void handleCertificateLine(List errors, Source source, int lineNumber, ManifestLine manifestLine) { + String certificate = parseSourceSectionLine(manifestLine, lineNumber, errors); + if (source != null) { + source.setCertificate(certificate); + } } private String parseSourceSectionLine(ManifestLine line, int lineNumber, List errors) { @@ -110,12 +130,19 @@ public class SourcesParser { private final String value; private String algorithm; private String hash; + private String signature; + private String certificate; - public Source(String value, String algorithm, String hash) { - + public Source(String value, String algorithm, String hash, String signature, String certificate) { this.value = value; this.algorithm = algorithm; this.hash = hash; + this.signature = signature; + this.certificate = certificate; + } + + public Source(String source, String algorithm, String hash) { + this(source, algorithm, hash, "", ""); } public Source(String source) { @@ -142,34 +169,52 @@ public class SourcesParser { this.hash = hash; } + public String getSignature() { + return signature; + } + + public void setSignature(String signature) { + this.signature = signature; + } + + public String getCertificate() { + return certificate; + } + + public void setCertificate(String certificate) { + this.certificate = certificate; + } + @Override public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { return false; } - - Source source1 = (Source) o; - return Objects.equals(value, source1.value) && - Objects.equals(algorithm, source1.algorithm) && - Objects.equals(hash, source1.hash); + Source source = (Source) o; + return Objects.equals(value, source.value) && + Objects.equals(algorithm, source.algorithm) && + Objects.equals(hash, source.hash) && + Objects.equals(signature, source.signature) && + Objects.equals(certificate, source.certificate); } @Override public int hashCode() { - return Objects.hash(value, algorithm, hash); + return Objects.hash(value, algorithm, hash, signature, certificate); } @Override public String toString() { return "Source{" + - "value='" + value + '\'' + - ", algorithm='" + algorithm + '\'' + - ", hash='" + hash + '\'' + - '}'; + "value='" + value + '\'' + + ", algorithm='" + algorithm + '\'' + + ", hash='" + hash + '\'' + + ", signature='" + signature + '\'' + + ", certificate='" + certificate + '\'' + + '}'; } } } -- cgit 1.2.3-korg