/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2008 L.Meckert - laurent.meckert.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package fr.gouv.finances.cp.xemelios.plugin.signature;
import javax.xml.namespace.NamespaceContext;
import java.security.cert.X509Certificate;

/**
 * verification d'une signature
 * @author laurent.meckert
 */
public interface ISignatureVerifier {

  /**
   *  Appelle au besoin les initialisations necessaires
   */
  //  abstract void initialize() throws Exception;
  void initialize() throws Exception;

  /**
   *  Verifie la signature de la chaine Xml passee en parametre
   *  le statut complet ( de type bitmask)  sera accessible par getStatus()
   *  si succes = la signature proprement dite sera recuperable
   *  en appelant getSignatureAsXmlString()
   *  Si il y a un certificat X509 , ce certificat sera recuperable
   *  en appelant getCert()
   *@return  true si le digest est OK false sinon
   *@param s une chaine xml signee
   */
  // abstract boolean verifyXml(String s) throws Exception;
  boolean verifyXml(String s) throws Exception;

  /**
   * Verifie la signature du fichier passee en parametre
   *@return  true si le digest est OK false sinon
   *@param s un fichier xml signe
   */
  // abstract boolean verifyFile(String s) throws Exception;
  boolean verifyFile(String s) throws Exception;

  /**
   * Post traitement
   * pex signe ou recopie la signature dans des elements
   *@return  true si  OK false sinon
   *@param outfilename un fichier xml a creer
   */
  boolean postTraitement(String outfilename) throws Exception;

  /**
   * Procede au besoin aux nettoyages apres execution
   */
  // abstract void terminate() throws Exception;
  void terminate() throws Exception;

  /**
   *
   *@return true si il y a qq chose a faire apres la validation
   *
   */
  public boolean hasPostTrait();

  /**
   *
   *@return true si il compte valider les certificats
   *
   */
  public boolean hasCertificatesValidation();

  public void setExternalDTD(String externalDTD);

  public boolean isDoSchemaValidation();

  public void setDoSchemaValidation(boolean doSchemaValidation);

  public void setSignatureXPath(String signatureXPath);

   public void setNsCtx(NamespaceContext ctx);

  public int getFoundSignatures();

  public Integer getIndividualStatus(int i);

  public boolean digestValid();

  public boolean digestValid(int istatus);

  public boolean isX509Cert(int istatus);

  public X509Certificate getCert();

  public X509Certificate getCert(int i);

  public String getStatusAsString();

  public int getStatusAsSeverity();
}

