Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

WriteKeyMsg.cc

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: WriteKeyMsg.cc,v 1.3 2004/05/19 15:56:49 mmarsh Exp $
00008 //
00009 // $Log: WriteKeyMsg.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:49  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:31:48  mmarsh
00014 // *** empty log message ***
00015 //
00016 //
00017 
00018 #include "Message.h"
00019 
00020 using namespace CODEX_Client;
00021 using namespace CODEX_ASN1;
00022 using namespace CODEX_Ciphers;
00023 
00024 WriteKeyMsg::WriteKeyMsg() :
00025    Message( false )
00026 {
00027 }
00028 
00029 WriteKeyMsg::WriteKeyMsg( const OctetString& name,
00030                           const RequestCipherTextType& encryption,
00031 #ifndef ELGAMAL
00032                           const RSAPlaintextPK& proof,
00033 #endif
00034                           const Credentials& credentials,
00035                           const SignedBoundNameMsg& binding ) :
00036    Message( true ),
00037    m_name( name ),
00038    m_encryption( encryption ),
00039 #ifndef ELGAMAL
00040    m_proof( proof ),
00041 #endif
00042    m_credentials( credentials ),
00043    m_binding( binding )
00044 {
00045 }
00046 
00047 WriteKeyMsg::WriteKeyMsg( const WriteKeyMsg& aWKM ) :
00048    Message( aWKM.m_initialized ),
00049    m_name( aWKM.m_name ),
00050    m_encryption( aWKM.m_encryption ),
00051 #ifndef ELGAMAL
00052    m_proof( aWKM.m_proof ),
00053 #endif
00054    m_credentials( aWKM.m_credentials ),
00055    m_binding( aWKM.m_binding )
00056 {
00057 }
00058 
00059 void
00060 WriteKeyMsg::operator=( const WriteKeyMsg& aWKM )
00061 {
00062    m_initialized = aWKM.m_initialized;
00063    m_name        = aWKM.m_name;
00064    m_encryption  = aWKM.m_encryption;
00065 #ifndef ELGAMAL
00066    m_proof       = aWKM.m_proof;
00067 #endif
00068    m_credentials = aWKM.m_credentials;
00069    m_binding     = aWKM.m_binding;
00070 }
00071 
00072 int
00073 WriteKeyMsg::marshal( unsigned char ** pp ) const
00074 {
00075    int r=0;
00076    int ret=0;
00077    unsigned char * p;
00078 
00079    ret += m_name.marshal(0);
00080    ret += m_encryption.marshal(0);
00081 #ifndef ELGAMAL
00082    ret += m_proof.marshal(0);
00083 #endif
00084    ret += m_credentials.marshal(0);
00085    ret += m_binding.marshal(0);
00086    M_ASN1_I2D_seq_total();
00087    m_name.marshal(&p);
00088    m_encryption.marshal(&p);
00089 #ifndef ELGAMAL
00090    m_proof.marshal(&p);
00091 #endif
00092    m_credentials.marshal(&p);
00093    m_binding.marshal(&p);
00094    M_ASN1_I2D_finish();
00095 }
00096 
00097 void*
00098 WriteKeyMsg::unmarshal( void* bogus, unsigned char ** pp, long length )
00099 {
00100    if ( m_initialized )
00101    {
00102       return NULL;
00103    }
00104    if ( (NULL == pp) || (NULL == *pp) )
00105    {
00106       return NULL;
00107    }
00108    ASN1_CTX c;
00109    c.pp = pp;
00110    c.q = *pp;
00111    c.error = ERR_R_NESTED_ASN1_ERROR;
00112    int i;
00113 
00114    M_ASN1_D2I_Init();
00115    M_ASN1_D2I_start_sequence();
00116    M_ASN1_D2I_get(i, m_name.unmarshal);
00117    M_ASN1_D2I_get(i, m_encryption.unmarshal);
00118 #ifndef ELGAMAL
00119    M_ASN1_D2I_get(i, m_proof.unmarshal);
00120 #endif
00121    M_ASN1_D2I_get(i, m_credentials.unmarshal);
00122    M_ASN1_D2I_get(i, m_binding.unmarshal);
00123    if ( !asn1_Finish(&c) )
00124    {
00125       return NULL;
00126    }
00127    *pp=c.p;
00128    m_initialized = true;
00129    return this;
00130   err: // needed by ASN.1 macros
00131    return NULL;
00132 }

Generated on Fri May 6 17:41:31 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1