1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/asn1/setdec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,110 @@
1.4 +/*
1.5 +* Copyright (c) 1998-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 +* This file contains the implementation of the ASN1 Set and Set-of object,
1.19 +* as described in X208 Sections 22 and 23 and X209 Sections 16 and 17. The
1.20 +* set object can contain an ordered series of zero, one or more other ASN1
1.21 +* objects. The set-of object contains zero, one or more of the objects
1.22 +* described in its definition. The data encodings of both these objects is
1.23 +* identical. The ordering of the elements contained within set objects is not
1.24 +* significant.
1.25 +* The implementation of sets is pretty much the same as that for sequences
1.26 +* (indeed it has started from a straight cut'n'paste) but there are some
1.27 +* significant differences with regard to ordering of items within the set,
1.28 +* comparison and retrieval of items.
1.29 +*
1.30 +*/
1.31 +
1.32 +
1.33 +#include "asn1dec.h"
1.34 +
1.35 +void TASN1DecSet::CleanupSet(TAny* aArray)
1.36 + {
1.37 + CArrayPtrFlat<TASN1DecGeneric>* array = REINTERPRET_CAST(CArrayPtrFlat<TASN1DecGeneric>*, aArray);
1.38 + array->ResetAndDestroy();
1.39 + delete array;
1.40 + }
1.41 +
1.42 +EXPORT_C TASN1DecSet::TASN1DecSet()
1.43 + {
1.44 + }
1.45 +
1.46 +
1.47 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::NewDERLC(const TDesC8& aSource)
1.48 +// this whole things needs looking at!
1.49 + {
1.50 + TInt Pos=0;
1.51 + CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
1.52 + TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret);
1.53 + CleanupStack::PushL(cleanupSeq);
1.54 + TASN1DecGeneric gen(aSource);
1.55 + gen.InitL();
1.56 + DecodeContentsL(gen.GetContentDER(), Pos, *ret);
1.57 + return ret;
1.58 + }
1.59 +
1.60 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos)
1.61 +
1.62 + {
1.63 + TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos);
1.64 + return TASN1DecSet::NewDERLC(Ptr);
1.65 + }
1.66 +
1.67 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource)
1.68 + {
1.69 + TInt pos = 0;
1.70 + CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
1.71 + TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret);
1.72 + CleanupStack::PushL(cleanupSeq);
1.73 + DecodeContentsL(aSource.GetContentDER(), pos, *ret);
1.74 + return ret;
1.75 + }
1.76 +
1.77 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax)
1.78 +
1.79 + {
1.80 + CArrayPtrFlat<TASN1DecGeneric>* res = DecodeDERLC(aSource, aPos);
1.81 + TInt count = res->Count();
1.82 + if ((count < aMin) || (count > aMax))
1.83 + {
1.84 + User::Leave(KErrArgument);
1.85 + }
1.86 + return res;
1.87 + }
1.88 +
1.89 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax)
1.90 + {
1.91 + CArrayPtrFlat<TASN1DecGeneric>* res = DecodeDERLC(aSource);
1.92 + TInt count = res->Count();
1.93 + if ((count < aMin) || (count > aMax))
1.94 + {
1.95 + User::Leave(KErrArgument);
1.96 + }
1.97 + return res;
1.98 + }
1.99 +
1.100 +void TASN1DecSet::DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat<TASN1DecGeneric>& aDest)
1.101 + {
1.102 + while (aPos < aSource.Length())
1.103 + {
1.104 + TPtrC8 Ptr=aSource.Right(aSource.Length() - aPos);
1.105 + TASN1DecGeneric* Decoded = new(ELeave) TASN1DecGeneric(Ptr);
1.106 + CleanupStack::PushL(Decoded);
1.107 + Decoded->InitL();
1.108 + aDest.AppendL(Decoded);
1.109 + aPos+=Decoded->LengthDER();
1.110 + CleanupStack::Pop();//i think this should be just 'pop': need to find out
1.111 + }
1.112 + }
1.113 +