/*
In cele ce urmeaza vom considera spre exemplificare imlpementarea OID-urilor (Object IDentifer) urmarind structura fizica si cea logica a acestei implementari. Pentru inceput descierea clasei CManager , punctul de pornire in structura logica, arata dupa cum urmeaza:
*/
class SSE_CLASS CManager { public: // Delegates the retrieval of an LDAPClient factory object to the implementation class // pointed to by the Singleton static CLDAPClientFactoryABC& LDAPClientFactory(void); (return object) (function) // Delegates the retrieval of an OCSPClient factory object to the implementation class // pointed to by the Singleton static COCSPClientFactoryABC& OCSPClientFactory(void);
// Delegates the retrieval of a stream factory object to the implementation class // pointed to by the Singleton static CStreamFactoryABC& StreamFactory(void);
// Delegates the retrieval of a utilities factory object to the implementation class // pointed to by the Singleton static CUtilitiesFactoryABC& UtilitiesFactory(void);
// Delegates the retrieval of a AuditLogController object to the implementation class // pointed to by the Singleton static CAuditLogControllerABC& AuditLogController(void); // Delegates the retrieval of a CryptoHandler object to the implementation class // pointed to by the Singleton static CCryptoHandlerABC& CryptoHandler(void);
// Delegates the retrieval of a OSAccessor object to the implementation class // pointed to by the Singleton static COSAccessABC& OS(void);
// Delegates the retrieval of a CMF object to the implementation class // pointed to by the Singleton static CCertificateManagementFrameworkABC& CMF(void);
// Delegates the retrieval of a CMSEngineFactory object to the implementation class // pointed to by the Singleton static CCMSEngineFactoryABC& CMSEngineFactory(void);
// Delegates the retrieval of a ASN1Factory object to the implementation class // pointed to by the Singleton static CASN1FactoryABC& ASN1Factory(void);
// Delegates the retrieval of a TransportFactory object to the implementation class // pointed to by the Singleton static CTransportFactoryABC& TransportFactory(void);
// Delegates the retrieval of an XMLFactory object to the implementation class // pointed to by the Singleton static CXMLFactoryABC& XMLFactory(void);
// Delegates the retrieval of a CCommonGUIFacadeABC object to the implementation // class pointed to by the Singleton static CCommonGUIFacadeABC& CommonGUI(void);
// Delegates the retrieval of an Application object to the implementation class // pointed to by the Singleton static CCApplication& Application(void);
// Returns the configuration object for an application. Subclasses will // override the GetConfigurationP method and return a configuration // object of their choice. The subclass can choose to return any subclass // of CConfigurationHandlerABC static CConfigurationHandlerABC& GetConfigurationHandler(void);
// Delegates the retrieval of a PGPLibFactory object to the implementation class // pointed to by the Singleton static CPGPLibFactoryABC& PGPLibFactory(void);
// Delegates the retrieval of a DatabaseFactory object // to the implementation class pointed to by the Singleton static CDatabaseFactoryABC& DatabaseFactory(void);
// Delegates the retrieval of the full qualified name of the module creating // the manager class to the implementation class pointed to by the Singleton. static const CCString& GetModuleFilename(void);
// This following static methods is used in external binaries static void SetSingleton(CManager* ppoSingleton); static void ResetSingleton(void);
// Returns the singleton instance static CManager& GetSingleton(void);
// Subclasses must override this and provide for object destruction virtual void Delete(void) = 0;
protected: // Default constructor CManager(void);
// Virtual destructor virtual ~CManager(void);
// Protected implementations used by static methods virtual CLDAPClientFactoryABC& LDAPClientFactoryP(void) = 0; virtual CPGPLibFactoryABC& PGPLibFactoryP(void) = 0; virtual COCSPClientFactoryABC& OCSPClientFactoryP(void) = 0; virtual CStreamFactoryABC& SSE_METHOD StreamFactoryP(void) = 0; virtual CUtilitiesFactoryABC& SSE_METHOD UtilitiesFactoryP(void) = 0; virtual CAuditLogControllerABC& SSE_METHOD AuditLogControllerP(void) = 0; virtual CCryptoHandlerABC& SSE_METHOD CryptoHandlerP(void) = 0; virtual COSAccessABC& SSE_METHOD OSAccessP(void) = 0; virtual CCertificateManagementFrameworkABC& SSE_METHOD CMFP(void) = 0; virtual CCMSEngineFactoryABC& SSE_METHOD CMSEngineFactoryP(void) = 0; virtual CASN1FactoryABC& SSE_METHOD ASN1FactoryP(void) = 0; virtual CTransportFactoryABC& SSE_METHOD TransportFactoryP(void) = 0; virtual CXMLFactoryABC& SSE_METHOD XMLFactoryP(void) = 0; virtual CCommonGUIFacadeABC& SSE_METHOD CommonGUIP(void) = 0; virtual CDatabaseFactoryABC& SSE_METHOD DatabaseFactoryP(void) = 0;
virtual CCApplication& SSE_METHOD ApplicationP(void) = 0; virtual const CCString& SSE_METHOD GetModuleFilenameP(void) const = 0; virtual CConfigurationHandlerABC& SSE_METHOD GetConfigurationHandlerP(void) = 0;
private: // Singleton member variable static CManager* mpoSingleton;
// The following constructors and operators are private with no implementation // to prevent their usage CManager(const CManager&); bool operator==(const CManager&) const; CManager& operator=(const CManager&);
};
/* Ce ne intereseaza din aceasta declaratie este sectiunea de declaratii publice ce incepe cu "public: ". Toti membrii si toate metodele din aceasta sectiune vor trebui inclusi in structura logica. Pentru a ajunge la implementarea OID-urilor avem nevoie sa folosim urmatorul "factory" din CManager: */ static CUtilitiesFactoryABC& UtilitiesFactory(void);
//Observand tipul returnat de aceasta metoda , ne uitam la declaratia clasei UtilitiesFactoryABC :
class SSE_CLASS CUtilitiesFactoryABC { public:
virtual CVerifyCodeSignatureABC* SSE_METHOD CreateVerifyCodeSignature( ) = 0;
// Creates a time bombing object for evaluation period handling. // poKey should be an application specific random byte stream and // it is XOR-ed with the stream content. If the size of poKey is less than // the stream content the key is used again. virtual CTimeBombingABC* SSE_METHOD CreateTimeBombing(const CStream& poFile, const CStream& poKey) = 0;
// Creates a simple collection class virtual CObjectCollectionABC* SSE_METHOD CreateSimpleCollection(void) = 0;
// Creates a simple String class (ppcData can be NULL) virtual CCStringABC* SSE_METHOD CreateString(const char* ppcData) = 0;
// Creates a String encoder. psInput is encoded as specified by peInputEnc. // peOutputEnc is the encoding of the result string. // This can be called only for Latin-1 or UTF-8 input encodings. virtual CStringEncoderABC* SSE_METHOD CreateStringEncoder( const char *psInput, CStringEncoderABC::EEncoding peInputEnc, CStringEncoderABC::EEncoding peOutputEnc) = 0;
// Creates a String encoder. psInput is encoded as specified by peInputEnc. // peOutputEnc is the encoding of the result string. // This can be called only for Latin-1 or UTF-8 input encodings. virtual CStringEncoderABC* SSE_METHOD CreateStringEncoder( const CCString& psInput, CStringEncoderABC::EEncoding peInputEnc, CStringEncoderABC::EEncoding peOutputEnc) = 0;
// Creates a String encoder. poInput is encoded as specified by peInputEnc. // peOutputEnc is the encoding of the result string. // This can be called for all known input encodings. virtual CStringEncoderABC* SSE_METHOD CreateStringEncoder( const CStream& poInput, CStringEncoderABC::EEncoding peInputEnc, CStringEncoderABC::EEncoding peOutputEnc) = 0;
// Creates an uninitialized OID object. virtual CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifier() = 0;
// Creates an object identifier object for the specified OID virtual CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifierFromString(const CCString& psOID) = 0;
// Creates an object identifier object for the specified DER encoded bytes virtual CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifierFromDER(const CStream& poDEROID) = 0;
// Creates an object identifier object for the specified unique ID virtual CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifierFromUniqueID(const unsigned int piUniqueID) = 0;
// Creates date time objects virtual CCDateTimeABC* SSE_METHOD CreateCurrentDateTime( CCDateTimeABC::ETimeZone peTZ = CCDateTimeABC::TZ_LOCAL) = 0; virtual CCDateTimeABC* SSE_METHOD CreateDateTime(const unsigned int piYear, const unsigned int piMonth, const unsigned int piDay, const unsigned int piHour, const unsigned int piMinute, const unsigned int piSecond, const unsigned int piMillisecond, CCDateTimeABC::ETimeZone peTZ = CCDateTimeABC::TZ_LOCAL) = 0; virtual CCDateTimeABC* SSE_METHOD CreateDateTime(const CCString& piDateStr, const char piToken, CCDateTimeABC::ETimeZone peTZ = CCDateTimeABC::TZ_LOCAL) = 0;
// Create a big number from an integer value virtual CBigNumberABC* SSE_METHOD CreateBigNumberFromInteger(const int piValue) = 0;
// Create a big number from a atream virtual CBigNumberABC* SSE_METHOD CreateBigNumberFromStream(const CStream& poValue) = 0;
// Create a big number from a string virtual CBigNumberABC* SSE_METHOD CreateBigNumberFromString(const CCString& psValue, int piBase = 10) = 0;
// Returns a reference to the transform engine virtual CTransformEngineABC& SSE_METHOD GetTransformEngine(void) = 0;
virtual CSystemMonitorABC* SSE_METHOD CreateSystemMonitor(void)= 0;
// Performs object destruction virtual void SSE_METHOD Delete(void) = 0;
protected: // Default constructor CUtilitiesFactoryABC(void) {}
// Virtual destructor virtual ~CUtilitiesFactoryABC(void) {}
private:
/** @link dependency * @label Creates*/ /*# CTimeBombingABC lnkCTimeBombingABC; */ // The following constructors and operators are private with no implementation // to prevent their usage CUtilitiesFactoryABC(const CUtilitiesFactoryABC&); bool operator==(const CUtilitiesFactoryABC&) const; CUtilitiesFactoryABC& operator=(const CUtilitiesFactoryABC&); };
/* Din nou partea care ne intereseaza este sectiunea public ace ne ofera accesul la diferite interfete. UtilitiesFactoryABC fiind o interfata (o clasa abstracta) ne uitam la implementarea sa CUtilitiesFactory: */ class SSE_CLASS CUtilitiesFactory : public CUtilitiesFactoryABC { public: /*! Default constructor */ CUtilitiesFactory(void);
private: /*! Destructor */ ~CUtilitiesFactory(void);
/*! creates a verÃfy codesignature object
@return object of CVerifyCodeSignature */ CVerifyCodeSignatureABC* SSE_METHOD CreateVerifyCodeSignature( );
/*! Creates a time bombing object for evaluation period handling. poKey should be an application specific random byte stream and it is XOR-ed with the stream content. If the size of poKey is less than the stream content the key is used again.
@param poFile as CStream @param poKey as CStream
@return pointer to a CTimeBombing object */ CTimeBombingABC* SSE_METHOD CreateTimeBombing(const CStream& poFile, const CStream& poKey);
/*! Creates a simple collection class
@return a pointer to CObjectCollection */ CObjectCollectionABC* SSE_METHOD CreateSimpleCollection(void); /*! Creates a simple String class (ppcData can be NULL)
@param ppcData as char*
@return a CCString object */ CCStringABC* SSE_METHOD CreateString(const char* ppcData);
/*! Creates a String encoder. psInput is encoded as specified by peInputEnc. peOutputEnc is the encoding of the result string.
@param psInput as char* @param psInputEnc as EEncoding @param psOutputEncoding as EEncoding
@return a pointer to a CStringEncoder object */ CStringEncoderABC* SSE_METHOD CreateStringEncoder( const char *psInput, CStringEncoderABC::EEncoding peInputEnc, CStringEncoderABC::EEncoding peOutputEnc);
/* Creates a String encoder. psInput is encoded as specified by peInputEnc. peOutputEnc is the encoding of the result string.
@param psInputb as CCString @param psInputEnc as EEncoding @param psOutputEnc as EEncoding
@return a pointer to a CStringEncoder object */ CStringEncoderABC* SSE_METHOD CreateStringEncoder( const CCString& psInput, CStringEncoderABC::EEncoding peInputEnc, CStringEncoderABC::EEncoding peOutputEnc);
/*! Creates a String encoder. poInput is encoded as specified by peInputEnc. peOutputEnc is the encoding of the result string.
@param poInput as CStream @param peInputEnc as EEncoding @param peOutputEnc as EEncoding
@return a pointer to a CStringEncoder object */ CStringEncoderABC* SSE_METHOD CreateStringEncoder( const CStream& poInput, CStringEncoderABC::EEncoding peInputEnc, CStringEncoderABC::EEncoding peOutputEnc);
/*! Creates an uninitialized OID object. @return a CObjectIdentifier object */ CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifier();
/*! Creates an object identifier object for the specified OID
@param psOID as CCString
@return a CObjectIdentifier object */ CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifierFromString(const CCString& psOID);
/*! Creates an object identifier object for the specified DER encoded bytes
@param psDEROID as CStream
@return a CObjectIdentifier object */ CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifierFromDER(const CStream& poDEROID);
/*! Creates an object identifier object for the specified unique ID
@param piUniqueID as unsigned int
@return a CObjectIdentifier object */ CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifierFromUniqueID(const unsigned int piUniqueID);
/*! Creates date time objects
@param peTZ as ETimeZone
@return a CDateTime object */ CCDateTimeABC* SSE_METHOD CreateCurrentDateTime(CCDateTimeABC::ETimeZone peTZ);
/*! Creates as date time object
@param piYear as unsigned int @param piMonth as unsigned int @param piDay as unsigned int @param piHour as unsigned int @param piMinute as unsigned int @param piMillisecond as unsigned int @param peTZ as ETimeZone
@return as date time object */ CCDateTimeABC* SSE_METHOD CreateDateTime(const unsigned int piYear, const unsigned int piMonth, const unsigned int piDay, const unsigned int piHour, const unsigned int piMinute, const unsigned int piSecond, const unsigned int piMillisecond, CCDateTimeABC::ETimeZone peTZ);
/*! create a date time object
@param piDateStr as CCString @param piToken as char @param peTZ as ETimeZone
@return a date time object */ CCDateTimeABC* SSE_METHOD CreateDateTime(const CCString& piDateStr, const char piToken, CCDateTimeABC::ETimeZone peTZ);
/*! Create a big number from an integer value
@param piValue as int
@return a CBigNumber object */ CBigNumberABC* SSE_METHOD CreateBigNumberFromInteger(const int piValue);
/*! Create a big number from a atream
@param poValue as CStream
@return a CBigNumber object */ CBigNumberABC* SSE_METHOD CreateBigNumberFromStream(const CStream& poValue);
/*! Create a big number from a string
@param psValue as CCString @param piBase as int - 10 is default
@return a CBigNumber object */ CBigNumberABC* SSE_METHOD CreateBigNumberFromString(const CCString& psValue, int piBase = 10);
/*! Returns a reference to the transform engine
@return a CTransportEngine object */ CTransformEngineABC& SSE_METHOD GetTransformEngine(void);
/* Creates a CSystemMonitor object
@return a CSystemMonitor object */ CSystemMonitorABC* SSE_METHOD CreateSystemMonitor(void);
/*! Performs object destruction */ void SSE_METHOD Delete(void);
// Member variable CTransformEngineABC* mpoTransformEngine; };
/*
Aici in sectiunea private sunt regasite metodele din interfata (implementarile lor) . Sa luam spre exemplu o metoda pusa la dispozititie de aceasta interfata:
CObjectIdentifierABC* SSE_METHOD CreateObjectIdentifierFromString(const CCString& psOID);
Apelul acestei metode ne pune la dispozitie un obiect CObjectIdentifierABC care din denumire ne indica accesul la o interfata ce este descrisa in felul urmator:
*/ class SSE_INTERFACE CObjectIdentifierABC : public CBaseObject { public: // Return true only if the GetOID method would return a valid OID. virtual bool SSE_METHOD IsInitialized(void) const = 0;
// Return the oid description (obtained from dumpasn1.cfg) virtual CCString SSE_METHOD GetDescription(void) const = 0;
// Return the OID in dot notation virtual CCString SSE_METHOD GetOID(void) const = 0;
// Return the DER bytes virtual CStream SSE_METHOD GetDER(void) const = 0;
// Return the unique identifier virtual unsigned int SSE_METHOD GetUniqueIdentifier(void) const = 0;
// Returns whether the object identifier was recognised virtual bool SSE_METHOD IsRecognised(void) const = 0;
// Comparison operator OVERLOADED_METHODS_2 ( virtual bool SSE_METHOD operator==(const CObjectIdentifierABC& poCompare) const = 0; , virtual bool SSE_METHOD operator==(const CCString& psOID) const = 0; ) protected: CObjectIdentifierABC(void) {}
// Certain constructors and operators are declared private in the // CBaseObject superclass };
Implementarea metodelor din interfata sunt in CObjectIdentifierImpl descrisa astfel:
class SSE_CLASS CObjectIdentifierImpl : public CObjectIdentifierABC { public: /*! Construct the implementation object @return CObjectIdentifierABC* */ static CObjectIdentifierABC* CreateObjectIdentifier();
/*! Construct the implementation object
@param psOID as CCString @return CObjectIdentifierABC* */ static CObjectIdentifierABC* CreateObjectIdentifier(const CCString& psOID);
/*! Construct the implementation object @param poDER as CStream @return CObjectIdentifierABC* */ static CObjectIdentifierABC* CreateObjectIdentifier(const CStream& poDER);
/*! Construct the implementation object
@param piUniqueID as unsigned int @return CObjectIdentifierABC* */ static CObjectIdentifierABC* CreateObjectIdentifier(const unsigned int piUniqueID);
private: /*! Constructor */ CObjectIdentifierImpl(const OID_DEFINITION& poDefinition, const CCString& psOID = "", const int piExceptionId = 0); /*! Destructor */ ~CObjectIdentifierImpl(void);
// Return true only if the GetOID method would return a valid OID. bool SSE_METHOD IsInitialized(void) const;
/*! Return the oid description (obtained from dumpasn1.cfg)
@return description as CCString */ CCString SSE_METHOD GetDescription(void) const;
/*! @return the OID in dot notation as CCString
*/ CCString SSE_METHOD GetOID(void) const;
/*! @return the DER bytes as CStream */ CStream SSE_METHOD GetDER(void) const;
/*! @return the unique identifier as unsigned int */ unsigned int SSE_METHOD GetUniqueIdentifier(void) const;
/*! @return whether the object identifier was recognised as bool */ bool SSE_METHOD IsRecognised(void) const;
/*! Comparison operators
@param poCompare as CObjectIdentifier
@return true if equal, otherwise false */ bool SSE_METHOD operator==(const CObjectIdentifierABC& poCompare) const;
/*! Comparison operators
@param psOID as CCString
@return true if equal, otherwise false */ bool SSE_METHOD operator==(const CCString& psOID) const;
/*! Performs object destruction */ void SSE_METHOD Delete(void);
/*! helper method for validating the internal state */ void SSE_METHOD Validate(void) const;
// Member variables const OID_DEFINITION& moDefinition; /**< IOD definition */
CCString msSpecifiedOID; /**< OID-Id */ int miSpecifiedExceptionId; /**< exception-ID */ };
/* Implementarea finala recurge la o clasa "proxy" CObjectIdentifier : */ class SSE_CLASS_FINAL CObjectIdentifier { public:
// Constructor for creating an uninitialized OID object. CObjectIdentifier();
// Constructor taking the object id as a string explicit CObjectIdentifier(const CCString& psOID);
// Constructor taking the object id as a DER encoded stream explicit CObjectIdentifier(const CStream& poDER);
// Copy Constructor CObjectIdentifier(const CObjectIdentifier& poCopy);
// This constructor is only to be used by the CCollection template explicit CObjectIdentifier(CObjectIdentifierABC* ppoOid);
// This constructor is used for obtaining an OID using the unique ID explicit CObjectIdentifier(const unsigned int piUniqueID);
// Destructor ~CObjectIdentifier(void);
// Return true only if the GetOID method would return a valid OID. bool SSE_METHOD IsInitialized(void) const;
// Return the oid description (obtained from dumpasn1.cfg) CCString SSE_METHOD GetDescription(void) const;
// Return the OID in dot notation CCString SSE_METHOD GetOID(void) const;
// Return the DER bytes CStream SSE_METHOD GetDER(void) const;
// Return the unique identifier unsigned int SSE_METHOD GetUniqueIdentifier(void) const;
// Returns whether the object identifier arguments specified to the // different constructors was recognised bool SSE_METHOD IsRecognised(void) const;
// Assignment operator CObjectIdentifier& SSE_METHOD operator=(const CObjectIdentifier& poCopy);
// Comparison operators bool SSE_METHOD operator==(const CObjectIdentifier& poCompare) const; bool SSE_METHOD operator==(const CCString& psOID) const; bool SSE_METHOD operator!=(const CObjectIdentifier& poCompare) const; bool SSE_METHOD operator!=(const CCString& psOID) const;
// This operator is only to be used by the CCollection template const CObjectIdentifierABC& SSE_METHOD operator*(void) const;
private: // Member variables CSmartPointer<CObjectIdentifierABC> moValue; }; /* Astfel, un exemplu de a obtine un OID folosind CreateObjectIdentifierFromString este:
CObjectIdentifier loOid( CManager::UtilitiesFactory().CreateObjectIdentifierFromString(psOid));
Deci avem lantul logic:
Daca ne punem problema asupra implementarii fizice a clasei observam ca este derivata din CBaseObject : */ class SSE_CLASS CBaseObject { public: // Compares this object agains the specified object and returns: // -1 = Less than; 0 = Equal to; 1 = Greater than virtual const int SSE_METHOD Compare(const CBaseObject& poCompare) const;
protected: // Default constructor CBaseObject(void);
// Virtual Destructor virtual ~CBaseObject(void);
// Subclasses must override this to provide object deletion virtual void SSE_METHOD Delete(void) = 0;
private: long miReferenceCount;
// Increments the reference count on this object void SSE_METHOD AddReference(void);
// Decrements the reference count on this object bool SSE_METHOD ReleaseReference(void);
friend CSmartObject; friend CObjectCollectionABC; friend CCString; }; /* Aceasta este clasa de baza pentru toate obiectele ce vor avea reference counting , clasa ce are acces la implementarile claselor CSmartObject, CObjectCollectinABC, CCString. Oricum, ce ne intereseaza este ca avem structura fizica:
Pentru parsarea declaratiilor de clasa si a membrilor sai (declaraii de variabila , prototipuri de functii) se poate folosi descrierea sintaxei din standard ce poate fi gasit la
Nail art
*/ |