cms/src/CCMSX509Validity.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CCMSX509Validity.h"
       
    21 #include "TCMSTimeUtil.h"
       
    22 #include <signed.h>
       
    23 #include <asn1dec.h>
       
    24 #include <asn1enc.h>
       
    25 
       
    26 // CONSTANTS
       
    27 const TInt KNumberOfSubModules = 2;
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CCMSX509Validity::CCMSX509Validity
       
    33 // C++ constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CCMSX509Validity::CCMSX509Validity(
       
    38     const TTime& aNotBefore,
       
    39     const TTime& aNotAfter )
       
    40     : iNotBefore( aNotBefore ), iNotAfter( aNotAfter )
       
    41     {
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CCMSX509Validity::CCMSX509Validity
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CCMSX509Validity::CCMSX509Validity( )
       
    51     {
       
    52     // CBase initilises member data to zero, which is good enough
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCMSX509Validity::NewL
       
    57 // Two-phased constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C CCMSX509Validity*
       
    61 CCMSX509Validity::NewL()
       
    62 	{
       
    63 	// creating with empty values
       
    64     CCMSX509Validity* self =
       
    65         new( ELeave ) CCMSX509Validity();
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CCMSX509Validity::NewL
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CCMSX509Validity*
       
    75 CCMSX509Validity::NewL(
       
    76     const TTime& aNotBefore,
       
    77     const TTime& aNotAfter )
       
    78     {
       
    79     CCMSX509Validity* self =
       
    80         new( ELeave ) CCMSX509Validity( aNotBefore, aNotAfter ); 
       
    81     return self;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCMSX509Validity::NewL
       
    86 // Two-phased constructor.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C CCMSX509Validity*
       
    90 CCMSX509Validity::NewL( const CValidityPeriod& aValidityPeriod )
       
    91     {
       
    92     CCMSX509Validity* self =
       
    93         new( ELeave ) CCMSX509Validity( aValidityPeriod.Start(),
       
    94                                         aValidityPeriod.Finish() ); 
       
    95     return self;
       
    96     }
       
    97 
       
    98 // Destructor
       
    99 CCMSX509Validity::~CCMSX509Validity()
       
   100     {
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CCMSX509Validity::DecodeL
       
   105 // Decrypts raw data to this instance
       
   106 // -----------------------------------------------------------------------------
       
   107 void CCMSX509Validity::DecodeL( const TDesC8& aRawData )
       
   108 	{
       
   109     CArrayPtr< TASN1DecGeneric >* itemList = DecodeSequenceLC(
       
   110         aRawData, KNumberOfSubModules, KNumberOfSubModules );
       
   111 
       
   112     TInt sequenceCounter = 0;
       
   113 
       
   114     // decode notBefore
       
   115     TTime notBefore = TCMSTimeUtil::ConvertToTimeL(
       
   116         itemList->At( sequenceCounter++ )->Encoding() );
       
   117 
       
   118     // decode notAfter
       
   119     TTime notAfter = TCMSTimeUtil::ConvertToTimeL(
       
   120         itemList->At( sequenceCounter )->Encoding() );
       
   121 
       
   122     // all done, change state
       
   123     iNotBefore = notBefore;
       
   124     iNotAfter = notAfter;
       
   125 
       
   126     CleanupStack::PopAndDestroy( itemList );
       
   127 	}
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CCMSX509Validity::EncoderLC
       
   131 // Returns ASN1 encoder for this instance
       
   132 // -----------------------------------------------------------------------------
       
   133 
       
   134 CASN1EncBase* CCMSX509Validity::EncoderLC() const
       
   135 	{
       
   136     CASN1EncSequence* root = CASN1EncSequence::NewLC();
       
   137 
       
   138     // encode notBefore
       
   139     CASN1EncBase* notBefore = TCMSTimeUtil::ConvertToEncoderLC( iNotBefore );
       
   140     root->AddAndPopChildL( notBefore );
       
   141 
       
   142     // encode notAfter
       
   143     CASN1EncBase* notAfter = TCMSTimeUtil::ConvertToEncoderLC( iNotAfter );
       
   144     root->AddAndPopChildL( notAfter );
       
   145 
       
   146     return root;
       
   147 	}
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CCMSX509Validity::NotBefore()
       
   151 // Getter for notBefore
       
   152 // -----------------------------------------------------------------------------
       
   153 EXPORT_C const TTime&
       
   154 CCMSX509Validity::NotBefore() const
       
   155 	{
       
   156 	return iNotBefore;
       
   157 	}
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CCMSX509Validity::NotAfter()
       
   161 // Getter for notAfter
       
   162 // -----------------------------------------------------------------------------
       
   163 EXPORT_C const TTime&
       
   164 CCMSX509Validity::NotAfter() const
       
   165 	{
       
   166 	return iNotAfter;
       
   167 	}
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CCMSX509Validity::SetNotBefore()
       
   171 // Setter for notBefore
       
   172 // -----------------------------------------------------------------------------
       
   173 EXPORT_C void CCMSX509Validity::SetNotBefore(
       
   174     const TTime& aNotBefore )
       
   175 	{
       
   176     iNotBefore = aNotBefore;
       
   177 	}
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CCMSX509Validity::SetNotAfter()
       
   181 // Setter for notAfter
       
   182 // -----------------------------------------------------------------------------
       
   183 EXPORT_C void CCMSX509Validity::SetNotAfter(
       
   184     const TTime& aNotAfter )
       
   185 	{
       
   186     iNotAfter = aNotAfter;
       
   187 	}
       
   188 
       
   189 //  End of File