1 /**
2 * Portions of this software was developed by employees of the National Institute
3 * of Standards and Technology (NIST), an agency of the Federal Government and is
4 * being made available as a public service. Pursuant to title 17 United States
5 * Code Section 105, works of NIST employees are not subject to copyright
6 * protection in the United States. This software may be subject to foreign
7 * copyright. Permission in the United States and in foreign countries, to the
8 * extent that NIST may hold copyright, to use, copy, modify, create derivative
9 * works, and distribute this software and its documentation without fee is hereby
10 * granted on a non-exclusive basis, provided that this notice and disclaimer
11 * of warranty appears in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
14 * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
15 * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
17 * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
18 * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
19 * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
20 * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
21 * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
22 * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
23 * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
24 * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
25 */
26
27 package gov.nist.secauto.swid.builder.resource;
28
29 public enum HashAlgorithm {
30 SHA_256(1, "SHA-256", 256, "http://www.w3.org/2001/04/xmlenc#sha256"),
31 SHA_256_128(2, "SHA_256_128", 128, "http://www.w3.org/2001/04/xmlenc#sha256"),
32 SHA_256_120(3, "SHA_256_120", 120, "http://www.w3.org/2001/04/xmlenc#sha256"),
33 SHA_256_96(4, "SHA_256_96", 96, "http://www.w3.org/2001/04/xmlenc#sha256"),
34 SHA_256_64(5, "SHA_256_64", 64, "http://www.w3.org/2001/04/xmlenc#sha256"),
35 SHA_256_32(6, "SHA_256_32", 32, "http://www.w3.org/2001/04/xmlenc#sha256"),
36 SHA_384(7, "SHA_384", 384, "http://www.w3.org/2001/04/xmldsig-more#sha384"),
37 SHA_512(8, "SHA-512", 512, "http://www.w3.org/2001/04/xmlenc#sha512"),
38 SHA_3_224(9, "SHA_3_224", 224, "http://www.w3.org/2007/05/xmldsig-more#sha3-224"),
39 SHA_3_256(9, "SHA_3_256", 256, "http://www.w3.org/2007/05/xmldsig-more#sha3-256"),
40 SHA_3_384(9, "SHA_3_384", 384, "http://www.w3.org/2007/05/xmldsig-more#sha3-384"),
41 SHA_3_512(9, "SHA_3_512", 512, "http://www.w3.org/2007/05/xmldsig-more#sha3-512");
42
43 /**
44 * From the Named Information Hash Algorithm Registry:
45 * https://www.iana.org/assignments/named-information/named-information.xhtml#hash-alg
46 */
47 private final int index;
48 private final String name;
49 /**
50 * The value length (in bits).
51 */
52 private final int valueLength;
53 private final String namespace;
54
55 private HashAlgorithm(int index, String name, int valueLength, String namespace) {
56 this.index = index;
57 this.name = name;
58 this.valueLength = valueLength;
59 this.namespace = namespace;
60 }
61
62 /**
63 * Retrieve the integer idenx value.
64 *
65 * @return the index value
66 */
67 public int getIndex() {
68 return index;
69 }
70
71 /**
72 * Retrieve the human-readable text value.
73 *
74 * @return the text name of the algorithm
75 */
76 public String getName() {
77 return name;
78 }
79
80 /**
81 * Retrieve the length in bits for the digest value. This can be used to truncate the digest result
82 * if the algorithm requires this.
83 *
84 * @return the valueLength (in bits)
85 */
86 public int getValueLength() {
87 return valueLength;
88 }
89
90 /**
91 * The namespace URI for the hash algorithm.
92 *
93 * @return a URI
94 */
95 public String getNamespace() {
96 return namespace;
97 }
98 }