First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * X.509 key classes and utility classes for key encoding/decoding.
25 #if !defined (X509KEYENCODER_H)
26 #define X509KEYENCODER_H
30 #include <asymmetrickeys.h>
31 #include <asymmetric.h>
36 // Forward declarations
38 class CASN1EncContainer;
39 class CASN1EncSequence;
40 class CASN1EncBitString;
44 * Abstract class that is the base class for RSA and DSA key encoder classes.
45 * These classes are used to encode the X509 ASN.1 types AlgorithmIdentifier and
46 * SubjectPublicKeyInfo.
48 * This class is part of the pkcs10 API, and will be changed or removed in a
49 * future release. You should not use it.
55 * Constructor that takes an algorithm identifier and saves it into the
56 * corresponding member variable. It is then used in the
57 * EncodeSignatureAlgorithm() function.
59 * @param aDigestAlg Digest algorithm to use. Currently the following
60 * algorithms are supported: MD2, MD5, and SHA-1.
62 TX509KeyEncoder(TAlgorithmId aDigestAlg);
65 * Produces the SubjectPublicKeyInfo encoding.
67 * The encoding has the following ASN.1 format:
69 * SubjectPublicKeyInfo {ALGORITHM : IOSet} ::= SEQUENCE {
70 * algorithm AlgorithmIdentifier {{IOSet}},
71 * subjectPublicKey BIT STRING
75 IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const = 0;
78 * Produces the AlgorithmIdentifier encoding.
80 * @return ASN.1 sequence containing signature algorithm
82 IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const = 0;
85 * Produces the DigestAlgorithmIdentifier encoder.
87 * The encoding has the following ASN.1 format
89 * DigestAlgorithmIdentifier ::= SEQUENCE {
90 * algorithm AlgorithmIdentifier,
91 * parameters ANY DEFINED BY algorithm OPTIONAL }
93 * AlgorithmIdentifier ::= OBJECT IDENTIFIER
96 * @return Appropriate ASN.1 sequence of type <code>DigestAlgorithmIdentifier</code>
98 IMPORT_C virtual CASN1EncSequence* EncodeDigestAlgorithmLC() const;
101 /** Digest algorithm to use. */
102 TAlgorithmId iDigestAlg;
105 class TX509RSAKeyEncoder : public TX509KeyEncoder
107 * Subclasses TC509KeyEncoder to provides key encoding capability for RSA public keys.
109 * This class is part of the pkcs10 API, and will be changed or removed in a
110 * future release. You should not use it.
116 * Constructs a RSA key pair encoder, saving reference to the passed
117 * key pair in the member variable.
119 * @param aPublicKey RSA public key to use for encoding.
120 * @param aDigestAlg Digest algorithm to use.
122 IMPORT_C TX509RSAKeyEncoder(const CRSAPublicKey& aPublicKey, TAlgorithmId aDigestAlg);
125 * Produces the SubjectPublicKeyInfo encoding.
127 * The resulting encoding has the following form:
131 * OID of the encryption algorithm (KRSA)
133 * BIT STRING encoded public key.
136 * @return DER-encoded public key information, placed on the cleanup stack.
138 IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const;
141 * Produces the AlgorithmIdentifier encoding.
143 * This has the following form:
146 * OID signature-algorithm
150 * @return ASN.1 sequence containing signature algorithm encoding,
151 * placed on the cleanup stack.
153 IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const;
157 * Saved reference to the RSA public key to be used for encoding.
159 const CRSAPublicKey& iPublicKey;
162 class TX509DSAKeyEncoder : public TX509KeyEncoder
164 * Provides key encoding and signing capability using a DSA public key.
166 * This class is part of the pkcs10 API, and will be changed or removed in a
167 * future release. You should not use it.
173 * Constructs a DSA key pair encoder, saving reference to the passed
174 * public key in the member variable.
176 * @param aKeyPublic DSA public key to use for encoding.
177 * @param aDigestAlg Digest algorithm to use.
179 IMPORT_C TX509DSAKeyEncoder(const CDSAPublicKey& aKeyPublic,
180 TAlgorithmId aDigestAlg);
183 * Produces the SubjectPublicKeyInfo encoding.
185 * The ASN.1 encoding of a DSA key has the following form:
189 * OID dsa (1.2.840.10040.4.1)
195 * INTEGER public value (y)
198 * @return DER-encoded public key information, placed on the cleanup stack.
200 IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const;
203 * Produces the AlgorithmIdentifier encoding.
205 * This has the following form:
208 * OID dsa-signature-oid
209 * SEQUENCE-OF dsa-params
215 * @return ASN.1 sequence containing signature algorithm encoding,
216 * placed on the cleanup stack.
218 IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const;
222 * Saved reference to the DSA public key to be used for encoding.
224 const CDSAPublicKey& iPublicKey;