1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/pkcs7/pkcs7digestinfo.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,107 @@
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 "pkcs7digestinfo.h"
1.23 +#include "pkcs7asn1.h"
1.24 +
1.25 +EXPORT_C CPKCS7DigestInfo* CPKCS7DigestInfo::NewL(const TDesC8& aRawData)
1.26 + {
1.27 + CPKCS7DigestInfo* self = new (ELeave) CPKCS7DigestInfo();
1.28 + CleanupStack::PushL(self);
1.29 + self->ConstructL(aRawData);
1.30 + CleanupStack::Pop(self);
1.31 + return self;
1.32 + }
1.33 +
1.34 +CPKCS7DigestInfo::~CPKCS7DigestInfo()
1.35 + {
1.36 + }
1.37 +
1.38 +CPKCS7DigestInfo::CPKCS7DigestInfo()
1.39 + {
1.40 + }
1.41 +
1.42 +EXPORT_C const TDesC8& CPKCS7DigestInfo::Digest() const
1.43 + {
1.44 + return iDigest;
1.45 + }
1.46 +
1.47 +EXPORT_C TAlgorithmId CPKCS7DigestInfo::Algorithm() const
1.48 + {
1.49 + return iAlgorithmId;
1.50 + }
1.51 +
1.52 +EXPORT_C const TPtrC8& CPKCS7DigestInfo::EncodedParams() const
1.53 + {
1.54 + return iEncodedParams;
1.55 + }
1.56 +
1.57 +void CPKCS7DigestInfo::ConstructL(const TDesC8& aDigestData)
1.58 + {
1.59 + CArrayPtr<TASN1DecGeneric>* digestInfo = PKCS7ASN1::DecodeSequenceLC(aDigestData);
1.60 +
1.61 + // Check if both the digestAlgorithm and the Digest are present.
1.62 + if ( digestInfo->Count() != 2 )
1.63 + {
1.64 + User::Leave(KErrArgument);
1.65 + }
1.66 +
1.67 + // DIGEST ALGORITHM
1.68 + // Get the algorithm identifier and the encoded parameters present in the sequence.
1.69 + const TASN1DecGeneric* digestInfoAt0 = digestInfo->At(0);
1.70 + if(digestInfoAt0->Tag() != EASN1Sequence || digestInfoAt0->Class() != EUniversal)
1.71 + {
1.72 + User::Leave(KErrArgument);
1.73 + }
1.74 + CX509AlgorithmIdentifier* digestAlg = CX509AlgorithmIdentifier::NewLC(digestInfo->At(0)->Encoding());
1.75 + TAlgorithmId algorithmId = digestAlg->Algorithm();
1.76 + switch(algorithmId)
1.77 + {
1.78 + case EMD2:
1.79 + {
1.80 + iAlgorithmId = EMD2;
1.81 + }
1.82 + break;
1.83 + case EMD5:
1.84 + {
1.85 + iAlgorithmId = EMD5;
1.86 + }
1.87 + break;
1.88 + case ESHA1:
1.89 + {
1.90 + iAlgorithmId = ESHA1;
1.91 + }
1.92 + break;
1.93 + default:
1.94 + User::Leave(KErrNotSupported);
1.95 + }
1.96 +
1.97 + iEncodedParams.Set(digestAlg->EncodedParams());
1.98 +
1.99 + // DIGEST
1.100 + const TASN1DecGeneric* digestInfoAt1 = digestInfo->At(1);
1.101 + if(digestInfoAt1->Tag() != EASN1OctetString || digestInfoAt1->Class() != EUniversal)
1.102 + {
1.103 + User::Leave(KErrArgument);
1.104 + }
1.105 + TASN1DecGeneric octetStringDecoder(*(digestInfo->At(1)));
1.106 + octetStringDecoder.InitL();
1.107 + iDigest.Set(octetStringDecoder.GetContentDER());
1.108 +
1.109 + CleanupStack::PopAndDestroy(2,digestInfo);// digestInfo, digestAlg
1.110 + }