package io.vertx.ext.auth;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;

/**
 * Options describing Key stored in PEM format.
 *
 * @author <a href="mailto:plopes@redhat.com">Paulo Lopes</a>
 */
@DataObject(generateConverter = true)
public class PubSecKeyOptions {

  private String algorithm;
  private String buffer;
  private String id;

  private boolean certificate;
  private Boolean symmetric;
  private String publicKey;
  private String secretKey;

  /**
   * Default constructor
   */
  public PubSecKeyOptions() {
  }

  /**
   * Copy constructor
   *
   * @param other the options to copy
   */
  public PubSecKeyOptions(PubSecKeyOptions other) {
    algorithm = other.getAlgorithm();
    buffer = other.getBuffer();
    id = other.getId();
    publicKey = other.getPublicKey();
    secretKey = other.getSecretKey();
    symmetric = other.isSymmetric();
    certificate = other.isCertificate();
  }

  /**
   * Constructor to create an options from JSON
   *
   * @param json the JSON
   */
  public PubSecKeyOptions(JsonObject json) {
    PubSecKeyOptionsConverter.fromJson(json, this);
  }

  public JsonObject toJson() {
    JsonObject json = new JsonObject();
    PubSecKeyOptionsConverter.toJson(this, json);
    return json;
  }

  public String getAlgorithm() {
    return algorithm;
  }

  public PubSecKeyOptions setAlgorithm(String algorithm) {
    this.algorithm = algorithm;
    return this;
  }

  /**
   * The PEM or Secret key buffer
   * @return the buffer.
   */
  public String getBuffer() {
    return buffer;
  }

  /**
   * The PEM or Secret key buffer
   * @return self.
   */
  public PubSecKeyOptions setBuffer(String buffer) {
    this.buffer = buffer;
    return this;
  }

  public String getId() {
    return id;
  }

  public PubSecKeyOptions setId(String id) {
    this.id = id;
    return this;
  }

  @Deprecated
  public String getPublicKey() {
    return publicKey;
  }

  @Deprecated
  public PubSecKeyOptions setPublicKey(String publicKey) {
    this.publicKey = publicKey;
    return this;
  }

  @Deprecated
  public String getSecretKey() {
    return secretKey;
  }

  @Deprecated
  public PubSecKeyOptions setSecretKey(String secretKey) {
    this.secretKey = secretKey;
    return this;
  }

  @Deprecated
  public boolean isSymmetric() {
    if (symmetric == null) {
      // attempt to derive the kind of key
      return algorithm.startsWith("HS") && publicKey == null && secretKey != null;
    }
    return symmetric;
  }

  @Deprecated
  public PubSecKeyOptions setSymmetric(boolean symmetric) {
    this.symmetric = symmetric;
    return this;
  }

  @Deprecated
  public boolean isCertificate() {
    return certificate;
  }

  @Deprecated
  public PubSecKeyOptions setCertificate(boolean certificate) {
    this.certificate = certificate;
    return this;
  }
}

@@ -1957,206 +1957,1032 @@
 %0A%0A  
-@Deprecated%0A  public PubSecKeyOptions setPublicKey(String publicKey) %7B%0A    this.publicKey = publicKey;%0A    return this;%0A  %7D%0A%0A  @Deprecated%0A  public String getSecretKey() %7B%0A    return secretKey;%0A  %7D%0A
+/**%0A   * @deprecated This setter ignored the PEM prefix and suffix which would assume the key to be RSA.%0A   *%0A   * Use %7B@link #setBuffer(String)%7D with the full content of your OpenSSL pem file. A PEM file must%0A   * contain at least 3 lines:%0A   *%0A   * %3Cpre%3E%0A   *   -----BEGIN PUBLIC KEY----%0A   *   ...%0A   *   -----END PUBLIC KEY---%0A   * %3C/pre%3E%0A   * @param publicKey the naked public key%0A   * @return self%0A   */%0A  @Deprecated%0A  public PubSecKeyOptions setPublicKey(String publicKey) %7B%0A    this.publicKey = publicKey;%0A    return this;%0A  %7D%0A%0A  @Deprecated%0A  public String getSecretKey() %7B%0A    return secretKey;%0A  %7D%0A%0A  /**%0A   * @deprecated This setter ignored the PEM prefix and suffix which would assume the key to be RSA.%0A   *%0A   * Use %7B@link #setBuffer(String)%7D with the full content of your OpenSSL pem file. A PEM file must%0A   * contain at least 3 lines:%0A   *%0A   * %3Cpre%3E%0A   *   -----BEGIN PRIVATE KEY----%0A   *   ...%0A   *   -----END PRIVATE KEY---%0A   * %3C/pre%3E%0A   * @param secretKey the naked public key%0A   * @return self%0A   */
 %0A  @

Document why the methods are deprecated