KeyTransRecipientInfo.cpp

Go to the documentation of this file.
00001 
00009 #include "KeyTransRecipientInfo.h"
00010 
00011 #include "IssuerAndSerialNumber.h"
00012 #include "Buffer.h"
00013 #include "OID.h"
00014 #include "AlgorithmIdentifier.h"
00015 #include "ASN1Helper.h"
00016 
00017 #include "CryptographicMessageSyntax2004.h"
00018 
00020 struct CPKIFKeyTransRecipientInfoImpl
00021 {
00022     CACCMSCMSVersion m_version;
00023     CPKIFIssuerAndSerialNumberPtr m_issuerAndSerial;
00024     CPKIFBufferPtr m_skid;
00025     CPKIFBufferPtr m_encryptedKey;
00026     CPKIFAlgorithmIdentifierPtr m_alg;
00027 };
00029 
00037 CPKIFKeyTransRecipientInfo::CPKIFKeyTransRecipientInfo()
00038     :m_impl (new CPKIFKeyTransRecipientInfoImpl)
00039 {
00040 }
00041 
00049 CPKIFKeyTransRecipientInfo::CPKIFKeyTransRecipientInfo(
00051     //CACCMSKeyTransRecipientInfo& ktri
00052     const CPKIFBufferPtr& ktriBuf)
00053     :m_impl (new CPKIFKeyTransRecipientInfoImpl)
00054 {
00055     CACASNWRAPPER_CREATE(CACCMSKeyTransRecipientInfo, InfoWrapper);
00056     CACCMSKeyTransRecipientInfo *ktri = InfoWrapper.Decode(ktriBuf->GetBuffer(), ktriBuf->GetLength());
00057 
00058     //CPKIFAlgorithmIdentifier creation
00059     CPKIFOIDPtr algOID(new CPKIFOID(ktri->keyEncryptionAlgorithm.algorithm.subid,
00060                         ktri->keyEncryptionAlgorithm.algorithm.numids));
00061     CPKIFBufferPtr paramBuf;
00062     if(ktri->keyEncryptionAlgorithm.m.parametersPresent)
00063     {
00064         paramBuf = CPKIFBufferPtr(new CPKIFBuffer(ktri->keyEncryptionAlgorithm.parameters.data,
00065                     ktri->keyEncryptionAlgorithm.parameters.numocts));
00066     
00067     
00068     }
00069     
00070     CPKIFAlgorithmIdentifierPtr tmpAlg(new CPKIFAlgorithmIdentifier(algOID, paramBuf)); 
00071 //  CPKIFAlgorithmIdentifierPtr tmpAlg(new CPKIFAlgorithmIdentifier(*(CACX509V3AlgorithmIdentifier*)&ktri->keyEncryptionAlgorithm));
00072     CPKIFBufferPtr tmpBuf(new CPKIFBuffer(ktri->encryptedKey.data, ktri->encryptedKey.numocts));
00073 
00074     if(1 == ktri->rid.t)
00075     {
00076 
00077         CACASNWRAPPER_CREATE(CACCMSIssuerAndSerialNumber, ISNWrapper);
00078         ASN1OpenType *data = ISNWrapper.Encode (ktri->rid.u.issuerAndSerialNumber);
00079         CPKIFBufferPtr isnBuf(new CPKIFBuffer(data->data, data->numocts));
00080         delete data;
00081 
00082         CPKIFIssuerAndSerialNumberPtr tmpIAndSN(new CPKIFIssuerAndSerialNumber(isnBuf));
00083         //CPKIFIssuerAndSerialNumberPtr tmpIAndSN(new CPKIFIssuerAndSerialNumber(*ktri->rid.u.issuerAndSerialNumber));
00084         m_impl->m_issuerAndSerial = tmpIAndSN;
00085     }
00086     else
00087     {
00088         CPKIFBufferPtr tmpSKID(new CPKIFBuffer(ktri->rid.u.subjectKeyIdentifier->data, ktri->rid.u.subjectKeyIdentifier->numocts));
00089         m_impl->m_skid = tmpSKID;
00090     }
00091 
00092     m_impl->m_alg = tmpAlg;
00093     m_impl->m_encryptedKey = tmpBuf;
00094     m_impl->m_version = ktri->version;
00095 }
00096 
00097 
00105 /*CPKIFKeyTransRecipientInfo::CPKIFKeyTransRecipientInfo(
00107     CACCMSKeyTransRecipientInfo& ktri)
00108     :m_impl (new CPKIFKeyTransRecipientInfoImpl)
00109 {
00110     CPKIFAlgorithmIdentifierPtr tmpAlg(new CPKIFAlgorithmIdentifier(*(CACX509V3AlgorithmIdentifier*)&ktri.keyEncryptionAlgorithm));
00111     CPKIFBufferPtr tmpBuf(new CPKIFBuffer(ktri.encryptedKey.data, ktri.encryptedKey.numocts));
00112 
00113     if(1 == ktri.rid.t)
00114     {
00115         CPKIFIssuerAndSerialNumberPtr tmpIAndSN(new CPKIFIssuerAndSerialNumber(*ktri.rid.u.issuerAndSerialNumber));
00116         m_impl->m_issuerAndSerial = tmpIAndSN;
00117     }
00118     else
00119     {
00120         CPKIFBufferPtr tmpSKID(new CPKIFBuffer(ktri.rid.u.subjectKeyIdentifier->data, ktri.rid.u.subjectKeyIdentifier->numocts));
00121         m_impl->m_skid = tmpSKID;
00122     }
00123 
00124     m_impl->m_alg = tmpAlg;
00125     m_impl->m_encryptedKey = tmpBuf;
00126     m_impl->m_version = ktri.version;
00127 }
00128 */
00136 CPKIFKeyTransRecipientInfo::~CPKIFKeyTransRecipientInfo()
00137 {
00138     delete m_impl;
00139     m_impl = NULL;
00140 }
00164 CPKIFKeyTransRecipientInfo::RecipientIdentifierChoice CPKIFKeyTransRecipientInfo::GetRecipientIdentifierChoice() const
00165 {
00166     if(m_impl->m_issuerAndSerial != (CPKIFIssuerAndSerialNumber*)NULL)
00167         return CPKIFKeyTransRecipientInfo::ISSUERSERIAL;
00168     else if(m_impl->m_skid != (CPKIFBuffer*)NULL)
00169         return CPKIFKeyTransRecipientInfo::SKID;
00170     else
00171         return CPKIFKeyTransRecipientInfo::UNSET;
00172 }
00181 CPKIFIssuerAndSerialNumberPtr CPKIFKeyTransRecipientInfo::GetIssuerAndSerialNumber() const
00182 {
00183     return m_impl->m_issuerAndSerial;
00184 }
00193 CPKIFBufferPtr CPKIFKeyTransRecipientInfo::GetSKID() const
00194 {
00195     return m_impl->m_skid;
00196 }
00204 CPKIFAlgorithmIdentifierPtr CPKIFKeyTransRecipientInfo::GetKeyEncryptionAlgorithm() const
00205 {
00206     return m_impl->m_alg;
00207 }
00215 CPKIFBufferPtr CPKIFKeyTransRecipientInfo::GetEncryptedKey() const
00216 {
00217     return m_impl->m_encryptedKey;
00218 }

Generated on Mon Nov 15 11:15:51 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6