package com.l7tech.security.cert;

import com.l7tech.util.HexUtils;
import com.l7tech.util.PoolByteArrayOutputStream;
import com.l7tech.util.ResourceUtils;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.cert.X509Certificate;

public class X509CertificateAdapter extends XmlAdapter<String, X509Certificate> {
   public X509Certificate unmarshal(String var1) throws Exception {
      byte[] var2 = HexUtils.decodeBase64(var1);
      ByteArrayInputStream var3 = new ByteArrayInputStream(var2);
      ObjectInputStream var4 = new ObjectInputStream(var3);
      return (X509Certificate)var4.readObject();
   }

   public String marshal(X509Certificate var1) throws Exception {
      ObjectOutputStream var3 = null;

      try {
         PoolByteArrayOutputStream var2 = new PoolByteArrayOutputStream(1024);
         var3 = new ObjectOutputStream(var2);
         var3.writeObject(var1);
         byte[] var4 = var2.detachPooledByteArray();
         return HexUtils.encodeBase64(var4);
      } finally {
         ResourceUtils.closeQuietly(var3);
      }
   }
}
