1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package gov.nist.secauto.swid.builder.resource.firmware;
28
29 import gov.nist.secauto.swid.builder.resource.HashAlgorithm;
30 import gov.nist.secauto.swid.builder.resource.HashUtils;
31
32 import java.io.File;
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.security.NoSuchAlgorithmException;
36 import java.util.Objects;
37
38 public class FirmwarePayloadDigest {
39 private final DigestType type;
40 private final HashAlgorithm algorithm;
41 private final byte[] value;
42 private final byte[] guidance;
43
44 public FirmwarePayloadDigest(DigestType type, HashAlgorithm algorithm, File file)
45 throws NoSuchAlgorithmException, IOException {
46 this(type, algorithm, HashUtils.hash(algorithm, file));
47 }
48
49 public FirmwarePayloadDigest(DigestType type, HashAlgorithm algorithm, File file, byte[] guidance)
50 throws NoSuchAlgorithmException, IOException {
51 this(type, algorithm, HashUtils.hash(algorithm, file), guidance);
52 }
53
54 public FirmwarePayloadDigest(DigestType type, HashAlgorithm algorithm, InputStream is)
55 throws NoSuchAlgorithmException, IOException {
56 this(type, algorithm, HashUtils.hash(algorithm, is));
57 }
58
59 public FirmwarePayloadDigest(DigestType type, HashAlgorithm algorithm, InputStream is, byte[] guidance)
60 throws NoSuchAlgorithmException, IOException {
61 this(type, algorithm, HashUtils.hash(algorithm, is), guidance);
62 }
63
64 public FirmwarePayloadDigest(DigestType type, HashAlgorithm algorithm, byte[] value) {
65 this(type, algorithm, value, null);
66 }
67
68 public FirmwarePayloadDigest(DigestType type, HashAlgorithm algorithm, byte[] value, byte[] guidance) {
69 super();
70 Objects.requireNonNull(type, "type");
71 Objects.requireNonNull(algorithm, "algorithm");
72 Objects.requireNonNull(value, "value");
73 this.type = type;
74 this.algorithm = algorithm;
75 this.value = value;
76 this.guidance = guidance;
77 }
78
79
80
81
82 public DigestType getType() {
83 return type;
84 }
85
86
87
88
89 public HashAlgorithm getAlgorithm() {
90 return algorithm;
91 }
92
93
94
95
96 public byte[] getValue() {
97 return value;
98 }
99
100
101
102
103 public byte[] getGuidance() {
104 return guidance;
105 }
106 }