os/security/cryptoservices/asnpkcs/test/tactiondecodepkcs5.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "tactiondecodepkcs5.h"
sl@0
    20
#include "t_input.h"
sl@0
    21
#include <asnpkcs.h>
sl@0
    22
#include <pbedata.h>
sl@0
    23
#include <pbe.h>
sl@0
    24
#include <asn1enc.h>
sl@0
    25
sl@0
    26
_LIT8(KInputStart, "<input>");
sl@0
    27
sl@0
    28
sl@0
    29
CTestAction* CActionDecodePKCS5::NewL(RFs& aFs,
sl@0
    30
									   CConsoleBase& aConsole,
sl@0
    31
									   Output& aOut, 
sl@0
    32
									   const TTestActionSpec& aTestActionSpec)
sl@0
    33
	{
sl@0
    34
	CActionDecodePKCS5* self = new(ELeave) CActionDecodePKCS5(aFs, aConsole, aOut);
sl@0
    35
	CleanupStack::PushL(self);
sl@0
    36
	self->ConstructL(aTestActionSpec);
sl@0
    37
	CleanupStack::Pop();
sl@0
    38
	return self;
sl@0
    39
	}
sl@0
    40
sl@0
    41
CActionDecodePKCS5::~CActionDecodePKCS5()
sl@0
    42
	{
sl@0
    43
	delete iInput;
sl@0
    44
	delete iOutput;
sl@0
    45
	}
sl@0
    46
sl@0
    47
CActionDecodePKCS5::CActionDecodePKCS5(RFs& aFs, 
sl@0
    48
								 CConsoleBase& aConsole,
sl@0
    49
								 Output& aOut)
sl@0
    50
								 
sl@0
    51
: CTestAction(aConsole, aOut), iFs(aFs)
sl@0
    52
	{
sl@0
    53
	}
sl@0
    54
sl@0
    55
void CActionDecodePKCS5::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0
    56
	{
sl@0
    57
	CTestAction::ConstructL(aTestActionSpec);
sl@0
    58
sl@0
    59
	iInput = Input::ParseElementHexL(aTestActionSpec.iActionBody, KInputStart);
sl@0
    60
	iOutput = HBufC8::NewL(iInput->Length()+100); //so we detect errors in
sl@0
    61
	//encoding not panics in descriptors
sl@0
    62
	}
sl@0
    63
sl@0
    64
void CActionDecodePKCS5::DoReportAction(void)
sl@0
    65
	{
sl@0
    66
	}
sl@0
    67
sl@0
    68
void CActionDecodePKCS5::DoCheckResult(TInt)
sl@0
    69
	{
sl@0
    70
	}
sl@0
    71
sl@0
    72
void CActionDecodePKCS5::PerformAction(TRequestStatus& aStatus)
sl@0
    73
	{
sl@0
    74
	TRequestStatus* status = &aStatus;
sl@0
    75
	iResult = EFalse;
sl@0
    76
	
sl@0
    77
	CPBEncryptParms* parms = TASN1DecPKCS5::DecodeDERL(*iInput);
sl@0
    78
	CleanupStack::PushL(parms);
sl@0
    79
	CASN1EncSequence* seq = TASN1EncPKCS5::EncodeDERL(*parms);
sl@0
    80
	CleanupStack::PushL(seq);
sl@0
    81
sl@0
    82
	iOutput->Des().SetLength(seq->LengthDER());
sl@0
    83
	TUint length=0;
sl@0
    84
	TPtr8 iOutputTemp = iOutput->Des();
sl@0
    85
	seq->WriteDERL(iOutputTemp, length);
sl@0
    86
sl@0
    87
	if(*iOutput == *iInput)
sl@0
    88
		{
sl@0
    89
		iResult = ETrue;
sl@0
    90
		}
sl@0
    91
sl@0
    92
	CleanupStack::PopAndDestroy(2); //seq, parms
sl@0
    93
	User::RequestComplete(status, KErrNone);
sl@0
    94
	iActionState = CTestAction::EPostrequisite;
sl@0
    95
	}