1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/pkcs10/pkcs9attr.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,134 @@
1.4 +/*
1.5 +* Copyright (c) 2007-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 +* CPKCS9ChallengePasswordAttr and CPKCS9ExtensionRequestAttr class implementation.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +#include <e32std.h>
1.24 +#include <e32def.h>
1.25 +#include <asn1enc.h>
1.26 +#include <pkcs9attr.h>
1.27 +
1.28 +// CPKCS9ChallengePasswordAttr ////////////////////////////////////////////////////////////
1.29 +
1.30 +EXPORT_C CPKCS9ChallengePasswordAttr* CPKCS9ChallengePasswordAttr::NewLC(const TDesC8& aPassword)
1.31 + {
1.32 + CPKCS9ChallengePasswordAttr* self = new (ELeave) CPKCS9ChallengePasswordAttr;
1.33 + CleanupStack::PushL(self);
1.34 + self->ConstructL(aPassword);
1.35 + return self;
1.36 + }
1.37 +
1.38 +EXPORT_C CPKCS9ChallengePasswordAttr* CPKCS9ChallengePasswordAttr::NewL(const TDesC8& aPassword)
1.39 + {
1.40 + CPKCS9ChallengePasswordAttr* self = NewLC(aPassword);
1.41 + CleanupStack::Pop(self);
1.42 + return self;
1.43 + }
1.44 +
1.45 +EXPORT_C void CPKCS9ChallengePasswordAttr::ResetL(const TDesC8& aPassword)
1.46 + {
1.47 + delete iRoot;
1.48 + iRoot = NULL;
1.49 + ConstructL(aPassword);
1.50 + }
1.51 +
1.52 +CPKCS9ChallengePasswordAttr::CPKCS9ChallengePasswordAttr()
1.53 + {
1.54 + }
1.55 +
1.56 +CPKCS9ChallengePasswordAttr::~CPKCS9ChallengePasswordAttr()
1.57 + {
1.58 + }
1.59 +
1.60 +CASN1EncBase* CPKCS9ChallengePasswordAttr::GetEncodingLC()
1.61 + {
1.62 + return CPKCSAttributeBase::GetEncodingLC();
1.63 + }
1.64 +
1.65 +void CPKCS9ChallengePasswordAttr::ConstructL(const TDesC8& aPassword)
1.66 + {
1.67 + // Size of password string should be between bounds
1.68 + if ((aPassword.Length() < KPkcs9StringLB) || (aPassword.Length() > KPkcs9StringUB))
1.69 + {
1.70 + User::Leave(KErrArgument);
1.71 + }
1.72 +
1.73 + iRoot = CASN1EncSequence::NewL();
1.74 + CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(KPkcs9ChallengePasswordAttrOID);
1.75 + iRoot->AddAndPopChildL(oid);
1.76 + iValueSet = CASN1EncSet::NewLC();
1.77 + iRoot->AddAndPopChildL(iValueSet); // Takes ownership
1.78 + CASN1EncPrintableString* value = CASN1EncPrintableString::NewLC(aPassword);
1.79 + iValueSet->AddAndPopChildL(value);
1.80 + }
1.81 +
1.82 +// CPKCS9ExtensionRequestAttr ////////////////////////////////////////////////////////////
1.83 +
1.84 +EXPORT_C CPKCS9ExtensionRequestAttr* CPKCS9ExtensionRequestAttr::NewLC(const CX509CertExtension& aExtension)
1.85 + {
1.86 + CPKCS9ExtensionRequestAttr* self = new (ELeave) CPKCS9ExtensionRequestAttr;
1.87 + CleanupStack::PushL(self);
1.88 + self->ConstructL(aExtension);
1.89 + return self;
1.90 + }
1.91 +
1.92 +EXPORT_C CPKCS9ExtensionRequestAttr* CPKCS9ExtensionRequestAttr::NewL(const CX509CertExtension& aExtension)
1.93 + {
1.94 + CPKCS9ExtensionRequestAttr* self = NewLC(aExtension);
1.95 + CleanupStack::Pop(self);
1.96 + return self;
1.97 + }
1.98 +
1.99 +EXPORT_C void CPKCS9ExtensionRequestAttr::AddExtensionL(const CX509CertExtension& aExtension)
1.100 + {
1.101 + CASN1EncSequence *extension = aExtension.EncodeASN1DERLC();
1.102 + iExtSeq->AddAndPopChildL(extension);
1.103 + }
1.104 +
1.105 +EXPORT_C void CPKCS9ExtensionRequestAttr::ResetL(const CX509CertExtension& aExtension)
1.106 + {
1.107 + delete iRoot;
1.108 + iRoot = NULL;
1.109 + ConstructL(aExtension);
1.110 + }
1.111 +
1.112 +CPKCS9ExtensionRequestAttr::CPKCS9ExtensionRequestAttr()
1.113 + {
1.114 + }
1.115 +
1.116 +CPKCS9ExtensionRequestAttr::~CPKCS9ExtensionRequestAttr()
1.117 + {
1.118 + }
1.119 +
1.120 +CASN1EncBase* CPKCS9ExtensionRequestAttr::GetEncodingLC()
1.121 + {
1.122 + return CPKCSAttributeBase::GetEncodingLC();
1.123 + }
1.124 +
1.125 +void CPKCS9ExtensionRequestAttr::ConstructL(const CX509CertExtension& aExtension)
1.126 + {
1.127 + iRoot = CASN1EncSequence::NewL();
1.128 + CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(KPkcs9ExtensionRequestAttrOID);
1.129 + iRoot->AddAndPopChildL(oid);
1.130 + iValueSet = CASN1EncSet::NewLC();
1.131 + iRoot->AddAndPopChildL(iValueSet); // Takes ownership
1.132 + iExtSeq = CASN1EncSequence::NewLC();
1.133 + iValueSet->AddAndPopChildL(iExtSeq);
1.134 + CASN1EncSequence *extension = aExtension.EncodeASN1DERLC();
1.135 + iExtSeq->AddAndPopChildL(extension);
1.136 + }
1.137 +