00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "Credentials.h"
00019 #include "CODEX_Exceptions/BignumExceptions.h"
00020
00021 using namespace CODEX_Ciphers;
00022 using namespace CODEX_Exceptions;
00023
00024 Credentials::Credentials() :
00025 CODEX_ASN1::Base( false )
00026 {
00027 }
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 Credentials::Credentials( const RSAPublicKey& publicKey ) :
00043 CODEX_ASN1::Base( true ),
00044 m_publicKey( publicKey )
00045 {
00046 }
00047
00048 Credentials::Credentials( const Credentials& aCred ) :
00049 CODEX_ASN1::Base( aCred ),
00050 m_publicKey( aCred.m_publicKey )
00051 {
00052 }
00053
00054 void
00055 Credentials::operator=( const Credentials& aCred )
00056 {
00057 m_initialized = aCred.m_initialized;
00058 m_publicKey = aCred.m_publicKey;
00059 }
00060
00061 const RSAPublicKey&
00062 Credentials::publicKey() const
00063 {
00064 return m_publicKey;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 int
00106 Credentials::marshal( unsigned char ** pp ) const
00107 {
00108 int r=0;
00109 int ret=0;
00110 unsigned char * p;
00111
00112 ret += m_publicKey.marshal(0);
00113 M_ASN1_I2D_seq_total();
00114 m_publicKey.marshal(&p);
00115 M_ASN1_I2D_finish();
00116 }
00117
00118 void*
00119 Credentials::unmarshal( void* bogus, unsigned char ** pp, long length )
00120 {
00121 if ( m_initialized )
00122 {
00123 return NULL;
00124 }
00125 if ( (NULL == pp) || (NULL == *pp) )
00126 {
00127 return NULL;
00128 }
00129
00130 ASN1_CTX c;
00131 c.pp = pp;
00132 c.q = *pp;
00133 c.error = ERR_R_NESTED_ASN1_ERROR;
00134 int i;
00135
00136 M_ASN1_D2I_Init();
00137 M_ASN1_D2I_start_sequence();
00138 M_ASN1_D2I_get(i, m_publicKey.unmarshal);
00139 if ( !asn1_Finish(&c) )
00140 {
00141 return NULL;
00142 }
00143 *pp=c.p;
00144 m_initialized = true;
00145 return this;
00146 err:
00147 return NULL;
00148 }