001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter;
004import gov.nist.secauto.metaschema.core.model.IBoundObject;
005import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
006import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
007import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue;
008import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues;
009import gov.nist.secauto.metaschema.databind.model.annotations.BoundFieldValue;
010import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
011import gov.nist.secauto.metaschema.databind.model.annotations.Matches;
012import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaField;
013import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
014import java.lang.Override;
015import java.lang.String;
016import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
017import org.apache.commons.lang3.builder.ToStringStyle;
018
019/**
020 * A representation of a cryptographic digest generated over a resource using a specified hash algorithm.
021 */
022@MetaschemaField(
023    formalName = "Hash",
024    description = "A representation of a cryptographic digest generated over a resource using a specified hash algorithm.",
025    name = "hash",
026    moduleClass = OscalMetadataModule.class,
027    valueConstraints = @ValueConstraints(matches = {@Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-224','SHA3-224')]", pattern = "^[0-9a-fA-F]{28}$"), @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-256','SHA3-256')]", pattern = "^[0-9a-fA-F]{32}$"), @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-384','SHA3-384')]", pattern = "^[0-9a-fA-F]{48}$"), @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-512','SHA3-512')]", pattern = "^[0-9a-fA-F]{64}$")})
028)
029public class Hash implements IBoundObject {
030  private final IMetaschemaData __metaschemaData;
031
032  /**
033   * "The digest method by which a hash is derived."
034   */
035  @BoundFlag(
036      formalName = "Hash algorithm",
037      description = "The digest method by which a hash is derived.",
038      name = "algorithm",
039      required = true,
040      typeAdapter = StringAdapter.class,
041      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.",
042      valueConstraints = @ValueConstraints(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).")}))
043  )
044  private String _algorithm;
045
046  @BoundFieldValue(
047      valueKeyName = "value"
048  )
049  private String _value;
050
051  public Hash() {
052    this(null);
053  }
054
055  public Hash(IMetaschemaData data) {
056    this.__metaschemaData = data;
057  }
058
059  @Override
060  public IMetaschemaData getMetaschemaData() {
061    return __metaschemaData;
062  }
063
064  public String getAlgorithm() {
065    return _algorithm;
066  }
067
068  public void setAlgorithm(String value) {
069    _algorithm = value;
070  }
071
072  public String getValue() {
073    return _value;
074  }
075
076  public void setValue(String value) {
077    _value = value;
078  }
079
080  @Override
081  public String toString() {
082    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
083  }
084}