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

Credentials.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: Credentials.cc,v 1.3 2004/05/19 15:56:46 mmarsh Exp $
00008 //
00009 // $Log: Credentials.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:46  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:31:47  mmarsh
00014 // *** empty log message ***
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 //Credentials::Credentials( const RSAPublicKey& publicKey,
00030 //                          const RSASignature& signature ) :
00031 //   PolCredBase( publicKey, signature )
00032 //{
00033 //}
00034 
00035 //Credentials::Credentials( const RSAPublicKey& publicKey,
00036 //                          const RSAPrivateKey& signingKey,
00037 //                          const HashFunction& hashFunc ) :
00038 //   PolCredBase( publicKey, signingKey, hashFunc )
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 //BIGNUM *
00068 //Credentials::digest( const CODEX_Ciphers::HashFunction& hf ) const
00069 //{
00070 //   unsigned char* buff = NULL;
00071 //   BIGNUM * retVal = NULL;
00072 //   CODEX_ASN1::ustring* str = NULL;
00073 //
00074 //   try
00075 //   {
00076 //      int length = marshal(0);
00077 //      buff = new unsigned char[ length ];
00078 //      unsigned char* pBuff = buff;
00079 //      marshal(&pBuff);
00080 //      str = hf( CODEX_ASN1::ustring( buff, length ) );
00081 //      delete buff;
00082 //      buff = NULL;
00083 //      retVal = BN_new();
00084 //      if ( NULL == retVal )
00085 //      {
00086 //         throw BignumNullException( __FILE__ , __LINE__ );
00087 //      }
00088 //      if ( NULL == BN_bin2bn( str->data(), str->length(), retVal ) )
00089 //      {
00090 //         throw BignumBin2BNException( __FILE__ , __LINE__ );
00091 //      }
00092 //      delete str;
00093 //
00094 //      return retVal;
00095 //   }
00096 //   catch ( ... )
00097 //   {
00098 //      if ( NULL != buff ) delete buff;
00099 //      if ( NULL != str ) delete str;
00100 //      if ( NULL != retVal ) BN_free( retVal );
00101 //      throw;
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: // needed by ASN.1 macros
00147    return NULL;
00148 }

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