rtp/srtpstack/src/srtpmasterkey.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2004 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 
       
    20 
       
    21 // INCLUDES
       
    22 #include <e32std.h>
       
    23 #include "srtpmasterkey.h"
       
    24 #include "srtpmastersalt.h"
       
    25 #include "srtpcryptocontext.h"
       
    26 #include "srtpdef.h"
       
    27 #include "srtputils.h"
       
    28 
       
    29 
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // Two-phased constructor. Used when stream uses its own cryptographic context
       
    33 // 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C CSRTPMasterKey* CSRTPMasterKey::NewL( const TDesC8& aKey, 
       
    37                        const TDesC8& aMKI, 
       
    38                        TUint aN_E, 
       
    39                        TUint aN_A )
       
    40     {
       
    41     
       
    42     
       
    43     CSRTPMasterKey* self = CSRTPMasterKey::NewLC( aKey,
       
    44                                                   aMKI,
       
    45                                                   aN_E, 
       
    46                                                   aN_A);
       
    47     CleanupStack::Pop( self );        
       
    48     return self;
       
    49     }	
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Two-phased constructor. Used when stream uses its own cryptographic context
       
    53 // 
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CSRTPMasterKey* CSRTPMasterKey::NewLC( const TDesC8& aKey, 
       
    57                        const TDesC8& aMKI, 
       
    58                        TUint aN_E, 
       
    59                        TUint aN_A )
       
    60     {
       
    61                                           
       
    62     CSRTPMasterKey* self = new( ELeave )CSRTPMasterKey ( aN_E, 
       
    63                                                          aN_A);                                                
       
    64     CleanupStack::PushL( self );    
       
    65     self->ConstructL( aKey, aMKI );
       
    66     return self;
       
    67     }	
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CSRTPMasterKey::CSRTPMasterKey
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CSRTPMasterKey::CSRTPMasterKey( TUint aN_E, 
       
    74                                 TUint aN_A) :
       
    75             iN_E( aN_E ),
       
    76             iN_A( aN_A )
       
    77             {
       
    78             }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CSRTPMasterKey::ConstructL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CSRTPMasterKey::ConstructL(  const TDesC8& aKey, 
       
    85                                   const TDesC8& aMKI )
       
    86 	{
       
    87     iKey = aKey.AllocL();
       
    88     if(aKey.Length()>16)
       
    89 	    {
       
    90 	    TSRTPUtils::HexString( *iKey );	
       
    91 	    }
       
    92     iMKI = aMKI.AllocL();
       
    93     iMKI->Des().SetLength(aMKI.Length());
       
    94    	}
       
    95 	
       
    96 // ---------------------------------------------------------------------------
       
    97 // CSRTPMasterKey::~CSRTPMasterKey
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CSRTPMasterKey::~CSRTPMasterKey( )
       
   101            
       
   102     {
       
   103     delete iKey;
       
   104     delete iMKI;
       
   105     }
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CSRTPMasterKey::MasterKey
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C  const TDesC8& CSRTPMasterKey::MasterKey() const
       
   113     {
       
   114     return *iKey;
       
   115     }
       
   116         
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CCSRTPMasterKey::MKI
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 EXPORT_C  const TDesC8& CSRTPMasterKey::MKI() const
       
   123     {
       
   124     return *iMKI;
       
   125     };
       
   126                             
       
   127 // ---------------------------------------------------------------------------
       
   128 // CSRTPMasterKey::EncrKeyLength
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C  TUint CSRTPMasterKey::EncrKeyLength() const
       
   132     {
       
   133     return iN_E;
       
   134     }
       
   135 
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CSRTPMasterKey::AuthKeyLength
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 EXPORT_C  TUint CSRTPMasterKey::AuthKeyLength() const
       
   142     {
       
   143     return iN_A;
       
   144     }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CSRTPMasterKey::operator=
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151  const CSRTPMasterKey& CSRTPMasterKey::operator=(const CSRTPMasterKey& aKey)
       
   152     {
       
   153     return aKey;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CSRTPMasterKey::Valid()
       
   158 // ---------------------------------------------------------------------------
       
   159 //       
       
   160 EXPORT_C  TBool CSRTPMasterKey::Valid() const
       
   161     {    
       
   162     if (iKey->Length() != KSRTPDefaultMasterKeyLength/8)
       
   163         {
       
   164         return EFalse;
       
   165         }       
       
   166     
       
   167     if (iN_E != KSRTPDefSessionEncryptionKeyLength)
       
   168         {
       
   169         return EFalse;
       
   170         }   
       
   171         
       
   172     if (iN_A != KSRTPDefSessionAuthenticationKeyLength)
       
   173         {
       
   174         return EFalse;
       
   175         }
       
   176         
       
   177     return ETrue;
       
   178     }
       
   179     
       
   180 
       
   181 
       
   182