javaextensions/satsa/apdu/src.s60/cstsprincipal.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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 <asn1dec.h>
       
    21 #include "cstsprincipal.h"
       
    22 
       
    23 namespace java
       
    24 {
       
    25 namespace satsa
       
    26 {
       
    27 
       
    28 CSTSPrincipal::CSTSPrincipal()
       
    29 {
       
    30 }
       
    31 
       
    32 void CSTSPrincipal::ConstructL()
       
    33 {
       
    34     // creating with empty values
       
    35     iPrincipalID = KNullDesC8().AllocL();
       
    36     iDomain = KNullDesC().AllocL();
       
    37 }
       
    38 
       
    39 CSTSPrincipal* CSTSPrincipal::NewLC()
       
    40 {
       
    41     CSTSPrincipal* self = new(ELeave) CSTSPrincipal();
       
    42     CleanupStack::PushL(self);
       
    43     self->ConstructL();
       
    44     return self;
       
    45 }
       
    46 
       
    47 CSTSPrincipal::~CSTSPrincipal()
       
    48 {
       
    49     delete iPrincipalID;
       
    50     delete iDomain;
       
    51 }
       
    52 
       
    53 // --------------------------------------------------------------------
       
    54 // CSTSPrincipal::DecodeL
       
    55 // Decrypts raw data to this instance
       
    56 // --------------------------------------------------------------------
       
    57 void CSTSPrincipal::DecodeL(const TDesC8& aRawData)
       
    58 {
       
    59     TASN1DecGeneric decGen(aRawData);
       
    60     decGen.InitL();
       
    61     TInt tag = decGen.Tag();
       
    62     switch (tag)
       
    63     {
       
    64     case ERootID:
       
    65     case EEndEntityID:
       
    66     {
       
    67         iType = (TType) tag;
       
    68         if (decGen.Class() != EContextSpecific)
       
    69         {
       
    70             User::Leave(KErrArgument);
       
    71         }
       
    72         TASN1DecOctetString octetDecoder;
       
    73         TInt pos = 0; // next method's parameter is reference to int
       
    74         HBufC8* tmpPrincipalID =
       
    75             octetDecoder.DecodeDERL(decGen.Encoding(), pos);
       
    76         delete iPrincipalID;
       
    77         iPrincipalID = tmpPrincipalID;
       
    78         break;
       
    79     }
       
    80     case EDomain:
       
    81     {
       
    82         iType = EDomain;
       
    83         if (decGen.Class() != EContextSpecific)
       
    84         {
       
    85             User::Leave(KErrArgument);
       
    86         }
       
    87         TInt pos = 0; //next method's parameter is reference to int
       
    88         TASN1DecObjectIdentifier decOidDomain;
       
    89         HBufC* oid = decOidDomain.DecodeDERL(decGen.Encoding(), pos);
       
    90         delete iDomain;
       
    91         iDomain = oid;
       
    92         break;
       
    93     }
       
    94     default:
       
    95     {
       
    96         //rest is for future extensions, we will not need them
       
    97     }
       
    98     }
       
    99 }
       
   100 // --------------------------------------------------------------------
       
   101 // CSTSPrincipal::Type
       
   102 // Getter for principal type
       
   103 // --------------------------------------------------------------------
       
   104 CSTSPrincipal::TType CSTSPrincipal::Type() const
       
   105 {
       
   106     return iType;
       
   107 }
       
   108 
       
   109 // --------------------------------------------------------------------
       
   110 // CSTSPrincipal::PrincipalID
       
   111 // Getter for principal id
       
   112 // --------------------------------------------------------------------
       
   113 const TDesC8& CSTSPrincipal::PrincipalID() const
       
   114 {
       
   115     return *iPrincipalID;
       
   116 }
       
   117 
       
   118 // ---------------------------------------------------------------------
       
   119 // CSTSPrincipal::Domain
       
   120 // Getter for domain
       
   121 // ---------------------------------------------------------------------
       
   122 const TDesC& CSTSPrincipal::Domain() const
       
   123 {
       
   124     return *iDomain;
       
   125 }
       
   126 
       
   127 } // namespace satsa
       
   128 } // namespace java
       
   129 //  End of File