os/security/cryptomgmtlibs/cryptotokenfw/source/ctframework/KeyUsage.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/cryptotokenfw/source/ctframework/KeyUsage.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,137 @@
     1.4 +/*
     1.5 +* Copyright (c) 2001-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 "securitydefs.h"
    1.23 +
    1.24 +////////////////////////////////////////////////////////////////////////////////
    1.25 +// TKeyUsagePKCS15 & TKeyUsageX509
    1.26 +////////////////////////////////////////////////////////////////////////////////
    1.27 +
    1.28 +//	x509									PKCS15 Public	PKCS15 Private
    1.29 +
    1.30 +//	DataEncipherment						Encrypt			Decrypt
    1.31 +//	DigitalSignature, keyCertSign, cRLSign	Verify			Sign
    1.32 +//	DigitalSignature, keyCertSign, cRLSign	VerifyRecover	SignRecover
    1.33 +//	KeyAgreement							Derive			Derive
    1.34 +//	KeyEncipherment							Wrap			Unwrap
    1.35 +//	NonRepudiation							NonRepudiation	NonRepudiation
    1.36 +
    1.37 +EXPORT_C TKeyUsagePKCS15 KeyUsageX509ToPKCS15Private(TKeyUsageX509 aUsage)
    1.38 +	{
    1.39 +	TKeyUsagePKCS15 result = EPKCS15UsageNone;
    1.40 +
    1.41 +	if (EX509UsageAll == aUsage)
    1.42 +		{
    1.43 +		result = EPKCS15UsageAll;
    1.44 +		}
    1.45 +	else
    1.46 +		{
    1.47 +		if (aUsage & EX509UsageDataEncipherment)
    1.48 +			{
    1.49 +			result |= EPKCS15UsageDecrypt;
    1.50 +			}
    1.51 +		if (aUsage & (EX509UsageDigitalSignature | EX509UsageKeyCertSign | EX509UsageCRLSign))
    1.52 +			{
    1.53 +			result |= EPKCS15UsageSign | EPKCS15UsageSignRecover;
    1.54 +			}
    1.55 +		if (aUsage & EX509UsageKeyAgreement)
    1.56 +			{
    1.57 +			result |= EPKCS15UsageDerive;
    1.58 +			}
    1.59 +		if (aUsage & EX509UsageKeyEncipherment)
    1.60 +			{
    1.61 +			result |= EPKCS15UsageUnwrap;
    1.62 +			}
    1.63 +		if (aUsage & EX509UsageNonRepudiation)
    1.64 +			{//	This shouldn't really happen, ENonRepudiation should be sole usage
    1.65 +			result |= EPKCS15UsageNonRepudiation;
    1.66 +			}
    1.67 +		}
    1.68 +	
    1.69 +	return result;
    1.70 +	}
    1.71 +
    1.72 +EXPORT_C TKeyUsagePKCS15 KeyUsageX509ToPKCS15Public(TKeyUsageX509 aUsage)
    1.73 +	{
    1.74 +	TKeyUsagePKCS15 result = EPKCS15UsageNone;
    1.75 +
    1.76 +	if (EX509UsageAll == aUsage)
    1.77 +		{
    1.78 +		result = EPKCS15UsageAll;
    1.79 +		}
    1.80 +	else
    1.81 +		{
    1.82 +		if (aUsage & EX509UsageDataEncipherment)
    1.83 +			{
    1.84 +			result |= EPKCS15UsageEncrypt;
    1.85 +			}
    1.86 +		if (aUsage & (EX509UsageDigitalSignature | EX509UsageKeyCertSign | EX509UsageCRLSign))
    1.87 +			{
    1.88 +			result |= EPKCS15UsageVerify | EPKCS15UsageVerifyRecover;
    1.89 +			}
    1.90 +		if (aUsage & EX509UsageKeyAgreement)
    1.91 +			{
    1.92 +			result |= EPKCS15UsageDerive;
    1.93 +			}
    1.94 +		if (aUsage & EX509UsageKeyEncipherment)
    1.95 +			{
    1.96 +			result |= EPKCS15UsageWrap;
    1.97 +			}
    1.98 +		if (aUsage & EX509UsageNonRepudiation)
    1.99 +			{//	This shouldn't really happen, ENonRepudiation should be sole usage
   1.100 +			result |= EPKCS15UsageNonRepudiation;
   1.101 +			}
   1.102 +		}
   1.103 +	
   1.104 +	return result;
   1.105 +	}
   1.106 +
   1.107 +EXPORT_C TKeyUsageX509 KeyUsagePKCS15ToX509(TKeyUsagePKCS15 aUsage)
   1.108 +	{
   1.109 +	TKeyUsageX509 result = EX509UsageNone;
   1.110 +
   1.111 +	if (EPKCS15UsageAll == aUsage)
   1.112 +		{
   1.113 +		result = EX509UsageAll;
   1.114 +		}
   1.115 +	else
   1.116 +		{
   1.117 +		if (aUsage & (EPKCS15UsageEncrypt | EPKCS15UsageDecrypt))
   1.118 +			{
   1.119 +			result |= EX509UsageDataEncipherment;
   1.120 +			}
   1.121 +		if (aUsage & (EPKCS15UsageVerify | EPKCS15UsageSign | EPKCS15UsageVerifyRecover | EPKCS15UsageSignRecover))
   1.122 +			{
   1.123 +			result |= EX509UsageDigitalSignature | EX509UsageKeyCertSign | EX509UsageCRLSign;
   1.124 +			}
   1.125 +		if (aUsage & EPKCS15UsageDerive)
   1.126 +			{
   1.127 +			result |= EX509UsageKeyAgreement;
   1.128 +			}
   1.129 +		if (aUsage & (EPKCS15UsageWrap | EPKCS15UsageUnwrap))
   1.130 +			{
   1.131 +			result |= EX509UsageKeyEncipherment;
   1.132 +			}
   1.133 +		if (aUsage & EPKCS15UsageNonRepudiation)
   1.134 +			{
   1.135 +			result |= EX509UsageNonRepudiation;
   1.136 +			}
   1.137 +		}
   1.138 +	
   1.139 +	return result;
   1.140 +	}