|
1 | 1 | package com.cosmian.rest.kmip.data_structures; |
2 | 2 |
|
3 | | -import com.cosmian.rest.kmip.json.KmipChoice2; |
| 3 | +import java.util.Objects; |
| 4 | +import java.util.Optional; |
| 5 | + |
| 6 | +import com.cosmian.rest.kmip.json.KmipStruct; |
| 7 | +import com.cosmian.rest.kmip.types.Attributes; |
| 8 | +import com.fasterxml.jackson.annotation.JsonProperty; |
4 | 9 |
|
5 | 10 | /** |
6 | 11 | * The Key Value is used only inside a Key Block and is either a Byte String or a: • The Key Value structure contains |
|
10 | 15 | * encapsulated with (and possibly wrapped with) the key material itself. • The Key Value Byte String is either the |
11 | 16 | * wrapped TTLV-encoded Key Value structure, or the wrapped un-encoded value of the Byte String Key Material field. |
12 | 17 | */ |
13 | | -public class KeyValue extends KmipChoice2<PlainTextKeyValue, byte[]> { |
| 18 | +public class KeyValue implements KmipStruct { |
| 19 | + |
| 20 | + @JsonProperty(value = "KeyMaterial") |
| 21 | + private KeyMaterial keyMaterial; |
| 22 | + |
| 23 | + @JsonProperty(value = "Attributes") |
| 24 | + private Optional<Attributes> attributes; |
| 25 | + |
| 26 | + public KeyValue() { |
| 27 | + } |
| 28 | + |
| 29 | + public KeyValue(KeyMaterial keyMaterial, Optional<Attributes> attributes) { |
| 30 | + this.keyMaterial = keyMaterial; |
| 31 | + this.attributes = attributes; |
| 32 | + } |
| 33 | + |
| 34 | + public KeyMaterial getKeyMaterial() { |
| 35 | + return this.keyMaterial; |
| 36 | + } |
| 37 | + |
| 38 | + public void setKeyMaterial(KeyMaterial keyMaterial) { |
| 39 | + this.keyMaterial = keyMaterial; |
| 40 | + } |
| 41 | + |
| 42 | + public Optional<Attributes> getAttributes() { |
| 43 | + return this.attributes; |
| 44 | + } |
| 45 | + |
| 46 | + public void setAttributes(Optional<Attributes> attributes) { |
| 47 | + this.attributes = attributes; |
| 48 | + } |
| 49 | + |
| 50 | + public KeyValue keyMaterial(KeyMaterial keyMaterial) { |
| 51 | + setKeyMaterial(keyMaterial); |
| 52 | + return this; |
| 53 | + } |
14 | 54 |
|
15 | | - public KeyValue(Object value) { |
16 | | - super(value); |
| 55 | + public KeyValue attributes(Optional<Attributes> attributes) { |
| 56 | + setAttributes(attributes); |
| 57 | + return this; |
17 | 58 | } |
18 | 59 |
|
19 | 60 | @Override |
20 | 61 | public boolean equals(Object o) { |
21 | | - return super.equals(o); |
| 62 | + if (o == this) |
| 63 | + return true; |
| 64 | + if (!(o instanceof KeyValue)) { |
| 65 | + return false; |
| 66 | + } |
| 67 | + KeyValue keyValue = (KeyValue) o; |
| 68 | + return Objects.equals(keyMaterial, keyValue.keyMaterial) && Objects.equals(attributes, keyValue.attributes); |
22 | 69 | } |
23 | 70 |
|
24 | 71 | @Override |
25 | 72 | public int hashCode() { |
26 | | - return super.hashCode(); |
| 73 | + return Objects.hash(keyMaterial, attributes); |
27 | 74 | } |
28 | 75 |
|
29 | 76 | @Override |
30 | 77 | public String toString() { |
31 | | - return super.toString(); |
| 78 | + return "{" + " keyMaterial='" + getKeyMaterial() + "'" + ", attributes='" + getAttributes() + "'" + "}"; |
32 | 79 | } |
33 | 80 |
|
34 | 81 | } |
0 commit comments