SubjectKeyIdentifier.cpp

Go to the documentation of this file.
00001 
00009 #include "SubjectKeyIdentifier.h"
00010 #include "OID.h"
00011 #include "Buffer.h"
00012 
00013 #include "ASN1Helper.h"
00014 #include "PKIX1Implicit88.h"
00015 #include "PKIX1Explicit88.h"
00016 #include "ToolkitUtils.h"
00017 
00018 #include <boost/scoped_array.hpp>
00019 #include <iostream>
00020 
00022 
00023 struct CPKIFSubjectKeyIdentifierImpl
00024 {
00025     CPKIFBufferPtr m_keyID;
00026     CPKIFBufferPtr m_value;
00027     bool m_extModified;
00028 };
00029 
00031 
00032 char CPKIFSubjectKeyIdentifier::extOID[] =      "2.5.29.14";
00033 
00045 CPKIFSubjectKeyIdentifier::CPKIFSubjectKeyIdentifier()
00046   :m_impl (new CPKIFSubjectKeyIdentifierImpl)
00047 {
00048 }
00049 
00057 CPKIFBufferPtr CPKIFSubjectKeyIdentifier::KeyIdentifier() const 
00058 {
00059     return m_impl->m_keyID;
00060 }
00068 void CPKIFSubjectKeyIdentifier::SetKeyIdentifier(CPKIFBufferPtr &skid) 
00069 {
00070     m_impl->m_keyID = skid;
00071     m_impl->m_extModified = true;
00072 }
00084 //CPKIFSubjectKeyIdentifier::CPKIFSubjectKeyIdentifier(
00085 //  //! [in] Reference to an internal structure representation of the extension containing information 
00086 //  //! used to construct the object
00087 //  const CACX509V3Extension& ext) 
00088 //  : CPKIFX509Extension(ext), m_impl (new CPKIFSubjectKeyIdentifierImpl)
00089 //{
00090 //  CACASNWRAPPER_CREATE(CACX509V3SubjectKeyIdentifier, objPDU);
00091 //  objPDU.Decode(ext.extnValue.data, ext.extnValue.numocts);
00092 //
00093 //  CPKIFBufferPtr tmpBP(new CPKIFBuffer(objPDU->data, objPDU->numocts));
00094 //  m_impl->m_keyID = tmpBP;
00095 //}
00096 
00108 CPKIFSubjectKeyIdentifier::CPKIFSubjectKeyIdentifier(
00109     const bool& criticality, const CPKIFBufferPtr& ext) 
00110   : CPKIFX509Extension (criticality, ext), m_impl (new CPKIFSubjectKeyIdentifierImpl)
00111 {
00112     CACASNWRAPPER_CREATE(CACX509V3SubjectKeyIdentifier, objPDU);
00113     objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00114 
00115     CPKIFBufferPtr tmpBP(new CPKIFBuffer(objPDU->data, objPDU->numocts));
00116     m_impl->m_keyID = tmpBP;
00117 
00118     m_impl->m_value = ext;
00119     m_impl->m_extModified = false;
00120 }
00121 
00129 CPKIFSubjectKeyIdentifier::~CPKIFSubjectKeyIdentifier()
00130 {
00131     if(m_impl)
00132     {
00133         delete m_impl;
00134         m_impl = 0;
00135     }
00136 }
00137 
00146 const CPKIFOIDPtr CPKIFSubjectKeyIdentifier::oid() const
00147 {
00148     //added static variable for copying instead of string creation each call
00149     static CPKIFOID staticOID(extOID);
00150     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00151     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00152     return tmp;
00153 }
00154 
00162 CPKIFBufferPtr CPKIFSubjectKeyIdentifier::value() const 
00163 {
00164     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00165     {
00166         CACASNWRAPPER_CREATE(CACX509V3SubjectKeyIdentifier, objPDU);    
00167         CACX509V3SubjectKeyIdentifier ext;
00168         memset(&ext, 0, sizeof(CACX509V3SubjectKeyIdentifier));
00169 
00170         ext.data = new unsigned char[m_impl->m_keyID->GetLength()];
00171         memcpy((void*)ext.data, m_impl->m_keyID->GetBuffer(), m_impl->m_keyID->GetLength());
00172         ext.numocts = m_impl->m_keyID->GetLength();
00173 
00174 
00175         ASN1OpenType* extEncoded = NULL;
00176         extEncoded = objPDU.Encode(&ext);
00177 
00178         CPKIFBufferPtr tmp(new CPKIFBuffer(extEncoded->data, extEncoded->numocts));
00179         
00180         m_impl->m_value = tmp;
00181         m_impl->m_extModified = false;
00182         if(extEncoded)
00183             delete extEncoded;
00184 
00185         if(ext.data)
00186             delete [] ext.data;
00187     }
00188 
00189     return m_impl->m_value;
00190 }
00191 
00193 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFSubjectKeyIdentifierPtr & skid)
00194 {
00195     return operator<<(os,*skid);
00196 }
00197 
00199 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFSubjectKeyIdentifier & skid)
00200 {
00201 
00202     CPKIFBufferPtr kidBuf = skid.KeyIdentifier();
00203     if(!kidBuf) return os << "(null)";
00204     boost::scoped_array<char> buf(new char[2*kidBuf->GetLength()+1]);
00205     btoa((char*)kidBuf->GetBuffer(), buf.get(), kidBuf->GetLength());
00206     return os << buf.get();
00207 }

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