// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java
// public static BigInteger generateRandomSerialNumber() {
//   return SerialNumberGenerator.instance.generateRandomSerialNumber();
// }
// 
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Signer.java
// public static interface SignerWithSerial extends Signer {
//   public Certificate sign();
// 
//   public SignerWithSerial setNotBefore(final ZonedDateTime notBefore);
// 
//   public SignerWithSerial setNotAfter(final ZonedDateTime notAfter);
// 
//   public SignerWithSerial validDuringYears(final int years);
// 
//   public SignerWithSerial addExtension(final CertExtension extension);
// 
//   public SignerWithSerial addExtension(ASN1ObjectIdentifier oid, boolean isCritical,
//       ASN1Encodable value);
// }
// 
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/ext/CertExtension.java
// public class CertExtension {
//   private final ASN1ObjectIdentifier oid;
//   private final boolean isCritical;
//   private final ASN1Encodable value;
// 
//   public CertExtension(final ASN1ObjectIdentifier oid, final boolean isCritical,
//       final ASN1Encodable value) {
//     this.oid = oid;
//     this.isCritical = isCritical;
//     this.value = value;
//   }
// 
//   public ASN1ObjectIdentifier getOid() {
//     return oid;
//   }
// 
//   public boolean isCritical() {
//     return isCritical;
//   }
// 
//   public ASN1Encodable getValue() {
//     return value;
//   }
// 
//   @Override
//   public String toString() {
//     return "Extension [" + oid + "=" + value + "]";
//   }
// 
// }


import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PublicKey;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import io.github.olivierlemasle.ca.Signer.SignerWithSerial;
import io.github.olivierlemasle.ca.ext.CertExtension;
package io.github.olivierlemasle.ca;





class SignerImpl implements Signer, SignerWithSerial {
  private static final String SIGNATURE_ALGORITHM = "SHA256withRSA";

  private final KeyPair signerKeyPair;
  private final DistinguishedName signerDn;
  private final PublicKey publicKey;
  private final DistinguishedName dn;
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java
// public static BigInteger generateRandomSerialNumber() {
//   return SerialNumberGenerator.instance.generateRandomSerialNumber();
// }
// 
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Signer.java
// public static interface SignerWithSerial extends Signer {
//   public Certificate sign();
// 
//   public SignerWithSerial setNotBefore(final ZonedDateTime notBefore);
// 
//   public SignerWithSerial setNotAfter(final ZonedDateTime notAfter);
// 
//   public SignerWithSerial validDuringYears(final int years);
// 
//   public SignerWithSerial addExtension(final CertExtension extension);
// 
//   public SignerWithSerial addExtension(ASN1ObjectIdentifier oid, boolean isCritical,
//       ASN1Encodable value);
// }
// 
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/ext/CertExtension.java
// public class CertExtension {
//   private final ASN1ObjectIdentifier oid;
//   private final boolean isCritical;
//   private final ASN1Encodable value;
// 
//   public CertExtension(final ASN1ObjectIdentifier oid, final boolean isCritical,
//       final ASN1Encodable value) {
//     this.oid = oid;
//     this.isCritical = isCritical;
//     this.value = value;
//   }
// 
//   public ASN1ObjectIdentifier getOid() {
//     return oid;
//   }
// 
//   public boolean isCritical() {
//     return isCritical;
//   }
// 
//   public ASN1Encodable getValue() {
//     return value;
//   }
// 
//   @Override
//   public String toString() {
//     return "Extension [" + oid + "=" + value + "]";
//   }
// 
// }


// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/SignerImpl.java
import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PublicKey;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import io.github.olivierlemasle.ca.Signer.SignerWithSerial;
import io.github.olivierlemasle.ca.ext.CertExtension;

package io.github.olivierlemasle.ca;





class SignerImpl implements Signer, SignerWithSerial {
  private static final String SIGNATURE_ALGORITHM = "SHA256withRSA";

  private final KeyPair signerKeyPair;
  private final DistinguishedName signerDn;
  private final PublicKey publicKey;
  private final DistinguishedName dn;
  private final List<CertExtension> extensions = new ArrayList<>();