/*************************************************
* X.509 Certificates Header File                 *
* (C) 1999-2003 The Botan Project                *
*************************************************/

#ifndef BOTAN_X509_CERTS_H__
#define BOTAN_X509_CERTS_H__

#include <botan/x509_obj.h>
#include <botan/x509_key.h>
#include <botan/pkcs8.h>
#include <map>

namespace Botan {

static const u32bit NO_CERT_PATH_LIMIT = 0xFFFFFFFF;

/*************************************************
* X.509 Certificate                              *
*************************************************/
class X509_Certificate : public X509_Object
   {
   public:
      struct X509_Error : public Exception
         {
         X509_Error(const std::string& error) :
            Exception("X509_Certificate: " + error) {}
         };

      u32bit x509_version() const;

      std::string start_time() const;
      std::string end_time() const;

      std::string subject_info(const std::string&) const;
      std::string issuer_info(const std::string&) const;
      X509_DN issuer_dn() const;
      X509_DN subject_dn() const;

      SecureVector<byte> serial_number() const;
      X509_PublicKey* subject_public_key() const;
      bool self_signed() const;

      bool is_CA_cert() const;
      u32bit path_limit() const;
      Key_Constraints get_constraints() const;
      std::vector<OID> get_ex_constraints() const;

      SecureVector<byte> authority_key_id() const;
      SecureVector<byte> subject_key_id() const;

      bool operator==(const X509_Certificate&) const;

      void force_decode();

      X509_Certificate(DataSource&, X509_Encoding = PEM);
      X509_Certificate(const std::string&, X509_Encoding = PEM);
   private:
      friend class X509_CA;
      X509_Certificate() {}
      void handle_v3_extension(const Extension&);

      std::multimap<std::string, std::string> subject, issuer;
      SecureVector<byte> v3_issuer_key_id, v3_subject_key_id;
      SecureVector<byte> v2_issuer_key_id, v2_subject_key_id;
      SecureVector<byte> pub_key, serial;
      X509_Time start, end;
      Key_Constraints constraints;
      std::vector<OID> ex_constraints;
      u32bit version, max_path_len;
      bool is_ca;
   };

/*************************************************
* X.509 Certificate Comparison                   *
*************************************************/
bool operator!=(const X509_Certificate&, const X509_Certificate&);

}

#endif
