cryptoservices/certificateandkeymgmt/x509/x509constraintext.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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 the License "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 <asn1dec.h>
       
    20 #include <x509constraintext.h>
       
    21 
       
    22 // Integer list methods
       
    23 EXPORT_C CX509IntListExt* CX509IntListExt::NewL(const TDesC8& aBinaryData)
       
    24 	{	
       
    25 	CX509IntListExt* self = CX509IntListExt::NewLC(aBinaryData);
       
    26 	CleanupStack::Pop(self);
       
    27 	return self;
       
    28 	}
       
    29 	
       
    30 EXPORT_C CX509IntListExt* CX509IntListExt::NewLC(const TDesC8& aBinaryData)
       
    31 	{
       
    32 	CX509IntListExt* self = new(ELeave) CX509IntListExt;
       
    33 	CleanupStack::PushL(self);
       
    34 	
       
    35 	TInt pos = 0;
       
    36 	self->ConstructL(aBinaryData, pos);
       
    37 	return self;
       
    38 	}
       
    39 
       
    40 CX509IntListExt::~CX509IntListExt() 
       
    41 	{
       
    42 	iIntArray.Close();
       
    43 	}
       
    44 	
       
    45 EXPORT_C const RArray<TInt>& CX509IntListExt::IntArray() const 
       
    46 	{
       
    47 	return iIntArray;	
       
    48 	}		
       
    49 
       
    50 void CX509IntListExt::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
    51 	{
       
    52 	CX509ExtensionBase::ConstructL(aBinaryData, aPos);
       
    53 	}
       
    54 
       
    55 void CX509IntListExt::DoConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
    56 	{
       
    57 	TASN1DecSequence encSeq;	
       
    58 	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos);
       
    59 	TInt count = seq->Count();
       
    60 	
       
    61 	TASN1DecInteger encInt;
       
    62 	for (TInt i = 0; i < count; i++) 
       
    63 		{
       
    64 		TASN1DecGeneric* curr = seq->At(i);
       
    65 		
       
    66 		if (curr->Tag() == EASN1Integer)		
       
    67 			{
       
    68 			User::LeaveIfError(iIntArray.Append(encInt.DecodeDERShortL(*curr)));
       
    69 			}		
       
    70 		else
       
    71 			{
       
    72 			User::Leave(KErrArgument);		
       
    73 			}
       
    74 		}		
       
    75 	CleanupStack::PopAndDestroy(seq);
       
    76 	}
       
    77 	
       
    78 //CX509IntListExt::CX509IntListExt() 
       
    79 //	{
       
    80 //	}
       
    81 	
       
    82 // UTF-8 String list methods	
       
    83 EXPORT_C CX509Utf8StringListExt* CX509Utf8StringListExt::NewL(const TDesC8& aBinaryData)
       
    84 	{	
       
    85 	CX509Utf8StringListExt* self = CX509Utf8StringListExt::NewLC(aBinaryData);
       
    86 	CleanupStack::Pop(self);
       
    87 	return self;
       
    88 	}
       
    89 	
       
    90 EXPORT_C CX509Utf8StringListExt* CX509Utf8StringListExt::NewLC(const TDesC8& aBinaryData)
       
    91 	{
       
    92 	CX509Utf8StringListExt* self = new(ELeave) CX509Utf8StringListExt;
       
    93 	CleanupStack::PushL(self);
       
    94 	
       
    95 	TInt pos = 0;
       
    96 	self->ConstructL(aBinaryData, pos);
       
    97 	return self;
       
    98 	}
       
    99 
       
   100 EXPORT_C const RPointerArray<HBufC>& CX509Utf8StringListExt::StringArray() const
       
   101 	{
       
   102 	return iStringArray;
       
   103 	}	
       
   104 
       
   105 void CX509Utf8StringListExt::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
   106 	{
       
   107 	CX509ExtensionBase::ConstructL(aBinaryData, aPos);
       
   108 	}
       
   109 	
       
   110 void CX509Utf8StringListExt::DoConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
   111 	{
       
   112 	TASN1DecSequence encSeq;	
       
   113 	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos);
       
   114 	TInt count = seq->Count();
       
   115 	
       
   116 	TASN1DecUTF8String encStr;
       
   117 	for (TInt i = 0; i < count; i++) 
       
   118 		{
       
   119 		TASN1DecGeneric* curr = seq->At(i);
       
   120 		if (curr->Tag() == EASN1UTF8String)		
       
   121 			{
       
   122 			HBufC *str = encStr.DecodeDERL(*curr);
       
   123 			CleanupStack::PushL(str);
       
   124 			User::LeaveIfError(iStringArray.Append(str));
       
   125 			CleanupStack::Pop(str);
       
   126 			}		
       
   127 		else
       
   128 			{
       
   129 			User::Leave(KErrArgument);		
       
   130 			}
       
   131 		}		
       
   132 	CleanupStack::PopAndDestroy(seq);
       
   133 	}
       
   134 
       
   135 CX509Utf8StringListExt::~CX509Utf8StringListExt() 
       
   136 	{
       
   137 	iStringArray.ResetAndDestroy();
       
   138 	}
       
   139 	
       
   140 // Capability set methods
       
   141 EXPORT_C CX509CapabilitySetExt* CX509CapabilitySetExt::NewL(const TDesC8& aBinaryData) 
       
   142 	{
       
   143 	CX509CapabilitySetExt* self = CX509CapabilitySetExt::NewLC(aBinaryData);
       
   144 	CleanupStack::Pop(self);
       
   145 	return self;
       
   146 	}
       
   147 
       
   148 EXPORT_C CX509CapabilitySetExt* CX509CapabilitySetExt::NewLC(const TDesC8& aBinaryData) 
       
   149 	{
       
   150 	CX509CapabilitySetExt* self = new (ELeave) CX509CapabilitySetExt;
       
   151 	CleanupStack::PushL(self);
       
   152 	
       
   153 	TInt pos = 0;
       
   154 	self->ConstructL(aBinaryData, pos);
       
   155 	return self;
       
   156 	}
       
   157 
       
   158 CX509CapabilitySetExt::~CX509CapabilitySetExt() 
       
   159 	{	
       
   160 	}
       
   161 
       
   162 EXPORT_C const TCapabilitySet& CX509CapabilitySetExt::CapabilitySet() const
       
   163 	{
       
   164 	return iCapabilitySet;
       
   165 	}
       
   166 
       
   167 void CX509CapabilitySetExt::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
   168 	{
       
   169 	CX509ExtensionBase::ConstructL(aBinaryData, aPos);
       
   170 	}
       
   171 			
       
   172 void CX509CapabilitySetExt::DoConstructL(const TDesC8& aBinaryData, TInt& aPos) 
       
   173 	{
       
   174 	TASN1DecBitString encBit;	
       
   175 	
       
   176 	// Decode the padding bits
       
   177 	HBufC8* bitBuffer = encBit.ExtractOctetStringL(aBinaryData, aPos);
       
   178 	CleanupStack::PushL(bitBuffer);
       
   179 	
       
   180 	// Create bitString for easy access of individual bits.
       
   181 	// This transfers ownership of bitBuffer
       
   182 	CX509BitString* bitString = new (ELeave) CX509BitString(bitBuffer, bitBuffer->Length() * 8);	
       
   183 	CleanupStack::Pop(bitBuffer);
       
   184 	
       
   185 	// Start off with an empty capability set and attempt to add each capability in turn
       
   186 	// making sure we don't go past the limit of the supported capabilities.
       
   187 	iCapabilitySet.SetEmpty();
       
   188 	for (TInt i = 0; i < ECapability_Limit; i++) 
       
   189 		{
       
   190 		if (bitString->IsSet(i))		
       
   191 			{
       
   192 			iCapabilitySet.AddCapability(static_cast<TCapability>(i));		
       
   193 			}
       
   194 		}	
       
   195 	delete bitString;
       
   196 	}