natfw/natfwunsaf_protocols/unsaf_codec/src/natfwunsafnonceattribute.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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 #include "natfwunsafnonceattribute.h"
       
    22 #include "natfwunsafutils.h"
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CNATFWUNSAFNonceAttribute::NewL
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 EXPORT_C CNATFWUNSAFNonceAttribute* CNATFWUNSAFNonceAttribute::NewL(
       
    29     const TDesC8& aNonce)
       
    30     {
       
    31     CNATFWUNSAFNonceAttribute* self = CNATFWUNSAFNonceAttribute::NewLC(
       
    32         aNonce);
       
    33     CleanupStack::Pop(self);
       
    34     return self;
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CNATFWUNSAFNonceAttribute::NewLC
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CNATFWUNSAFNonceAttribute* CNATFWUNSAFNonceAttribute::NewLC(
       
    42     const TDesC8& aNonce)
       
    43     {
       
    44     CNATFWUNSAFNonceAttribute* self =
       
    45         new (ELeave) CNATFWUNSAFNonceAttribute();
       
    46     CleanupStack::PushL(self);
       
    47     TBool valid = ETrue;
       
    48     for ( TInt i = 0; i < aNonce.Length(); i++ )
       
    49         {
       
    50         valid = NATFWUNSAFUtils::IsQdTextChar(aNonce[i]);
       
    51         if ( !valid )
       
    52             {
       
    53             break;
       
    54             }
       
    55         }
       
    56     if (!valid)
       
    57         {
       
    58         if(!NATFWUNSAFUtils::IsQuotedString(aNonce))
       
    59             {
       
    60             User::Leave(KErrArgument);
       
    61             }
       
    62         }
       
    63     self->ConstructL(aNonce);
       
    64     return self;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CNATFWUNSAFNonceAttribute::DecodeAttributeL
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CNATFWUNSAFAttribute*
       
    72 CNATFWUNSAFNonceAttribute::DecodeAttributeL(const TDesC8& aByteStream)
       
    73     {
       
    74     TUint16 valueLength = ParseLengthL(aByteStream);
       
    75 
       
    76     //Stream has to have enough data for the whole value element
       
    77     __ASSERT_ALWAYS(aByteStream.Length() >= EValueOffset + valueLength,
       
    78                     User::Leave(KErrArgument));
       
    79     return NewL(aByteStream.Mid(EValueOffset, valueLength));
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CNATFWUNSAFNonceAttribute::CNATFWUNSAFNonceAttribute
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CNATFWUNSAFNonceAttribute::CNATFWUNSAFNonceAttribute() :
       
    87     CNATFWUNSAFAttribute()
       
    88     {
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CNATFWUNSAFNonceAttribute::ConstructL
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CNATFWUNSAFNonceAttribute::ConstructL(const TDesC8& aNonce)
       
    96     {
       
    97     iNonce = aNonce.AllocL();
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CNATFWUNSAFNonceAttribute::~CNATFWUNSAFNonceAttribute
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CNATFWUNSAFNonceAttribute::~CNATFWUNSAFNonceAttribute()
       
   105     {
       
   106     delete iNonce;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CNATFWUNSAFNonceAttribute::Type
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CNATFWUNSAFAttribute::TType CNATFWUNSAFNonceAttribute::Type() const
       
   114     {
       
   115     return ENonce;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CNATFWUNSAFNonceAttribute::EncodeValueL
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 HBufC8* CNATFWUNSAFNonceAttribute::EncodeValueL() const
       
   123     {
       
   124     return iNonce->AllocL();
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CNATFWUNSAFNonceAttribute::Value
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C const TDesC8& CNATFWUNSAFNonceAttribute::Value() const
       
   132     {
       
   133     return *iNonce;
       
   134     }
       
   135