001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
004import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
005import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
006import gov.nist.secauto.metaschema.binding.model.annotations.Matches;
007import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaField;
008import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaFieldValue;
009import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
010import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
011import gov.nist.secauto.metaschema.model.common.datatype.adapter.StringAdapter;
012import java.lang.Override;
013import java.lang.String;
014import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
015import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
016
017/**
018 * A representation of a cryptographic digest generated over a resource using a specified hash algorithm.
019 */
020@MetaschemaField(
021    formalName = "Hash",
022    description = "A representation of a cryptographic digest generated over a resource using a specified hash algorithm.",
023    name = "hash",
024    metaschema = OscalMetadataMetaschema.class,
025    isCollapsible = false
026)
027@ValueConstraints(
028    matches = {
029        @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-224','SHA3-224')]", pattern = "^[0-9a-fA-F]{28}$"),
030        @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-256','SHA3-256')]", pattern = "^[0-9a-fA-F]{32}$"),
031        @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-384','SHA3-384')]", pattern = "^[0-9a-fA-F]{48}$"),
032        @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-512','SHA3-512')]", pattern = "^[0-9a-fA-F]{64}$")
033    }
034)
035public class Hash {
036  @MetaschemaFieldValue(
037      valueKeyName = "value"
038  )
039  private String _value;
040
041  @BoundFlag(
042      formalName = "Hash algorithm",
043      description = "The digest method by which a hash is derived.",
044      useName = "algorithm",
045      required = true,
046      typeAdapter = StringAdapter.class,
047      remarks = "Any other value used MUST be a value defined in the W3C [XML Security Algorithm Cross-Reference](https://www.w3.org/TR/xmlsec-algorithms/#digest-method-uris) Digest Methods (W3C, April 2013) or [RFC 6931 Section 2.1.5](https://tools.ietf.org/html/rfc6931#section-2.1.5) New SHA Functions."
048  )
049  @ValueConstraints(
050      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "SHA-224", description = "The SHA-224 algorithm as defined by [NIST FIPS 180-4](https://doi.org/10.6028/NIST.FIPS.180-4)."), @AllowedValue(value = "SHA-256", description = "The SHA-256 algorithm as defined by [NIST FIPS 180-4](https://doi.org/10.6028/NIST.FIPS.180-4)."), @AllowedValue(value = "SHA-384", description = "The SHA-384 algorithm as defined by [NIST FIPS 180-4](https://doi.org/10.6028/NIST.FIPS.180-4)."), @AllowedValue(value = "SHA-512", description = "The SHA-512 algorithm as defined by [NIST FIPS 180-4](https://doi.org/10.6028/NIST.FIPS.180-4)."), @AllowedValue(value = "SHA3-224", description = "The SHA3-224 algorithm as defined by [NIST FIPS 202](https://doi.org/10.6028/NIST.FIPS.202)."), @AllowedValue(value = "SHA3-256", description = "The SHA3-256 algorithm as defined by [NIST FIPS 202](https://doi.org/10.6028/NIST.FIPS.202)."), @AllowedValue(value = "SHA3-384", description = "The SHA3-384 algorithm as defined by [NIST FIPS 202](https://doi.org/10.6028/NIST.FIPS.202)."), @AllowedValue(value = "SHA3-512", description = "The SHA3-512 algorithm as defined by [NIST FIPS 202](https://doi.org/10.6028/NIST.FIPS.202).")})
051  )
052  private String _algorithm;
053
054  public Hash() {
055  }
056
057  public String getValue() {
058    return _value;
059  }
060
061  public void setValue(String value) {
062    _value = value;
063  }
064
065  public String getAlgorithm() {
066    return _algorithm;
067  }
068
069  public void setAlgorithm(String value) {
070    _algorithm = value;
071  }
072
073  @Override
074  public String toString() {
075    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
076  }
077}