os/security/cryptoservices/certificateandkeymgmt/x509/x509constraintext.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/x509/x509constraintext.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,197 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <asn1dec.h>
    1.23 +#include "x509constraintext.h"
    1.24 +#include "x509bitstring.h"
    1.25 +
    1.26 +// Integer list methods
    1.27 +EXPORT_C CX509IntListExt* CX509IntListExt::NewL(const TDesC8& aBinaryData)
    1.28 +	{	
    1.29 +	CX509IntListExt* self = CX509IntListExt::NewLC(aBinaryData);
    1.30 +	CleanupStack::Pop(self);
    1.31 +	return self;
    1.32 +	}
    1.33 +	
    1.34 +EXPORT_C CX509IntListExt* CX509IntListExt::NewLC(const TDesC8& aBinaryData)
    1.35 +	{
    1.36 +	CX509IntListExt* self = new(ELeave) CX509IntListExt;
    1.37 +	CleanupStack::PushL(self);
    1.38 +	
    1.39 +	TInt pos = 0;
    1.40 +	self->ConstructL(aBinaryData, pos);
    1.41 +	return self;
    1.42 +	}
    1.43 +
    1.44 +CX509IntListExt::~CX509IntListExt() 
    1.45 +	{
    1.46 +	iIntArray.Close();
    1.47 +	}
    1.48 +	
    1.49 +EXPORT_C const RArray<TInt>& CX509IntListExt::IntArray() const 
    1.50 +	{
    1.51 +	return iIntArray;	
    1.52 +	}		
    1.53 +
    1.54 +void CX509IntListExt::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
    1.55 +	{
    1.56 +	CX509ExtensionBase::ConstructL(aBinaryData, aPos);
    1.57 +	}
    1.58 +
    1.59 +void CX509IntListExt::DoConstructL(const TDesC8& aBinaryData, TInt& aPos)
    1.60 +	{
    1.61 +	TASN1DecSequence encSeq;	
    1.62 +	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos);
    1.63 +	TInt count = seq->Count();
    1.64 +	
    1.65 +	TASN1DecInteger encInt;
    1.66 +	for (TInt i = 0; i < count; i++) 
    1.67 +		{
    1.68 +		TASN1DecGeneric* curr = seq->At(i);
    1.69 +		
    1.70 +		if (curr->Tag() == EASN1Integer)		
    1.71 +			{
    1.72 +			User::LeaveIfError(iIntArray.Append(encInt.DecodeDERShortL(*curr)));
    1.73 +			}		
    1.74 +		else
    1.75 +			{
    1.76 +			User::Leave(KErrArgument);		
    1.77 +			}
    1.78 +		}		
    1.79 +	CleanupStack::PopAndDestroy(seq);
    1.80 +	}
    1.81 +	
    1.82 +//CX509IntListExt::CX509IntListExt() 
    1.83 +//	{
    1.84 +//	}
    1.85 +	
    1.86 +// UTF-8 String list methods	
    1.87 +EXPORT_C CX509Utf8StringListExt* CX509Utf8StringListExt::NewL(const TDesC8& aBinaryData)
    1.88 +	{	
    1.89 +	CX509Utf8StringListExt* self = CX509Utf8StringListExt::NewLC(aBinaryData);
    1.90 +	CleanupStack::Pop(self);
    1.91 +	return self;
    1.92 +	}
    1.93 +	
    1.94 +EXPORT_C CX509Utf8StringListExt* CX509Utf8StringListExt::NewLC(const TDesC8& aBinaryData)
    1.95 +	{
    1.96 +	CX509Utf8StringListExt* self = new(ELeave) CX509Utf8StringListExt;
    1.97 +	CleanupStack::PushL(self);
    1.98 +	
    1.99 +	TInt pos = 0;
   1.100 +	self->ConstructL(aBinaryData, pos);
   1.101 +	return self;
   1.102 +	}
   1.103 +
   1.104 +EXPORT_C const RPointerArray<HBufC>& CX509Utf8StringListExt::StringArray() const
   1.105 +	{
   1.106 +	return iStringArray;
   1.107 +	}	
   1.108 +
   1.109 +void CX509Utf8StringListExt::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
   1.110 +	{
   1.111 +	CX509ExtensionBase::ConstructL(aBinaryData, aPos);
   1.112 +	}
   1.113 +	
   1.114 +void CX509Utf8StringListExt::DoConstructL(const TDesC8& aBinaryData, TInt& aPos)
   1.115 +	{
   1.116 +	TASN1DecSequence encSeq;	
   1.117 +	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos);
   1.118 +	TInt count = seq->Count();
   1.119 +	
   1.120 +	TASN1DecUTF8String encStr;
   1.121 +	for (TInt i = 0; i < count; i++) 
   1.122 +		{
   1.123 +		TASN1DecGeneric* curr = seq->At(i);
   1.124 +		if (curr->Tag() == EASN1UTF8String)		
   1.125 +			{
   1.126 +			HBufC *str = encStr.DecodeDERL(*curr);
   1.127 +			CleanupStack::PushL(str);
   1.128 +			User::LeaveIfError(iStringArray.Append(str));
   1.129 +			CleanupStack::Pop(str);
   1.130 +			}		
   1.131 +		else
   1.132 +			{
   1.133 +			User::Leave(KErrArgument);		
   1.134 +			}
   1.135 +		}		
   1.136 +	CleanupStack::PopAndDestroy(seq);
   1.137 +	}
   1.138 +
   1.139 +CX509Utf8StringListExt::~CX509Utf8StringListExt() 
   1.140 +	{
   1.141 +	iStringArray.ResetAndDestroy();
   1.142 +	}
   1.143 +	
   1.144 +// Capability set methods
   1.145 +EXPORT_C CX509CapabilitySetExt* CX509CapabilitySetExt::NewL(const TDesC8& aBinaryData) 
   1.146 +	{
   1.147 +	CX509CapabilitySetExt* self = CX509CapabilitySetExt::NewLC(aBinaryData);
   1.148 +	CleanupStack::Pop(self);
   1.149 +	return self;
   1.150 +	}
   1.151 +
   1.152 +EXPORT_C CX509CapabilitySetExt* CX509CapabilitySetExt::NewLC(const TDesC8& aBinaryData) 
   1.153 +	{
   1.154 +	CX509CapabilitySetExt* self = new (ELeave) CX509CapabilitySetExt;
   1.155 +	CleanupStack::PushL(self);
   1.156 +	
   1.157 +	TInt pos = 0;
   1.158 +	self->ConstructL(aBinaryData, pos);
   1.159 +	return self;
   1.160 +	}
   1.161 +
   1.162 +CX509CapabilitySetExt::~CX509CapabilitySetExt() 
   1.163 +	{	
   1.164 +	}
   1.165 +
   1.166 +EXPORT_C const TCapabilitySet& CX509CapabilitySetExt::CapabilitySet() const
   1.167 +	{
   1.168 +	return iCapabilitySet;
   1.169 +	}
   1.170 +
   1.171 +void CX509CapabilitySetExt::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
   1.172 +	{
   1.173 +	CX509ExtensionBase::ConstructL(aBinaryData, aPos);
   1.174 +	}
   1.175 +			
   1.176 +void CX509CapabilitySetExt::DoConstructL(const TDesC8& aBinaryData, TInt& aPos) 
   1.177 +	{
   1.178 +	TASN1DecBitString encBit;	
   1.179 +	
   1.180 +	// Decode the padding bits
   1.181 +	HBufC8* bitBuffer = encBit.ExtractOctetStringL(aBinaryData, aPos);
   1.182 +	CleanupStack::PushL(bitBuffer);
   1.183 +	
   1.184 +	// Create bitString for easy access of individual bits.
   1.185 +	// This transfers ownership of bitBuffer
   1.186 +	CX509BitString* bitString = new (ELeave) CX509BitString(bitBuffer, bitBuffer->Length() * 8);	
   1.187 +	CleanupStack::Pop(bitBuffer);
   1.188 +	
   1.189 +	// Start off with an empty capability set and attempt to add each capability in turn
   1.190 +	// making sure we don't go past the limit of the supported capabilities.
   1.191 +	iCapabilitySet.SetEmpty();
   1.192 +	for (TInt i = 0; i < ECapability_Limit; i++) 
   1.193 +		{
   1.194 +		if (bitString->IsSet(i))		
   1.195 +			{
   1.196 +			iCapabilitySet.AddCapability(static_cast<TCapability>(i));		
   1.197 +			}
   1.198 +		}	
   1.199 +	delete bitString;
   1.200 +	}