~zooko/cryptopp/trunk

« back to all changes in this revision

Viewing changes to asn.h

  • Committer: weidai
  • Date: 2006-12-09 17:18:13 UTC
  • Revision ID: svn-v4:57ff6487-cd31-0410-9ec3-f628ee90f5f0:trunk/c5:247
add Salsa20 cipher

Show diffs side-by-side

added added

removed removed

Lines of Context:
230
230
        }
231
231
};
232
232
 
233
 
//! _
234
 
template <class BASE>
235
 
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ASN1CryptoMaterial : public ASN1Object, public BASE
 
233
//! key that can be ASN.1 encoded
 
234
/** derived class should override either BERDecodeKey or BERDecodeKey2 */
 
235
class CRYPTOPP_DLL ASN1Key : public ASN1CryptoMaterial
236
236
{
237
237
public:
238
 
        void Save(BufferedTransformation &bt) const
239
 
                {BEREncode(bt);}
240
 
        void Load(BufferedTransformation &bt)
241
 
                {BERDecode(bt);}
 
238
        virtual OID GetAlgorithmID() const =0;
 
239
        virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
 
240
                {BERDecodeNull(bt); return false;}
 
241
        virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
 
242
                {DEREncodeNull(bt); return false;}      // see RFC 2459, section 7.3.1
 
243
        //! decode subjectPublicKey part of subjectPublicKeyInfo, or privateKey part of privateKeyInfo, without the BIT STRING or OCTET STRING header
 
244
        virtual void BERDecodeKey(BufferedTransformation &bt) {assert(false);}
 
245
        virtual void BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, size_t size)
 
246
                {BERDecodeKey(bt);}
 
247
        //! encode subjectPublicKey part of subjectPublicKeyInfo, or privateKey part of privateKeyInfo, without the BIT STRING or OCTET STRING header
 
248
        virtual void DEREncodeKey(BufferedTransformation &bt) const =0;
242
249
};
243
250
 
244
251
//! encodes/decodes subjectPublicKeyInfo
245
 
class CRYPTOPP_DLL X509PublicKey : public ASN1CryptoMaterial<PublicKey>
 
252
class CRYPTOPP_DLL X509PublicKey : virtual public ASN1Key, public PublicKey
246
253
{
247
254
public:
248
255
        void BERDecode(BufferedTransformation &bt);
249
256
        void DEREncode(BufferedTransformation &bt) const;
250
 
 
251
 
        virtual OID GetAlgorithmID() const =0;
252
 
        virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
253
 
                {BERDecodeNull(bt); return false;}
254
 
        virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
255
 
                {DEREncodeNull(bt); return false;}      // see RFC 2459, section 7.3.1
256
 
 
257
 
        //! decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header
258
 
        virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
259
 
        //! encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header
260
 
        virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0;
261
257
};
262
258
 
263
259
//! encodes/decodes privateKeyInfo
264
 
class CRYPTOPP_DLL PKCS8PrivateKey : public ASN1CryptoMaterial<PrivateKey>
 
260
class CRYPTOPP_DLL PKCS8PrivateKey : virtual public ASN1Key, public PrivateKey
265
261
{
266
262
public:
267
263
        void BERDecode(BufferedTransformation &bt);
268
264
        void DEREncode(BufferedTransformation &bt) const;
269
265
 
270
 
        virtual OID GetAlgorithmID() const =0;
271
 
        virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
272
 
                {BERDecodeNull(bt); return false;}
273
 
        virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
274
 
                {DEREncodeNull(bt); return false;}      // see RFC 2459, section 7.3.1
275
 
 
276
 
        //! decode privateKey part of privateKeyInfo, without the OCTET STRING header
277
 
        virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
278
 
        //! encode privateKey part of privateKeyInfo, without the OCTET STRING header
279
 
        virtual void DEREncodePrivateKey(BufferedTransformation &bt) const =0;
280
 
 
281
266
        //! decode optional attributes including context-specific tag
282
267
        /*! /note default implementation stores attributes to be output in DEREncodeOptionalAttributes */
283
268
        virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt);
284
269
        //! encode optional attributes including context-specific tag
285
270
        virtual void DEREncodeOptionalAttributes(BufferedTransformation &bt) const;
286
271
 
287
 
protected:
 
272
private:
288
273
        ByteQueue m_optionalAttributes;
289
274
};
290
275