package com.airlock.iam.common.domain.service.csp;

import com.airlock.iam.base.misc.util.Base64Util;
import com.airlock.iam.security.util.SeededSecureRandom;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public final class CspNonce {
   private static final SeededSecureRandom RANDOM = SeededSecureRandom.getInstance();
   private static final int TOKEN_LENGTH_IN_BYTES = 32;
   private final String nonce;

   public static CspNonce generateCspNonce() {
      byte[] random = new byte[32];
      RANDOM.nextBytes(random);
      return new CspNonce(Base64Util.encodeUrlSafeToString(random, true));
   }

   @SuppressFBWarnings(justification = "generated code")
   public String nonce() {
      return this.nonce;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   private CspNonce(String nonce) {
      this.nonce = nonce;
   }
}
