/*

The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.

The Original Code is a portion of the Path Development API developed
by CygnaCom Solutions, Inc.

Portions created by CygnaCom Solutions, Inc. are Copyright (C) CygnaCom 
Solutions, Inc. All Rights Reserved.

Contributor(s): ______________________________________.

http://www.cygnacom.com

*/
/*------------------------------------------------------------------------*\
|  Project Name  :   Path Development API
|  File Name     :   CertsRec.h
|  Creation Date :   May 17, 1999
|  Author        :   Matt Cooper (mcooper@cygnacom.com)
|  Last Mode Date:   May 17, 1999
|  Modification History:
|--------------------------------------------------------------------------
|
|     Known Bugs:   None
|                   
|--------------------------------------------------------------------------
| Cryptographic devices and technical data regarding them are subject to
| Federal Government export controls as specified in Title 22, Code of
| Federal Regulations, Parts 121 through 128.  Cryptographic devices
| implementing the Data Encryption Standard (DES) and technical data
| regarding them must comply with these Federal regulations
|--------------------------------------------------------------------------
| Copyright (c) 1999, CygnaCom Solutions, Inc.
| All Rights Reserved.
\*------------------------------------------------------------------------*/

// CertsRec.h: interface for the CCertsRec class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CERTSREC_H__E685FC27_E844_11D2_B1AB_00207814A98B__INCLUDED_)
#define AFX_CERTSREC_H__E685FC27_E844_11D2_B1AB_00207814A98B__INCLUDED_

#include "Defines.h"

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef ULONG
#define ULONG unsigned long
#endif


#define CCERTSREC_ERR_BASE					11000
#define CCERTSREC_REQUIRED_PARAM_MISSING	CCERTSREC_ERR_BASE + 1
#define CCERTSREC_SERIAL_NUMBER_MISSING		CCERTSREC_ERR_BASE + 2 
#define CCERTSREC_ALLOC_FAIL				CCERTSREC_ERR_BASE + 3
#define CCERTSREC_INVALID_CERT				CCERTSREC_ERR_BASE + 4
#define CCERTSREC_INCORRECT_CERT			CCERTSREC_ERR_BASE + 5
#define CCERTSREC_CERT1_INVALID				CCERTSREC_ERR_BASE + 6
#define CCERTSREC_CERT2_INVALID				CCERTSREC_ERR_BASE + 7
#define CCERTSREC_ADDRESS_INVALID			CCERTSREC_ERR_BASE + 8
#define CCERTSREC_FUNC_INVALID_ON_THIS		CCERTSREC_ERR_BASE + 9
#define CCERTSREC_DUPLICATE_CERT			CCERTSREC_ERR_BASE + 10



class CCertsRec  
{
	friend class CCertCache;
public:
	void ClearCheckedFlags( ULONG sessionMask );
	void SetServerSearched();
	void SetRAMSearched();
	void SetClientSearched();
	void SetDSASearched();

	int IsServerSearched();
	int IsClientSearched();
	int IsRAMSearched();
	int IsDSASearched();
	int m_modified;
	long set_entry( char *subjectDN );
	long SortCerts( char* trustedRootDN, char** acceptablePolicySet );
	long AddCert( Bytes_struct* pBinCert, long type );
	CCertsRec *NextRec;

	CCertsRec();
	virtual ~CCertsRec();

	long set_entry(LPCERTCACHE_ENTRY_STRUCT lpCertListHead, unsigned long flag );


	char *get_key() const {return m_lpszKey;}

	// equality of keys
	bool operator==(const CCertsRec&) const;
//	bool operator==(const CPathRec *other);

	// extracting && setting flag
	unsigned long get_flag() const { return m_flag; }
	void set_flag(unsigned long flag) { m_flag |= flag; }
	void unset_flag(unsigned long flag)
	{
		unsigned long setflag;
		memset(&setflag,0xFF,sizeof(unsigned long));
		setflag ^= flag;
		m_flag &= setflag;
	}
	int is_flag_set( unsigned long bit ) const
	{
		if( bit == (bit & m_flag) )
			return 1;
		return 0;
	}

	void CopyFrom( CCertsRec *rec );

	LPCERTCACHE_ENTRY_STRUCT m_lpCerts;

private:
	// information associated with a symbol
	unsigned long m_flag;
	char *m_lpszKey;

protected:
	LPCERTCACHE_ENTRY_STRUCT GetNextUncheckedCert(ULONG sessionMask, LPCPL_SESSION_INFO sessInfo);
	ULONG m_searched;
	long AddCert(Cert_struct *pCert, Bytes_struct *pBinCert, long type);
	long CopyEntryStruct( LPCERTCACHE_ENTRY_STRUCT input, LPCERTCACHE_ENTRY_STRUCT* copy );
	void FreeCertList(LPCERTCACHE_ENTRY_STRUCT *pListHead);
	long m_entryNumber;
	void FreeEntry();
};

#endif // !defined(AFX_CERTSREC_H__E685FC27_E844_11D2_B1AB_00207814A98B__INCLUDED_)
