KeyAgreePublicKey.cpp
Go to the documentation of this file.00001
00010 #include "KeyAgreePublicKey.h"
00011 #include "components.h"
00012 #include "ToolkitUtils.h"
00013 #include "Buffer.h"
00014 #include "PKIFSCVPErrors.h"
00015 #include "SCVPException.h"
00016 #include "ASN1Helper.h"
00017 #include "SCVP.h"
00018 #include "AlgorithmIdentifier.h"
00019 #include "OID.h"
00020
00022
00023 struct CPKIFKeyAgreePublicKeyImpl
00024 {
00025 CPKIFBufferPtr m_publicKey;
00026 CPKIFAlgorithmIdentifierPtr m_algorithm;
00027 CPKIFAlgorithmIdentifierPtr m_macAlgorithm;
00028 CPKIFAlgorithmIdentifierPtr m_kDF;
00029 };
00030
00032
00041 CPKIFKeyAgreePublicKey::CPKIFKeyAgreePublicKey() :m_impl(new CPKIFKeyAgreePublicKeyImpl)
00042 {
00043 LOG_STRING_DEBUG("CPKIFKeyAgreePublicKey::CPKIFKeyAgreePublicKey()", TOOLKIT_SCVP_ASN, 0, this);
00044
00045 }
00056 CPKIFKeyAgreePublicKey::CPKIFKeyAgreePublicKey(
00058 const CPKIFBufferPtr& keyAgreePublicKey)
00059 :m_impl (new CPKIFKeyAgreePublicKeyImpl)
00060 {
00061 if(keyAgreePublicKey == (CPKIFBuffer*)NULL || 0 == keyAgreePublicKey->GetLength())
00062 {
00063 throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00064 }
00065
00066 CACASNWRAPPER_CREATE(KeyAgreePublicKey, objPDU);
00067 objPDU.Decode(keyAgreePublicKey->GetBuffer(), keyAgreePublicKey->GetLength());
00068
00069 CPKIFBufferPtr buff(new CPKIFBuffer(objPDU->publicKey.data, objPDU->publicKey.numbits/8));
00070
00071 m_impl->m_publicKey = buff;
00072
00073
00074 CPKIFOIDPtr algOID(new CPKIFOID(objPDU->algorithm.algorithm.subid, objPDU->algorithm.algorithm.numids));
00075
00076 CPKIFBufferPtr algParams;
00077 if(objPDU->algorithm.m.parametersPresent == 1)
00078 {
00079 CPKIFBufferPtr tmpAlgParams(new CPKIFBuffer(objPDU->algorithm.parameters.data, objPDU->algorithm.parameters.numocts));
00080
00081 algParams = tmpAlgParams;
00082 }
00083 CPKIFAlgorithmIdentifierPtr alg(new CPKIFAlgorithmIdentifier(algOID, algParams));
00084
00085 m_impl->m_algorithm = alg;
00086
00087
00088
00089 CPKIFOIDPtr macAlgOID(new CPKIFOID(objPDU->macAlgorithm.algorithm.subid, objPDU->macAlgorithm.algorithm.numids));
00090
00091 CPKIFBufferPtr macAlgParams;
00092 if(objPDU->macAlgorithm.m.parametersPresent == 1)
00093 {
00094 CPKIFBufferPtr tmpAlgParams(new CPKIFBuffer(objPDU->macAlgorithm.parameters.data, objPDU->macAlgorithm.parameters.numocts));
00095
00096 macAlgParams = tmpAlgParams;
00097 }
00098 CPKIFAlgorithmIdentifierPtr macAlg(new CPKIFAlgorithmIdentifier(macAlgOID, macAlgParams));
00099
00100 m_impl->m_macAlgorithm = macAlg;
00101
00102
00103 CPKIFOIDPtr kDFAlgOID(new CPKIFOID(objPDU->kDF.algorithm.subid, objPDU->kDF.algorithm.numids));
00104
00105 CPKIFBufferPtr kDFAlgParams;
00106 if(objPDU->kDF.m.parametersPresent == 1)
00107 {
00108 CPKIFBufferPtr tmpAlgParams(new CPKIFBuffer(objPDU->kDF.parameters.data, objPDU->kDF.parameters.numocts));
00109
00110 kDFAlgParams = tmpAlgParams;
00111 }
00112 CPKIFAlgorithmIdentifierPtr kDFAlg(new CPKIFAlgorithmIdentifier(kDFAlgOID, kDFAlgParams));
00113
00114 m_impl->m_kDF = kDFAlg;
00115
00116 }
00124 CPKIFKeyAgreePublicKey::~CPKIFKeyAgreePublicKey()
00125 {
00126 LOG_STRING_DEBUG("CPKIFKeyAgreePublicKey::~CPKIFKeyAgreePublicKey()", TOOLKIT_SCVP_ASN, 0, this);
00127
00128 if (m_impl) {
00129 delete m_impl;
00130 }
00131 }
00139 void CPKIFKeyAgreePublicKey::SetPublicKey(
00142 CPKIFBufferPtr& publicKey)
00143 {
00144 LOG_STRING_DEBUG("CPKIFKeyAgreePublicKey::SetNonce(CPKIFStringPtr& nonce)", TOOLKIT_SCVP_ASN, 0, this);
00145
00146 m_impl->m_publicKey = publicKey;
00147 }
00155 const CPKIFBufferPtr CPKIFKeyAgreePublicKey::GetPublicKey() const
00156 {
00157 if(m_impl->m_publicKey == NULL)
00158 {
00159 CPKIFBufferPtr t;
00160 return t;
00161 }
00162 else
00163 return m_impl->m_publicKey;
00164 }
00165
00173 void CPKIFKeyAgreePublicKey::SetAlgorithm(
00175 CPKIFAlgorithmIdentifierPtr& algorithm)
00176 {
00177 m_impl->m_algorithm = algorithm;
00178 }
00186 CPKIFAlgorithmIdentifierPtr CPKIFKeyAgreePublicKey::GetAlgorithm() const
00187 {
00188 return m_impl->m_algorithm;
00189 }
00190
00198 void CPKIFKeyAgreePublicKey::SetMACAlgorithm(
00200 CPKIFAlgorithmIdentifierPtr& macAlgorithm)
00201 {
00202 m_impl->m_macAlgorithm = macAlgorithm;
00203 }
00211 CPKIFAlgorithmIdentifierPtr CPKIFKeyAgreePublicKey::GetMACAlgorithm() const
00212 {
00213 return m_impl->m_macAlgorithm;
00214 }
00215
00223 void CPKIFKeyAgreePublicKey::SetKDF(
00225 CPKIFAlgorithmIdentifierPtr& kDF)
00226 {
00227 m_impl->m_kDF = kDF;
00228 }
00236 CPKIFAlgorithmIdentifierPtr CPKIFKeyAgreePublicKey::GetKDF() const
00237 {
00238 return m_impl->m_kDF;
00239 }