Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Integer.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: Integer.cc,v 1.3 2004/05/19 15:56:37 mmarsh Exp $
00008 //
00009 // $Log: Integer.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:37  mmarsh
00011 // Added copyright and license statements.
00012 //
00013 // Revision 1.2  2003/11/04 22:31:46  mmarsh
00014 // *** empty log message ***
00015 //
00016 //
00017 
00018 #include "Integer.h"
00019 
00020 using namespace CODEX_ASN1;
00021 
00022 Integer::Integer() :
00023    Base( false ),
00024    m_value( 0 ),
00025    m_asn1( 0 )
00026 {
00027 }
00028 
00029 Integer::Integer( int value ) :
00030    Base( true ),
00031    m_value( value )
00032 {
00033    m_asn1 = ASN1_INTEGER_new();
00034    ASN1_INTEGER_set( m_asn1, m_value );
00035 }
00036    
00037 Integer::Integer( const ASN1_INTEGER* asn1 ) :
00038    Base( true )
00039 {
00040    m_asn1 = M_ASN1_INTEGER_dup( asn1 );
00041    m_value = (int) ASN1_INTEGER_get(m_asn1);
00042 }
00043 
00044 Integer::Integer( const Integer& aInt ) :
00045    Base( aInt.m_initialized ),
00046    m_value( aInt.m_value ),
00047    m_asn1( 0 )
00048 {
00049    if ( 0 != aInt.m_asn1 )
00050    {
00051       m_asn1 = M_ASN1_INTEGER_dup( aInt.m_asn1 );
00052    }
00053 }
00054 
00055 Integer::~Integer()
00056 {
00057    ASN1_INTEGER_free( m_asn1 );
00058 }
00059 
00060 void
00061 Integer::operator=( const Integer& aInt )
00062 {
00063    m_initialized = aInt.m_initialized;
00064    m_value = aInt.m_value;
00065    if ( 0 != m_asn1 )
00066    {
00067       M_ASN1_INTEGER_free( m_asn1 );
00068       m_asn1 = 0;
00069    }
00070    if ( 0 != aInt.m_asn1 )
00071    {
00072       m_asn1 = M_ASN1_INTEGER_dup( aInt.m_asn1 );
00073    }
00074 }
00075 
00076 int
00077 Integer::marshal( unsigned char ** pp ) const
00078 {
00079    return i2d_ASN1_INTEGER( m_asn1, pp );
00080 }
00081 
00082 void*
00083 Integer::unmarshal( void* bogus, unsigned char** pp, long length )
00084 {
00085    if ( m_initialized )
00086    {
00087       return NULL;
00088    }
00089    if ( 0 == d2i_ASN1_INTEGER( &m_asn1, (unsigned char**)pp, length ) )
00090    {
00091       return NULL;
00092    }
00093    m_value = (int) ASN1_INTEGER_get(m_asn1);
00094    m_initialized = true;
00095    return this;
00096 }

Generated on Wed Jun 2 16:32:55 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18