package io.github.olivierlemasle.ca;

import java.security.PublicKey;

import org.bouncycastle.openssl.PEMException;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
import org.bouncycastle.pkcs.PKCS10CertificationRequest;

class CsrImpl implements CSR {
  private final PKCS10CertificationRequest request;

  public CsrImpl(final PKCS10CertificationRequest request) {
    this.request = request;
  }

  @Override
  public DistinguishedName getSubject() {
    return new BcX500NameDnImpl(request.getSubject());
  }

  @Override
  public PublicKey getPublicKey() {
    try {
      return (new JcaPEMKeyConverter()).getPublicKey(request.getSubjectPublicKeyInfo());
    } catch (final PEMException e) {
      throw new CaException(e);
    }
  }

}

@@ -278,42 +278,65 @@
 nal 
-PKCS10CertificationRequest request
+DistinguishedName dn;%0A  private final PublicKey publicKey
 ;%0A%0A 
@@ -403,221 +403,84 @@
     
-this.request = request;%0A  %7D%0A%0A  @Override%0A  public DistinguishedName getSubject() %7B%0A    return new BcX500NameDnImpl(request.getSubject());%0A  %7D%0A%0A  @Override%0A  public PublicKey getPublicKey() %7B%0A    try %7B%0A      return
+dn = new BcX500NameDnImpl(request.getSubject());%0A    try %7B%0A      publicKey =
  (ne
@@ -632,10 +632,159 @@
  %7D%0A  %7D%0A%0A
+  @Override%0A  public DistinguishedName getSubject() %7B%0A    return dn;%0A  %7D%0A%0A  @Override%0A  public PublicKey getPublicKey() %7B%0A    return publicKey;%0A  %7D%0A%0A
 %7D%0A

Optimize CsrImpl