|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +// Code generated by Microsoft (R) TypeSpec Code Generator. |
| 4 | + |
| 5 | +package com.azure.security.keyvault.keys.implementation.models; |
| 6 | + |
| 7 | +import com.azure.core.annotation.Fluent; |
| 8 | +import com.azure.core.annotation.Generated; |
| 9 | +import com.azure.core.util.Base64Url; |
| 10 | +import com.azure.core.util.CoreUtils; |
| 11 | +import com.azure.json.JsonReader; |
| 12 | +import com.azure.json.JsonSerializable; |
| 13 | +import com.azure.json.JsonToken; |
| 14 | +import com.azure.json.JsonWriter; |
| 15 | +import java.io.IOException; |
| 16 | +import java.util.Objects; |
| 17 | + |
| 18 | +/** |
| 19 | + * The key attestation information. |
| 20 | + */ |
| 21 | +@Fluent |
| 22 | +public final class KeyAttestation implements JsonSerializable<KeyAttestation> { |
| 23 | + /* |
| 24 | + * A base64url-encoded string containing certificates in PEM format, used for attestation validation. |
| 25 | + */ |
| 26 | + @Generated |
| 27 | + private Base64Url certificatePemFile; |
| 28 | + |
| 29 | + /* |
| 30 | + * The attestation blob bytes encoded as base64url string corresponding to a private key. |
| 31 | + */ |
| 32 | + @Generated |
| 33 | + private Base64Url privateKeyAttestation; |
| 34 | + |
| 35 | + /* |
| 36 | + * The attestation blob bytes encoded as base64url string corresponding to a public key in case of asymmetric key. |
| 37 | + */ |
| 38 | + @Generated |
| 39 | + private Base64Url publicKeyAttestation; |
| 40 | + |
| 41 | + /* |
| 42 | + * The version of the attestation. |
| 43 | + */ |
| 44 | + @Generated |
| 45 | + private String version; |
| 46 | + |
| 47 | + /** |
| 48 | + * Creates an instance of KeyAttestation class. |
| 49 | + */ |
| 50 | + @Generated |
| 51 | + public KeyAttestation() { |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Get the certificatePemFile property: A base64url-encoded string containing certificates in PEM format, used for |
| 56 | + * attestation validation. |
| 57 | + * |
| 58 | + * @return the certificatePemFile value. |
| 59 | + */ |
| 60 | + @Generated |
| 61 | + public byte[] getCertificatePemFile() { |
| 62 | + if (this.certificatePemFile == null) { |
| 63 | + return null; |
| 64 | + } |
| 65 | + return this.certificatePemFile.decodedBytes(); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Set the certificatePemFile property: A base64url-encoded string containing certificates in PEM format, used for |
| 70 | + * attestation validation. |
| 71 | + * |
| 72 | + * @param certificatePemFile the certificatePemFile value to set. |
| 73 | + * @return the KeyAttestation object itself. |
| 74 | + */ |
| 75 | + @Generated |
| 76 | + public KeyAttestation setCertificatePemFile(byte[] certificatePemFile) { |
| 77 | + if (certificatePemFile == null) { |
| 78 | + this.certificatePemFile = null; |
| 79 | + } else { |
| 80 | + this.certificatePemFile = Base64Url.encode(CoreUtils.clone(certificatePemFile)); |
| 81 | + } |
| 82 | + return this; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Get the privateKeyAttestation property: The attestation blob bytes encoded as base64url string corresponding to a |
| 87 | + * private key. |
| 88 | + * |
| 89 | + * @return the privateKeyAttestation value. |
| 90 | + */ |
| 91 | + @Generated |
| 92 | + public byte[] getPrivateKeyAttestation() { |
| 93 | + if (this.privateKeyAttestation == null) { |
| 94 | + return null; |
| 95 | + } |
| 96 | + return this.privateKeyAttestation.decodedBytes(); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Set the privateKeyAttestation property: The attestation blob bytes encoded as base64url string corresponding to a |
| 101 | + * private key. |
| 102 | + * |
| 103 | + * @param privateKeyAttestation the privateKeyAttestation value to set. |
| 104 | + * @return the KeyAttestation object itself. |
| 105 | + */ |
| 106 | + @Generated |
| 107 | + public KeyAttestation setPrivateKeyAttestation(byte[] privateKeyAttestation) { |
| 108 | + if (privateKeyAttestation == null) { |
| 109 | + this.privateKeyAttestation = null; |
| 110 | + } else { |
| 111 | + this.privateKeyAttestation = Base64Url.encode(CoreUtils.clone(privateKeyAttestation)); |
| 112 | + } |
| 113 | + return this; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Get the publicKeyAttestation property: The attestation blob bytes encoded as base64url string corresponding to a |
| 118 | + * public key in case of asymmetric key. |
| 119 | + * |
| 120 | + * @return the publicKeyAttestation value. |
| 121 | + */ |
| 122 | + @Generated |
| 123 | + public byte[] getPublicKeyAttestation() { |
| 124 | + if (this.publicKeyAttestation == null) { |
| 125 | + return null; |
| 126 | + } |
| 127 | + return this.publicKeyAttestation.decodedBytes(); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Set the publicKeyAttestation property: The attestation blob bytes encoded as base64url string corresponding to a |
| 132 | + * public key in case of asymmetric key. |
| 133 | + * |
| 134 | + * @param publicKeyAttestation the publicKeyAttestation value to set. |
| 135 | + * @return the KeyAttestation object itself. |
| 136 | + */ |
| 137 | + @Generated |
| 138 | + public KeyAttestation setPublicKeyAttestation(byte[] publicKeyAttestation) { |
| 139 | + if (publicKeyAttestation == null) { |
| 140 | + this.publicKeyAttestation = null; |
| 141 | + } else { |
| 142 | + this.publicKeyAttestation = Base64Url.encode(CoreUtils.clone(publicKeyAttestation)); |
| 143 | + } |
| 144 | + return this; |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Get the version property: The version of the attestation. |
| 149 | + * |
| 150 | + * @return the version value. |
| 151 | + */ |
| 152 | + @Generated |
| 153 | + public String getVersion() { |
| 154 | + return this.version; |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Set the version property: The version of the attestation. |
| 159 | + * |
| 160 | + * @param version the version value to set. |
| 161 | + * @return the KeyAttestation object itself. |
| 162 | + */ |
| 163 | + @Generated |
| 164 | + public KeyAttestation setVersion(String version) { |
| 165 | + this.version = version; |
| 166 | + return this; |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * {@inheritDoc} |
| 171 | + */ |
| 172 | + @Generated |
| 173 | + @Override |
| 174 | + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { |
| 175 | + jsonWriter.writeStartObject(); |
| 176 | + jsonWriter.writeStringField("certificatePemFile", Objects.toString(this.certificatePemFile, null)); |
| 177 | + jsonWriter.writeStringField("privateKeyAttestation", Objects.toString(this.privateKeyAttestation, null)); |
| 178 | + jsonWriter.writeStringField("publicKeyAttestation", Objects.toString(this.publicKeyAttestation, null)); |
| 179 | + jsonWriter.writeStringField("version", this.version); |
| 180 | + return jsonWriter.writeEndObject(); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Reads an instance of KeyAttestation from the JsonReader. |
| 185 | + * |
| 186 | + * @param jsonReader The JsonReader being read. |
| 187 | + * @return An instance of KeyAttestation if the JsonReader was pointing to an instance of it, or null if it was |
| 188 | + * pointing to JSON null. |
| 189 | + * @throws IOException If an error occurs while reading the KeyAttestation. |
| 190 | + */ |
| 191 | + @Generated |
| 192 | + public static KeyAttestation fromJson(JsonReader jsonReader) throws IOException { |
| 193 | + return jsonReader.readObject(reader -> { |
| 194 | + KeyAttestation deserializedKeyAttestation = new KeyAttestation(); |
| 195 | + while (reader.nextToken() != JsonToken.END_OBJECT) { |
| 196 | + String fieldName = reader.getFieldName(); |
| 197 | + reader.nextToken(); |
| 198 | + |
| 199 | + if ("certificatePemFile".equals(fieldName)) { |
| 200 | + deserializedKeyAttestation.certificatePemFile |
| 201 | + = reader.getNullable(nonNullReader -> new Base64Url(nonNullReader.getString())); |
| 202 | + } else if ("privateKeyAttestation".equals(fieldName)) { |
| 203 | + deserializedKeyAttestation.privateKeyAttestation |
| 204 | + = reader.getNullable(nonNullReader -> new Base64Url(nonNullReader.getString())); |
| 205 | + } else if ("publicKeyAttestation".equals(fieldName)) { |
| 206 | + deserializedKeyAttestation.publicKeyAttestation |
| 207 | + = reader.getNullable(nonNullReader -> new Base64Url(nonNullReader.getString())); |
| 208 | + } else if ("version".equals(fieldName)) { |
| 209 | + deserializedKeyAttestation.version = reader.getString(); |
| 210 | + } else { |
| 211 | + reader.skipChildren(); |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + return deserializedKeyAttestation; |
| 216 | + }); |
| 217 | + } |
| 218 | +} |
0 commit comments