/* Generated from /usr/src/crypto/dist/heimdal/lib/hx509/crmf.asn1 */
/* Do not edit */

#ifndef __crmf_asn1_h__
#define __crmf_asn1_h__

#include <stddef.h>
#include <time.h>

#ifndef __asn1_common_definitions__
#define __asn1_common_definitions__

typedef struct heim_integer {
  size_t length;
  void *data;
  int negative;
} heim_integer;

typedef struct heim_octet_string {
  size_t length;
  void *data;
} heim_octet_string;

typedef char *heim_general_string;

typedef char *heim_utf8_string;

typedef char *heim_printable_string;

typedef char *heim_ia5_string;

typedef struct heim_bmp_string {
  size_t length;
  uint16_t *data;
} heim_bmp_string;

typedef struct heim_universal_string {
  size_t length;
  uint32_t *data;
} heim_universal_string;

typedef char *heim_visible_string;

typedef struct heim_oid {
  size_t length;
  unsigned *components;
} heim_oid;

typedef struct heim_bit_string {
  size_t length;
  void *data;
} heim_bit_string;

typedef struct heim_octet_string heim_any;
typedef struct heim_octet_string heim_any_set;

#define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R)                  \
  do {                                                         \
    (BL) = length_##T((S));                                    \
    (B) = malloc((BL));                                        \
    if((B) == NULL) {                                          \
      (R) = ENOMEM;                                            \
    } else {                                                   \
      (R) = encode_##T(((unsigned char*)(B)) + (BL) - 1, (BL), \
                       (S), (L));                              \
      if((R) != 0) {                                           \
        free((B));                                             \
        (B) = NULL;                                            \
      }                                                        \
    }                                                          \
  } while (0)

struct units;

#endif

#include <rfc2459_asn1.h>
#include <heim_asn1.h>
/*
CRMFRDNSequence ::= SEQUENCE OF RelativeDistinguishedName
*/

typedef struct CRMFRDNSequence {
  unsigned int len;
  RelativeDistinguishedName *val;
} CRMFRDNSequence;

int    encode_CRMFRDNSequence(unsigned char *, size_t, const CRMFRDNSequence *, size_t *);
int    decode_CRMFRDNSequence(const unsigned char *, size_t, CRMFRDNSequence *, size_t *);
void   free_CRMFRDNSequence  (CRMFRDNSequence *);
size_t length_CRMFRDNSequence(const CRMFRDNSequence *);
int    copy_CRMFRDNSequence  (const CRMFRDNSequence *, CRMFRDNSequence *);


/*
Controls ::= SEQUENCE OF AttributeTypeAndValue
*/

typedef struct Controls {
  unsigned int len;
  AttributeTypeAndValue *val;
} Controls;

int    encode_Controls(unsigned char *, size_t, const Controls *, size_t *);
int    decode_Controls(const unsigned char *, size_t, Controls *, size_t *);
void   free_Controls  (Controls *);
size_t length_Controls(const Controls *);
int    copy_Controls  (const Controls *, Controls *);


/*
POPOSigningKey ::= SEQUENCE {
  poposkInput           [0] IMPLICIT POPOSigningKeyInput OPTIONAL,
  algorithmIdentifier   AlgorithmIdentifier,
  signature               BIT STRING {
  },
}
*/

typedef struct POPOSigningKey {
  POPOSigningKeyInput *poposkInput;
  AlgorithmIdentifier algorithmIdentifier;
  heim_bit_string signature;
} POPOSigningKey;

int    encode_POPOSigningKey(unsigned char *, size_t, const POPOSigningKey *, size_t *);
int    decode_POPOSigningKey(const unsigned char *, size_t, POPOSigningKey *, size_t *);
void   free_POPOSigningKey  (POPOSigningKey *);
size_t length_POPOSigningKey(const POPOSigningKey *);
int    copy_POPOSigningKey  (const POPOSigningKey *, POPOSigningKey *);


/*
PKMACValue ::= SEQUENCE {
  algId           AlgorithmIdentifier,
  value             BIT STRING {
  },
}
*/

typedef struct PKMACValue {
  AlgorithmIdentifier algId;
  heim_bit_string value;
} PKMACValue;

int    encode_PKMACValue(unsigned char *, size_t, const PKMACValue *, size_t *);
int    decode_PKMACValue(const unsigned char *, size_t, PKMACValue *, size_t *);
void   free_PKMACValue  (PKMACValue *);
size_t length_PKMACValue(const PKMACValue *);
int    copy_PKMACValue  (const PKMACValue *, PKMACValue *);


/*
POPOSigningKeyInput ::= SEQUENCE {
  authInfo        CHOICE {
    sender          [0] IMPLICIT GeneralName,
    publicKeyMAC    PKMACValue,
  },
  publicKey       SubjectPublicKeyInfo,
}
*/

typedef struct POPOSigningKeyInput {
  struct  {
    enum {
      choice_POPOSigningKeyInput_authInfo_sender = 1,
      choice_POPOSigningKeyInput_authInfo_publicKeyMAC
    } element;
    union {
      GeneralName sender;
      PKMACValue publicKeyMAC;
    } u;
  } authInfo;
  SubjectPublicKeyInfo publicKey;
} POPOSigningKeyInput;

int    encode_POPOSigningKeyInput(unsigned char *, size_t, const POPOSigningKeyInput *, size_t *);
int    decode_POPOSigningKeyInput(const unsigned char *, size_t, POPOSigningKeyInput *, size_t *);
void   free_POPOSigningKeyInput  (POPOSigningKeyInput *);
size_t length_POPOSigningKeyInput(const POPOSigningKeyInput *);
int    copy_POPOSigningKeyInput  (const POPOSigningKeyInput *, POPOSigningKeyInput *);


/*
PBMParameter ::= SEQUENCE {
  salt             OCTET STRING,
  owf              AlgorithmIdentifier,
  iterationCount   INTEGER,
  mac              AlgorithmIdentifier,
}
*/

typedef struct PBMParameter {
  heim_octet_string salt;
  AlgorithmIdentifier owf;
  heim_integer iterationCount;
  AlgorithmIdentifier mac;
} PBMParameter;

int    encode_PBMParameter(unsigned char *, size_t, const PBMParameter *, size_t *);
int    decode_PBMParameter(const unsigned char *, size_t, PBMParameter *, size_t *);
void   free_PBMParameter  (PBMParameter *);
size_t length_PBMParameter(const PBMParameter *);
int    copy_PBMParameter  (const PBMParameter *, PBMParameter *);


/*
SubsequentMessage ::= INTEGER {
  encrCert(0),
  challengeResp(1)
}
*/

typedef enum SubsequentMessage {
  encrCert = 0,
  challengeResp = 1
} SubsequentMessage;

int    encode_SubsequentMessage(unsigned char *, size_t, const SubsequentMessage *, size_t *);
int    decode_SubsequentMessage(const unsigned char *, size_t, SubsequentMessage *, size_t *);
void   free_SubsequentMessage  (SubsequentMessage *);
size_t length_SubsequentMessage(const SubsequentMessage *);
int    copy_SubsequentMessage  (const SubsequentMessage *, SubsequentMessage *);


/*
POPOPrivKey ::= CHOICE {
  thisMessage         [0]   BIT STRING {
  },
  subsequentMessage   [1] IMPLICIT SubsequentMessage,
  dhMAC               [2]   BIT STRING {
  },
  agreeMAC            [3] IMPLICIT PKMACValue,
  encryptedKey        [4] heim_any,
}
*/

typedef struct POPOPrivKey {
  enum {
    choice_POPOPrivKey_thisMessage = 1,
    choice_POPOPrivKey_subsequentMessage,
    choice_POPOPrivKey_dhMAC,
    choice_POPOPrivKey_agreeMAC,
    choice_POPOPrivKey_encryptedKey
  } element;
  union {
    heim_bit_string thisMessage;
    SubsequentMessage subsequentMessage;
    heim_bit_string dhMAC;
    PKMACValue agreeMAC;
    heim_any encryptedKey;
  } u;
} POPOPrivKey;

int    encode_POPOPrivKey(unsigned char *, size_t, const POPOPrivKey *, size_t *);
int    decode_POPOPrivKey(const unsigned char *, size_t, POPOPrivKey *, size_t *);
void   free_POPOPrivKey  (POPOPrivKey *);
size_t length_POPOPrivKey(const POPOPrivKey *);
int    copy_POPOPrivKey  (const POPOPrivKey *, POPOPrivKey *);


/*
ProofOfPossession ::= CHOICE {
  raVerified        [0]   NULL,
  signature         [1] POPOSigningKey,
  keyEncipherment   [2] POPOPrivKey,
  keyAgreement      [3] POPOPrivKey,
}
*/

typedef struct ProofOfPossession {
  enum {
    choice_ProofOfPossession_raVerified = 1,
    choice_ProofOfPossession_signature,
    choice_ProofOfPossession_keyEncipherment,
    choice_ProofOfPossession_keyAgreement
  } element;
  union {
    int raVerified;
    POPOSigningKey signature;
    POPOPrivKey keyEncipherment;
    POPOPrivKey keyAgreement;
  } u;
} ProofOfPossession;

int    encode_ProofOfPossession(unsigned char *, size_t, const ProofOfPossession *, size_t *);
int    decode_ProofOfPossession(const unsigned char *, size_t, ProofOfPossession *, size_t *);
void   free_ProofOfPossession  (ProofOfPossession *);
size_t length_ProofOfPossession(const ProofOfPossession *);
int    copy_ProofOfPossession  (const ProofOfPossession *, ProofOfPossession *);


/*
CertTemplate ::= SEQUENCE {
  version         [0] INTEGER OPTIONAL,
  serialNumber    [1] INTEGER OPTIONAL,
  signingAlg      [2] SEQUENCE {
    algorithm           OBJECT IDENTIFIER,
    parameters      heim_any OPTIONAL,
  } OPTIONAL,
  issuer          [3] IMPLICIT CHOICE {
    rdnSequence     CRMFRDNSequence,
  } OPTIONAL,
  validity        [4] SEQUENCE {
    notBefore       [0] Time OPTIONAL,
    notAfter        [1] Time OPTIONAL,
  } OPTIONAL,
  subject         [5] IMPLICIT CHOICE {
    rdnSequence     CRMFRDNSequence,
  } OPTIONAL,
  publicKey       [6] IMPLICIT SEQUENCE {
    algorithm          AlgorithmIdentifier,
    subjectPublicKey       BIT STRING {
    } OPTIONAL,
  } OPTIONAL,
  issuerUID       [7] IMPLICIT   BIT STRING {
  } OPTIONAL,
  subjectUID      [8] IMPLICIT   BIT STRING {
  } OPTIONAL,
  extensions      [9] IMPLICIT SEQUENCE OF Extension OPTIONAL,
}
*/

typedef struct CertTemplate {
  heim_integer *version;
  heim_integer *serialNumber;
  struct  {
    heim_oid algorithm;
    heim_any *parameters;
  } *signingAlg;
  struct  {
    enum {
      choice_CertTemplate_issuer_rdnSequence = 1
    } element;
    union {
      CRMFRDNSequence rdnSequence;
    } u;
  } *issuer;
  struct  {
    Time *notBefore;
    Time *notAfter;
  } *validity;
  struct  {
    enum {
      choice_CertTemplate_subject_rdnSequence = 1
    } element;
    union {
      CRMFRDNSequence rdnSequence;
    } u;
  } *subject;
  struct  {
    AlgorithmIdentifier algorithm;
    heim_bit_string *subjectPublicKey;
  } *publicKey;
  heim_bit_string *issuerUID;
  heim_bit_string *subjectUID;
  struct  {
    unsigned int len;
    Extension *val;
  } *extensions;
} CertTemplate;

int    encode_CertTemplate(unsigned char *, size_t, const CertTemplate *, size_t *);
int    decode_CertTemplate(const unsigned char *, size_t, CertTemplate *, size_t *);
void   free_CertTemplate  (CertTemplate *);
size_t length_CertTemplate(const CertTemplate *);
int    copy_CertTemplate  (const CertTemplate *, CertTemplate *);


/*
CertRequest ::= SEQUENCE {
  certReqId       INTEGER,
  certTemplate    CertTemplate,
  controls        Controls OPTIONAL,
}
*/

typedef struct CertRequest {
  heim_integer certReqId;
  CertTemplate certTemplate;
  Controls *controls;
} CertRequest;

int    encode_CertRequest(unsigned char *, size_t, const CertRequest *, size_t *);
int    decode_CertRequest(const unsigned char *, size_t, CertRequest *, size_t *);
void   free_CertRequest  (CertRequest *);
size_t length_CertRequest(const CertRequest *);
int    copy_CertRequest  (const CertRequest *, CertRequest *);


/*
CertReqMsg ::= SEQUENCE {
  certReq         CertRequest,
  popo            ProofOfPossession OPTIONAL,
  regInfo         SEQUENCE OF AttributeTypeAndValue OPTIONAL,
}
*/

typedef struct CertReqMsg {
  CertRequest certReq;
  ProofOfPossession *popo;
  struct  {
    unsigned int len;
    AttributeTypeAndValue *val;
  } *regInfo;
} CertReqMsg;

int    encode_CertReqMsg(unsigned char *, size_t, const CertReqMsg *, size_t *);
int    decode_CertReqMsg(const unsigned char *, size_t, CertReqMsg *, size_t *);
void   free_CertReqMsg  (CertReqMsg *);
size_t length_CertReqMsg(const CertReqMsg *);
int    copy_CertReqMsg  (const CertReqMsg *, CertReqMsg *);


/*
CertReqMessages ::= SEQUENCE OF CertReqMsg
*/

typedef struct CertReqMessages {
  unsigned int len;
  CertReqMsg *val;
} CertReqMessages;

int    encode_CertReqMessages(unsigned char *, size_t, const CertReqMessages *, size_t *);
int    decode_CertReqMessages(const unsigned char *, size_t, CertReqMessages *, size_t *);
void   free_CertReqMessages  (CertReqMessages *);
size_t length_CertReqMessages(const CertReqMessages *);
int    copy_CertReqMessages  (const CertReqMessages *, CertReqMessages *);


#endif /* __crmf_asn1_h__ */
