#ifndef _FS_LTVVERIFIER_C_H_
#define _FS_LTVVERIFIER_C_H_

#ifdef __cplusplus
extern "C" {
#endif



typedef enum _FSResponseType {
e_FSTypeNone = 0,
e_FSTypeCRL = 1,
e_FSTypeOCSP = 2,
}FSResponseType;


typedef struct _FSResponse {
  FSResponseType type;
  FS_BSTR response_data;
}FSResponse;


typedef enum _FSCertStatus {
e_FSCertStatusValid = 0,
e_FSCertStatusRevoked = 1,
e_FSCertStatusExpired = 2,
e_FSCertStatusCertStatusUnknown = 3,
}FSCertStatus;



typedef enum _FSRevocationReason {
e_FSReasonNoStatus = -1,
e_FSReasonUnspecified = 0,
e_FSReasonKeyCompromise = 1,
e_FSReasonCACompromise = 2,
e_FSReasonAffiliationChanged = 3,
e_FSReasonSuperseded = 4,
e_FSReasonCessationOfOperation = 5,
e_FSReasonCertificateHold = 6,
e_FSReasonRemoveFromCRL = 7,
e_FSReasonPrivilegeWithDrawn = 8,
e_FSReasonAACompromise = 9,
}FSRevocationReason;



typedef enum _FSResponseInfoLocation {
e_FSLocationNotSet = 0,
e_FSLocationDSS = 1,
e_FSLocationSignature = 2,
e_FSLocationOnline = 3,
}FSResponseInfoLocation;


typedef struct _FSTimeRange {
  FSDateTime start_time;
  FSDateTime end_time;
}FSTimeRange;

typedef struct _FSCertVerifyResult {
  FS_BSTR cert;
  FS_BOOL is_ca;
  FS_BOOL is_trusted;
  FSResponse response;
  FSTimeRange response_effect_time_range;
  FSDateTime revoke_time;
  FSCertStatus cert_status;
  FSRevocationReason reason;
  FSDateTime cert_check_time;
  FS_BOOL exist_signature_vri_creation_time;
  FSDateTime signature_vri_creation_time;
  FS_BOOL exist_response_signature_vri_creation_time;
  FSDateTime response_signature_vri_creation_time;
  FSResponseInfoLocation response_info_location;
}FSCertVerifyResult;

typedef struct _FSCertIssuerPair {
  FS_BSTR cert;
  FS_BSTR issuer;
}FSCertIssuerPair;

typedef struct _FSRevocationArrayInfo {
  FS_BSTR* ocsp_array;
  FS_UINT32 ocsp_array_length;
  FS_BSTR* crl_array;
  FS_UINT32 crl_array_length;
}FSRevocationArrayInfo;

typedef struct _FSRevocationCallback {
  void* user_data;
  void (*Release)(void* user_data);
  void (*GetCertChainFromSignature)(void* user_data, const char*signature_content, FS_BSTR* return_stringarray, FS_UINT32* return_stringarray_length);
  FSResponse (*GetResponseOnLineForSingleCert)(void* user_data, const FSCertIssuerPair cert_issuer_pair);
  FSCertVerifyResult (*VerifyOCSP)(void* user_data, const FSCertIssuerPair cert_issuer_pair, const char*ocsp_data);
  FSCertVerifyResult (*VerifyCRL)(void* user_data, const FSCertIssuerPair cert_issuer_pair, const char*crl_data);
  FS_BOOL (*IsCA)(void* user_data, const char*cert);
  FSDateTime (*GetDTSTime)(void* user_data, const char*signature_content);
  FS_BSTR (*GetTSTSignature)(void* user_data, const char*signature_content);
  FSDateTime (*GetTSTTime)(void* user_data, const char*signature_content);
  FSCertIssuerPair (*GetOCSPCertAndIssuer)(void* user_data, const char*ocsp_data, char** trust_cert_chain_array, FS_UINT32 array_length_trust_cert_chain);
  FSDateTime (*GetOCSPProducedAtTime)(void* user_data, const char*ocsp_data);
  FS_BOOL (*IsOCSPNeedCheck)(void* user_data, const char*ocsp_data);
  FSTimeRange (*GetCertValidTimeRange)(void* user_data, const char*cert);
  FS_BSTR (*GetOCSPSignature)(void* user_data, const char*ocsp_data);
  FS_BSTR (*GetCRLSignature)(void* user_data, const char*crl_data);
  FSRevocationArrayInfo (*GetRevocationInfoFromSignatureData)(void* user_data, const char*signature_content);
  FS_BOOL (*IsIssuerMatchCert)(void* user_data, const FSCertIssuerPair cert_issuer_pair);
}FSRevocationCallback;


typedef enum _FSTimeType {
e_FSSignatureCreationTime = 0,
e_FSSignatureTSTTime = 1,
e_FSCurrentTime = 2,
e_FSVRICreationTime = 3,
}FSTimeType;



typedef enum _FSVerifyMode {
e_FSVerifyModeAcrobat = 1,
}FSVerifyMode;


typedef struct _FSTrustedCertStoreCallback {
  void* user_data;
  FS_BOOL (*IsCertTrusted)(void* user_data, const char*cert);
  FS_BOOL (*IsCertTrustedRoot)(void* user_data, const char*cert);
}FSTrustedCertStoreCallback;

typedef struct _FSCertChainResolverCallback {
  void* user_data;
  void (*GetCertificates)(void* user_data, FS_BSTR* return_stringarray, FS_UINT32* return_stringarray_length);
}FSCertChainResolverCallback;


typedef enum _FSLTVState {
e_FSLTVStateInactive = 0,
e_FSLTVStateEnable = 1,
e_FSLTVStateNotEnable = 2,
}FSLTVState;


FSErrorCode FSDK_LTVVerifier_Create(const FS_PDFDOC_HANDLE document, FS_BOOL is_verify_signature, FS_BOOL use_expired_tst,
                       FS_BOOL ignore_doc_info, FSTimeType time_type, FS_LTVVERIFIER_HANDLE* ltvverifier_return_value);
FSErrorCode FSDK_LTVVerifier_Release(FS_LTVVERIFIER_HANDLE ltvverifier_handle);
FSErrorCode FSDK_LTVVerifier_IsEmpty(FS_LTVVERIFIER_HANDLE ltvverifier_handle, FS_BOOL* return_value);
FSErrorCode FSDK_LTVVerifier_SetRevocationCallback(FS_LTVVERIFIER_HANDLE ltvverifier_handle, FSRevocationCallback* callback);
FSErrorCode FSDK_LTVVerifier_SetVerifyMode(FS_LTVVERIFIER_HANDLE ltvverifier_handle, FSVerifyMode mode);
FSErrorCode FSDK_LTVVerifier_SetTrustedCertStoreCallback(FS_LTVVERIFIER_HANDLE ltvverifier_handle, FSTrustedCertStoreCallback* callback);
FSErrorCode FSDK_LTVVerifier_Verify(FS_LTVVERIFIER_HANDLE ltvverifier_handle, FS_SIGNATUREVERIFYRESULT_HANDLE* return_signagture_verify_result_array, FS_UINT32* return_array_length);
FSErrorCode FSDK_LTVVerifier_VerifySignature(FS_LTVVERIFIER_HANDLE ltvverifier_handle, const FS_SIGNATURE_HANDLE signature, FS_SIGNATUREVERIFYRESULT_HANDLE* return_signagture_verify_result_array, FS_UINT32* return_array_length);
FSErrorCode FSDK_LTVVerifier_AddDSS(FS_LTVVERIFIER_HANDLE ltvverifier_handle, const FS_SIGNATUREVERIFYRESULT_HANDLE signature_verify_result);
FSErrorCode FSDK_LTVVerifier_SetCertChainResolverCallback(FS_LTVVERIFIER_HANDLE ltvverifier_handle, FSCertChainResolverCallback* callback);
FSErrorCode FSDK_SignatureVerifyResult_IsEmpty(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FS_BOOL* return_value);
FSErrorCode FSDK_SignatureVerifyResult_Release(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle);
FSErrorCode FSDK_SignatureVerifyResult_GetSignatureName(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FS_BSTR* return_value);
FSErrorCode FSDK_SignatureVerifyResult_GetSignatureHashValue(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FS_BSTR* return_value);
FSErrorCode FSDK_SignatureVerifyResult_GetSignatureState(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FS_UINT32* return_value);
FSErrorCode FSDK_SignatureVerifyResult_GetSignatureCheckTime(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FSDateTime* return_value);
FSErrorCode FSDK_SignatureVerifyResult_GetSignatureCheckTimeType(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FSTimeType* return_value);
FSErrorCode FSDK_SignatureVerifyResult_GetLTVState(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FSLTVState* return_value);
FSErrorCode FSDK_SignatureVerifyResult_GetCertificateVerifyResults(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FSCertVerifyResult* return_cert_verify_result_array, FS_UINT32* return_array_length);
FSErrorCode FSDK_SignatureVerifyResult_GetOCSPSigantureVerifyResults(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FS_SIGNATUREVERIFYRESULT_HANDLE* return_signagture_verify_result_array, FS_UINT32* return_array_length);
FSErrorCode FSDK_SignatureVerifyResult_GetTSTSignatureVerifyResult(FS_SIGNATUREVERIFYRESULT_HANDLE signatureverifyresult_handle, FS_SIGNATUREVERIFYRESULT_HANDLE* return_value);
#ifdef __cplusplus
}
#endif
#endif
