os/security/cryptoservices/certificateandkeymgmt/asn1/encenc.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) 2005-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
/**
sl@0
    20
 @file
sl@0
    21
*/
sl@0
    22
sl@0
    23
#include <e32std.h>
sl@0
    24
#include <e32def.h>
sl@0
    25
#include <asn1enc.h>
sl@0
    26
#include <asn1dec.h>
sl@0
    27
sl@0
    28
EXPORT_C CASN1EncEncoding::~CASN1EncEncoding()
sl@0
    29
	{
sl@0
    30
	delete iContents;
sl@0
    31
	}
sl@0
    32
sl@0
    33
// Set arbitrary initial values for tag type and class because they will be 
sl@0
    34
// inited in ConstructL().
sl@0
    35
EXPORT_C CASN1EncEncoding::CASN1EncEncoding() : 
sl@0
    36
	CASN1EncBase(EASN1EOC, EUniversal)
sl@0
    37
	{
sl@0
    38
	}
sl@0
    39
sl@0
    40
EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewLC(const TDesC8& aEncoding)
sl@0
    41
	{
sl@0
    42
	CASN1EncEncoding* self = new (ELeave) CASN1EncEncoding;
sl@0
    43
	CleanupStack::PushL(self);
sl@0
    44
	self->ConstructL(aEncoding);
sl@0
    45
	return self;
sl@0
    46
	}
sl@0
    47
sl@0
    48
EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewL(const TDesC8& aEncoding)
sl@0
    49
	{
sl@0
    50
	CASN1EncEncoding* self = NewLC(aEncoding);
sl@0
    51
	CleanupStack::Pop(self);
sl@0
    52
	return self;
sl@0
    53
	}
sl@0
    54
sl@0
    55
EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewLC(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass)
sl@0
    56
	{
sl@0
    57
	CASN1EncEncoding* self = new (ELeave) CASN1EncEncoding;
sl@0
    58
	CleanupStack::PushL(self);
sl@0
    59
	self->ConstructL(aEncoding, aType, aClass);
sl@0
    60
	return self;		
sl@0
    61
	}
sl@0
    62
sl@0
    63
void CASN1EncEncoding::ConstructL(const TDesC8& aEncoding)
sl@0
    64
	{
sl@0
    65
	// Use decoder to get information about the outer wrapper of the passed 
sl@0
    66
	// encoding.
sl@0
    67
	TASN1DecGeneric decoder(aEncoding);
sl@0
    68
	decoder.InitL();
sl@0
    69
	iClass = decoder.Class();
sl@0
    70
	iTag = decoder.Tag();
sl@0
    71
	// Set this information so that the base class knows how to write 
sl@0
    72
	// DER encoding.
sl@0
    73
	SetTag(iTag, iClass);
sl@0
    74
	// Copy just the contents of the passed encoding.
sl@0
    75
	iContents = decoder.GetContentDER().AllocL();
sl@0
    76
	// Save this for base class writing functions.
sl@0
    77
	iContentsLengthDER = iContents->Length();
sl@0
    78
	// This is base class' method which initializes length of length 
sl@0
    79
	// encoding for proper DER writing.
sl@0
    80
	CalculateLengthLengthDER();
sl@0
    81
	}
sl@0
    82
sl@0
    83
void CASN1EncEncoding::ConstructL(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass)
sl@0
    84
	{
sl@0
    85
	// Use decoder to get information about the outer wrapper of the passed 
sl@0
    86
	// encoding.
sl@0
    87
	TASN1DecGeneric decoder(aEncoding);
sl@0
    88
	decoder.InitL();
sl@0
    89
	iClass = aClass;
sl@0
    90
	iTag = aType;
sl@0
    91
	// Set this information so that the base class knows how to write 
sl@0
    92
	// DER encoding.
sl@0
    93
	SetTag(aType, aClass);
sl@0
    94
	// Copy just the contents of the passed encoding.
sl@0
    95
	iContents = decoder.GetContentDER().AllocL();
sl@0
    96
	// Save this for base class writing functions.
sl@0
    97
	iContentsLengthDER = iContents->Length();
sl@0
    98
	// This is base class' method which initializes length of length 
sl@0
    99
	// encoding for proper DER writing.
sl@0
   100
	CalculateLengthLengthDER();
sl@0
   101
	}
sl@0
   102
sl@0
   103
sl@0
   104
// This method is not called but is necessary because it overrides a 
sl@0
   105
// pure virtual function of the base class. The variable is properly 
sl@0
   106
// initialized in ConstructL().
sl@0
   107
void CASN1EncEncoding::CalculateContentsLengthDER()
sl@0
   108
	{
sl@0
   109
	iContentsLengthDER = iContents->Length();
sl@0
   110
	}
sl@0
   111
sl@0
   112
TBool CASN1EncEncoding::IsConstructed() const
sl@0
   113
	{
sl@0
   114
	return ETrue;
sl@0
   115
	}
sl@0
   116
sl@0
   117
// When this method is called by the base class write helper, the tag 
sl@0
   118
// and length are already written.
sl@0
   119
void CASN1EncEncoding::WriteContentsDERL(TDes8& aBuf) const
sl@0
   120
	{
sl@0
   121
	aBuf.Copy(*iContents);
sl@0
   122
	}