View Javadoc
1   package gov.nist.secauto.oscal.lib.model;
2   
3   import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
4   import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
5   import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
6   import gov.nist.secauto.metaschema.binding.model.annotations.Matches;
7   import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaField;
8   import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaFieldValue;
9   import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
10  import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
11  import gov.nist.secauto.metaschema.model.common.datatype.adapter.StringAdapter;
12  import java.lang.Override;
13  import java.lang.String;
14  import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
15  import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
16  
17  /**
18   * A representation of a cryptographic digest generated over a resource using a specified hash algorithm.
19   */
20  @MetaschemaField(
21      formalName = "Hash",
22      description = "A representation of a cryptographic digest generated over a resource using a specified hash algorithm.",
23      name = "hash",
24      metaschema = OscalMetadataMetaschema.class,
25      isCollapsible = false
26  )
27  @ValueConstraints(
28      matches = {
29          @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-224','SHA3-224')]", pattern = "^[0-9a-fA-F]{28}$"),
30          @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-256','SHA3-256')]", pattern = "^[0-9a-fA-F]{32}$"),
31          @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-384','SHA3-384')]", pattern = "^[0-9a-fA-F]{48}$"),
32          @Matches(level = IConstraint.Level.ERROR, target = ".[@algorithm=('SHA-512','SHA3-512')]", pattern = "^[0-9a-fA-F]{64}$")
33      }
34  )
35  public class Hash {
36    @MetaschemaFieldValue(
37        valueKeyName = "value"
38    )
39    private String _value;
40  
41    @BoundFlag(
42        formalName = "Hash algorithm",
43        description = "The digest method by which a hash is derived.",
44        useName = "algorithm",
45        required = true,
46        typeAdapter = StringAdapter.class,
47        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."
48    )
49    @ValueConstraints(
50        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).")})
51    )
52    private String _algorithm;
53  
54    public Hash() {
55    }
56  
57    public String getValue() {
58      return _value;
59    }
60  
61    public void setValue(String value) {
62      _value = value;
63    }
64  
65    public String getAlgorithm() {
66      return _algorithm;
67    }
68  
69    public void setAlgorithm(String value) {
70      _algorithm = value;
71    }
72  
73    @Override
74    public String toString() {
75      return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
76    }
77  }