All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.resourcemanager.databoxedge.models.AsymmetricEncryptedSecret Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.databoxedge.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
 * Represent the secrets intended for encryption with asymmetric key pair.
 */
@Fluent
public final class AsymmetricEncryptedSecret implements JsonSerializable {
    /*
     * The value of the secret.
     */
    private String value;

    /*
     * Thumbprint certificate used to encrypt \"Value\". If the value is unencrypted, it will be null.
     */
    private String encryptionCertThumbprint;

    /*
     * The algorithm used to encrypt "Value".
     */
    private EncryptionAlgorithm encryptionAlgorithm;

    /**
     * Creates an instance of AsymmetricEncryptedSecret class.
     */
    public AsymmetricEncryptedSecret() {
    }

    /**
     * Get the value property: The value of the secret.
     * 
     * @return the value value.
     */
    public String value() {
        return this.value;
    }

    /**
     * Set the value property: The value of the secret.
     * 
     * @param value the value value to set.
     * @return the AsymmetricEncryptedSecret object itself.
     */
    public AsymmetricEncryptedSecret withValue(String value) {
        this.value = value;
        return this;
    }

    /**
     * Get the encryptionCertThumbprint property: Thumbprint certificate used to encrypt \"Value\". If the value is
     * unencrypted, it will be null.
     * 
     * @return the encryptionCertThumbprint value.
     */
    public String encryptionCertThumbprint() {
        return this.encryptionCertThumbprint;
    }

    /**
     * Set the encryptionCertThumbprint property: Thumbprint certificate used to encrypt \"Value\". If the value is
     * unencrypted, it will be null.
     * 
     * @param encryptionCertThumbprint the encryptionCertThumbprint value to set.
     * @return the AsymmetricEncryptedSecret object itself.
     */
    public AsymmetricEncryptedSecret withEncryptionCertThumbprint(String encryptionCertThumbprint) {
        this.encryptionCertThumbprint = encryptionCertThumbprint;
        return this;
    }

    /**
     * Get the encryptionAlgorithm property: The algorithm used to encrypt "Value".
     * 
     * @return the encryptionAlgorithm value.
     */
    public EncryptionAlgorithm encryptionAlgorithm() {
        return this.encryptionAlgorithm;
    }

    /**
     * Set the encryptionAlgorithm property: The algorithm used to encrypt "Value".
     * 
     * @param encryptionAlgorithm the encryptionAlgorithm value to set.
     * @return the AsymmetricEncryptedSecret object itself.
     */
    public AsymmetricEncryptedSecret withEncryptionAlgorithm(EncryptionAlgorithm encryptionAlgorithm) {
        this.encryptionAlgorithm = encryptionAlgorithm;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (value() == null) {
            throw LOGGER.atError()
                .log(
                    new IllegalArgumentException("Missing required property value in model AsymmetricEncryptedSecret"));
        }
        if (encryptionAlgorithm() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property encryptionAlgorithm in model AsymmetricEncryptedSecret"));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(AsymmetricEncryptedSecret.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("value", this.value);
        jsonWriter.writeStringField("encryptionAlgorithm",
            this.encryptionAlgorithm == null ? null : this.encryptionAlgorithm.toString());
        jsonWriter.writeStringField("encryptionCertThumbprint", this.encryptionCertThumbprint);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of AsymmetricEncryptedSecret from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of AsymmetricEncryptedSecret if the JsonReader was pointing to an instance of it, or null if
     * it was pointing to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the AsymmetricEncryptedSecret.
     */
    public static AsymmetricEncryptedSecret fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            AsymmetricEncryptedSecret deserializedAsymmetricEncryptedSecret = new AsymmetricEncryptedSecret();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("value".equals(fieldName)) {
                    deserializedAsymmetricEncryptedSecret.value = reader.getString();
                } else if ("encryptionAlgorithm".equals(fieldName)) {
                    deserializedAsymmetricEncryptedSecret.encryptionAlgorithm
                        = EncryptionAlgorithm.fromString(reader.getString());
                } else if ("encryptionCertThumbprint".equals(fieldName)) {
                    deserializedAsymmetricEncryptedSecret.encryptionCertThumbprint = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedAsymmetricEncryptedSecret;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy