{-------------------------------------------------------------------------------
Translated form headers/x509.h

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      THIS ISN'T COMPLETE TRANSLATION OF C++ HEADERS AND NEVER WILL BE.

  FOR COPYRIGHT OF ORIGINAL ERIC YOUNG SOFTWARE LOOK AT FILES IN HEADER FOLDER.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

      Copyright (C) 1998 by Jan Tomasek <xtomasej@fel.cvut.cz>
      All rights reserved.

      This library is free for commercial and non-commercial use as long as
      the following conditions are aheared to.  The following conditions
      apply to all code found in this distribution.  The documentation
      included with this distribution is covered by the same copyright terms.

      Copyright remains Jan Tomasek's, and as such any Copyright notices in
      the code are not to be removed.
      If this package is used in a product, Jan Tomasek should be given
      attribution as the author of the parts of the library used.
      This can be in the form of a textual message at program startup or
      in documentation (online or textual) provided with the package.

      Redistribution and use in source and binary forms, with or without
      modification, are permitted provided that the following conditions
      are met:
      1. Redistributions of source code must retain the copyright
         notice, this list of conditions and the following disclaimer.
      2. Redistributions in binary form must reproduce the above copyright
         notice, this list of conditions and the following disclaimer in the
         documentation and/or other materials provided with the distribution.
      3. All advertising materials mentioning features or use of this software
         must display the following acknowledgement:
             "This product includes software written by
              Jan Tomasek <xtomasej@fel.cvut.cz>"

      THIS SOFTWARE IS PROVIDED BY JAN TOMASEK ``AS IS'' AND
      ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
      FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      SUCH DAMAGE.

      The licence and distribution terms for any publically available version or
      derivative of this code cannot be changed.  i.e. this code cannot simply
      be copied and put under another distribution licence
      [including the GNU Public Licence.]
-------------------------------------------------------------------------------}
  PASN1_OBJECT = Pointer;
  PASN1_TYPE   = Pointer;
  PASN1_UTCTIME= Pointer;
  PASN1_BIT_STRING= Pointer;
  PASN1_OCTET_STRING= Pointer;
  PASN1_STRING = Pointer;
  PASN1_INTEGER = Pointer;
  PASN1_IA5STRING = Pointer;

  PX509_ALGOR =^TX509_ALGOR;
  PX509_VAL =^TX509_VAL;
  PX509_PUBKEY =^TX509_PUBKEY;
  PX509_SIG =^TX509_SIG;
  PX509_NAME_ENTRY =^TX509_NAME_ENTRY;
  PX509_NAME =^TX509_NAME;
  PX509_EXTENSION =^TX509_EXTENSION;
  PX509_EXTENSION_METHOD =^TX509_EXTENSION_METHOD;
  PX509_REQ_INFO =^TX509_REQ_INFO;
  PX509_REQ =^TX509_REQ;
  PX509_CINF =^TX509_CINF;
  PX509 =^TX509;
  PX509_REVOKED =^TX509_REVOKED;
  PX509_CRL_INFO =^TX509_CRL_INFO;
  PX509_CRL =^TX509_CRL;
  PX509_ATTRIBUTE =^TX509_ATTRIBUTE;
  PX509_PKEY =^TX509_PKEY;
  PNETSCAPE_SPKAC =^TNETSCAPE_SPKAC;
  PNETSCAPE_SPKI =^TNETSCAPE_SPKI;
  PCBC_PARAM = ^TCBC_PARAM;
  PX509_INFO = pointer;


  TX509_ALGOR = record
    algorithm : PASN1_OBJECT;                   {ASN1_OBJECT *algorithm;}
    parameter : PASN1_TYPE;                     {ASN1_TYPE *parameter;}
  End;

  TX509_VAL = record
    notBefore : PASN1_UTCTIME;                  {ASN1_UTCTIME *notBefore;}
    notAfter  : PASN1_UTCTIME;                  {ASN1_UTCTIME *notAfter;}
  End;

  TX509_PUBKEY = record
    algor      : PX509_ALGOR;                   {X509_ALGOR *algor;}
    public_key : PASN1_BIT_STRING;              {ASN1_BIT_STRING *public_key;}
    pkey       : PEVP_PKEY;                     {struct evp_pkey_st /* EVP_PKEY*/ *pkey;}
  End;

  TX509_SIG = record
    algor      : PX509_ALGOR;                   {X509_ALGOR *algor;}
    digest     : PASN1_OCTET_STRING;            {ASN1_OCTET_STRING *digest;}
  End;

  TX509_NAME_ENTRY = record
    aobject    : PASN1_OBJECT;                  {ASN1_OBJECT *object;}
    value      : PASN1_STRING;                  {ASN1_STRING *value;}
    aset       : int;                           {int set;}
    size       : int;                           {int size;       /* temp variable */}
  End;

  { we always keep X509_NAMEs in 2 forms. }
  TX509_NAME = record
    {of X509_NAME_ENTRY}
    entries : PSTACK;                           {STACK *entries; /* of X509_NAME_ENTRY */                 }
    {true if 'bytes' needs to be built}
    modified: int;                              {int modified;  /* true if 'bytes' needs to be built */  }
                                                {#ifdef HEADER_BUFFER_H                                          }
    bytes   : PBUF_MEM;                         {       BUF_MEM *bytes;                                          }
                                                {#else                                                           }
                                                {       char *bytes;                                             }
                                                {#endif                                                          }
  End;

  TX509_EXTENSION = record
    aobject       : PASN1_OBJECT;               {ASN1_OBJECT *object;}
    critical      : short;                      {short critical;}
    netscape_hack : short;                      {short netscape_hack;}
    value         : PASN1_OCTET_STRING;         {ASN1_OCTET_STRING *value;}
  End;


  TX509_EXTENSION_METHOD = record
    nid           : int;                        {int nid;      }
    data_type     : int;                        {int data_type;}
    pack_type     : int;                        {int pack_type;}
  End;

  TX509_REQ_INFO = record
    version    : PASN1_INTEGER;                 {ASN1_INTEGER *version;                             }
    subject    : PX509_NAME;                    {X509_NAME *subject;                                }
    pubkey     : PX509_PUBKEY;                  {X509_PUBKEY *pubkey;                               }
    {d=2 hl=2 l=  0 cons: cont: 00 }
    attributes : PSTACK;                        {STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */}
    req_kludge : int;                           {int req_kludge;                                    }
  End;

  TX509_REQ = record
    req_info    : PX509_REQ_INFO;               {X509_REQ_INFO *req_info;}
    sig_alg     : PX509_ALGOR;                  {X509_ALGOR *sig_alg;}
    signature   : PASN1_BIT_STRING;             {ASN1_BIT_STRING *signature;}
    references  : int;                          {int references;}
  End;

  TX509_CINF = record
    {[ 0 ] default of v1}
    version        : PASN1_INTEGER;             {ASN1_INTEGER *version;}
    serialNumber   : PASN1_INTEGER;             {ASN1_INTEGER *serialNumber;}
    signature      : PX509_ALGOR;               {X509_ALGOR *signature;}
    issuer         : PX509_NAME;                {X509_NAME *issuer;}
    validity       : PX509_VAL;                 {X509_VAL *validity;}
    subject        : PX509_NAME;                {X509_NAME *subject;}
    key            : PX509_PUBKEY;              {X509_PUBKEY *key;}
    { [ 1 ] optional in v2 }
    issuerUID      : PASN1_BIT_STRING;          {ASN1_BIT_STRING *issuerUID;}
    { [ 2 ] optional in v2 }
    subjectUID     : PASN1_BIT_STRING;          {ASN1_BIT_STRING *subjectUID;}
    { [ 3 ] optional in v3 }
    extensions     : PSTACK;                    {STACK /* X509_EXTENSION */ *extensions;}
  End;

  TX509 = record
    cert_info      : PX509_CINF;                {X509_CINF *cert_info;}
    sig_alg        : PX509_ALGOR;               {X509_ALGOR *sig_alg;}
    signature      : PASN1_BIT_STRING;          {ASN1_BIT_STRING *signature;}
    valid          : int;                       {int valid;}
    references     : int;                       {int references;}
    name           : Pchar;                     {char *name;}
  end;

  TX509_REVOKED = record
    serialNumber   : PASN1_INTEGER;             {ASN1_INTEGER *serialNumber;}
    revocationDate : PASN1_UTCTIME;             {ASN1_UTCTIME *revocationDate;}
    { optional X509_EXTENSION }
    extensions     : PSTACK;                    {STACK /* optional X509_EXTENSION */ *extensions;}
    { load sequence }
    sequence       : int;                       {int sequence; /* load sequence */}
  end;

  TX509_CRL_INFO = record
    version        : PASN1_INTEGER;             {ASN1_INTEGER *version;                     }
    sig_alg        : PX509_ALGOR;               {X509_ALGOR *sig_alg;                       }
    issuer         : PX509_NAME;                {X509_NAME *issuer;                         }
    lastUpdate     : PASN1_UTCTIME;             {ASN1_UTCTIME *lastUpdate;                  }
    nextUpdate     : PASN1_UTCTIME;             {ASN1_UTCTIME *nextUpdate;                  }
    revoked        : PSTACK;                    {STACK /* X509_REVOKED */ *revoked;         }
    extensions     : PSTACK;                    {STACK /* [0] X509_EXTENSION */ *extensions;}
  end;

  TX509_CRL = record
    { actual signature }
    crl            : PX509_CRL_INFO;            {X509_CRL_INFO *crl;}
    sig_alg        : PX509_ALGOR;               {X509_ALGOR *sig_alg;}
    signature      : PASN1_BIT_STRING;          {ASN1_BIT_STRING *signature;}
    references     : int;                       {int references;}
  End;


  { a sequence of these are used }
  TX509_ATTRIBUTE_value = record
    case byte of                                {union   {}
      0: (ptr   : PChar);                       { char            *ptr;}
      1: (aset  : PSTACK);                      {/* 1 */  STACK /* ASN1_TYPE */ *set;}
      2: (single: PASN1_TYPE);                  {/* 0 */  ASN1_TYPE       *single;}
  end;

  TX509_ATTRIBUTE = record
    aobject       : PASN1_OBJECT;               {ASN1_OBJECT *object;}
    { 1 for a set, 0 for a single item (which is wrong) }
    aset          : int;                        {int set;}
    value         : TX509_ATTRIBUTE_value;
  end;

  TX509_PKEY = record
    version       : int;                        {int version;}
    { The PKCS#8 data types }
    enc_algor     : PX509_ALGOR;                {X509_ALGOR *enc_algor;}
    { encrypted pub key }
    enc_pkey      : PASN1_OCTET_STRING;         {ASN1_OCTET_STRING *enc_pkey;}

    { When decrypted, the following will not be NULL }
    dec_pkey      : PEVP_PKEY;                  {EVP_PKEY *dec_pkey;}

    { used to encrypt and decrypt }
    key_length    : int;                        {int key_length;}
    key_data      : Pchar;                      {char *key_data;}
    { true if we should auto free key_data }
    key_free      : int;                        {int key_free;}

    { expanded version of 'enc_algor' }
    cipher        : TEVP_CIPHER_INFO;           {EVP_CIPHER_INFO cipher;}

    references    : int;                        {int references;}
  end;

  TX509_INFO = record
    x509       : PX509;                         {X509 *x509;}
    crl        : PX509_CRL;                     {X509_CRL *crl;}
    x_pkey     : PX509_PKEY;                    {X509_PKEY *x_pkey;}

    enc_cipher : TEVP_CIPHER_INFO;              {EVP_CIPHER_INFO enc_cipher;}
    enc_len    : int;                           {int enc_len;}
    enc_data   : Pchar;                         {char *enc_data;}

    references : int;                           {int references;}
  end;

{ The next 2 structures and their 8 routines were sent to me by
  Pat Richard <patr@x509.com> and are used to manipulate
  Netscapes spki strucutres - usefull if you are writing a CA web page}

  TNETSCAPE_SPKAC = record
    pubkey     : PX509_PUBKEY;                  {X509_PUBKEY *pubkey;}
    { challenge sent in atlas >= PR2 }
    challenge  : PASN1_IA5STRING;               {ASN1_IA5STRING *challenge;}
  end;

  TNETSCAPE_SPKI = record
    { signed public key and challenge }
    spkac      : PNETSCAPE_SPKAC;               {NETSCAPE_SPKAC *spkac;  /* signed public key and challenge */}
    sig_algor  : PX509_ALGOR;                   {X509_ALGOR *sig_algor;}
    signature  : PASN1_BIT_STRING;              {ASN1_BIT_STRING *signature;}
  end;

  TCBC_PARAM = record
    iv         : Array[0..8-1] of uchar;        {unsigned char iv[8];}
  End;

