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