package com.airlock.iam.factor.domain.model.fido;

import com.airlock.iam.common.api.domain.model.binary.ByteSequence;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Objects;
import lombok.NonNull;
import org.apache.commons.lang3.Validate;

public final class FidoPublicKey {
   private static final int MAXIMAL_LENGTH_IN_BYTES = 1024;
   @NonNull
   private final ByteSequence publicKey;

   private FidoPublicKey(byte[] publicKey) {
      Objects.requireNonNull(publicKey);
      Validate.isTrue(publicKey.length <= 1024, String.format("The given public key is too long. Keys up to %d bytes are supported.", 1024), new Object[0]);
      this.publicKey = ByteSequence.byteSequence(publicKey);
   }

   public static FidoPublicKey publicKey(byte[] publicKey) {
      return new FidoPublicKey(publicKey);
   }

   public byte[] bytes() {
      return this.publicKey.bytes();
   }

   public String base64Url() {
      return this.publicKey.base64Url();
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof FidoPublicKey other)) {
         return false;
      } else {
         Object this$publicKey = this.publicKey;
         Object other$publicKey = other.publicKey;
         return this$publicKey == null ? other$publicKey == null : this$publicKey.equals(other$publicKey);
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      Object $publicKey = this.publicKey;
      return result * 59 + ($publicKey == null ? 43 : $publicKey.hashCode());
   }
}
