Botan  1.11.15
src/lib/cert/cvc/signed_obj.h
Go to the documentation of this file.
00001 /*
00002 * EAC SIGNED Object
00003 * (C) 2007 FlexSecure GmbH
00004 *     2008 Jack Lloyd
00005 *
00006 * Botan is released under the Simplified BSD License (see license.txt)
00007 */
00008 
00009 #ifndef BOTAN_EAC_SIGNED_OBJECT_H__
00010 #define BOTAN_EAC_SIGNED_OBJECT_H__
00011 
00012 #include <botan/asn1_obj.h>
00013 #include <botan/key_constraint.h>
00014 #include <botan/x509_key.h>
00015 #include <botan/pipe.h>
00016 #include <vector>
00017 
00018 namespace Botan {
00019 
00020 /**
00021 * This class represents abstract signed EAC object
00022 */
00023 class BOTAN_DLL EAC_Signed_Object
00024    {
00025    public:
00026       /**
00027       * Get the TBS (to-be-signed) data in this object.
00028       * @return DER encoded TBS data of this object
00029       */
00030       virtual std::vector<byte> tbs_data() const = 0;
00031 
00032       /**
00033       * Get the signature of this object as a concatenation, i.e. if the
00034       * signature consists of multiple parts (like in the case of ECDSA)
00035       * these will be concatenated.
00036       * @return signature as a concatenation of its parts
00037       */
00038 
00039       /*
00040        NOTE: this is here only because abstract signature objects have
00041        not yet been introduced
00042       */
00043       virtual std::vector<byte> get_concat_sig() const = 0;
00044 
00045       /**
00046       * Get the signature algorithm identifier used to sign this object.
00047       * @result the signature algorithm identifier
00048       */
00049       AlgorithmIdentifier signature_algorithm() const;
00050 
00051       /**
00052       * Check the signature of this object.
00053       * @param key the public key associated with this signed object
00054       * @param sig the signature we are checking
00055       * @return true if the signature was created by the private key
00056       * associated with this public key
00057       */
00058       bool check_signature(class Public_Key& key,
00059                            const std::vector<byte>& sig) const;
00060 
00061       /**
00062       * Write this object DER encoded into a specified pipe.
00063       * @param pipe the pipe to write the encoded object to
00064       * @param encoding the encoding type to use
00065       */
00066       virtual void encode(Pipe& pipe,
00067                           X509_Encoding encoding = PEM) const = 0;
00068 
00069       /**
00070       * BER encode this object.
00071       * @return result containing the BER representation of this object.
00072       */
00073       std::vector<byte> BER_encode() const;
00074 
00075       /**
00076       * PEM encode this object.
00077       * @return result containing the PEM representation of this object.
00078       */
00079       std::string PEM_encode() const;
00080 
00081       virtual ~EAC_Signed_Object() {}
00082    protected:
00083       void do_decode();
00084       EAC_Signed_Object() {}
00085 
00086       AlgorithmIdentifier sig_algo;
00087       std::vector<byte> tbs_bits;
00088       std::string PEM_label_pref;
00089       std::vector<std::string> PEM_labels_allowed;
00090    private:
00091       virtual void force_decode() = 0;
00092    };
00093 
00094 }
00095 
00096 #endif