aboutsummaryrefslogtreecommitdiffstats
path: root/src/cert/cvc/signed_obj.cpp
blob: 4a08ed0ac15da71329311956e1e1bd259ff62158 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* X.509 SIGNED Object
* (C) 1999-2007 Jack Lloyd
*     2007 FlexSecure GmbH
*
* Distributed under the terms of the Botan license
*/

#include <botan/signed_obj.h>

namespace Botan {

/*
* Return a BER encoded X.509 object
*/
SecureVector<byte> EAC_Signed_Object::BER_encode() const
   {
   Pipe ber;
   ber.start_msg();
   encode(ber, RAW_BER);
   ber.end_msg();
   return ber.read_all();
   }

/*
* Return a PEM encoded X.509 object
*/
std::string EAC_Signed_Object::PEM_encode() const
   {
   Pipe pem;
   pem.start_msg();
   encode(pem, PEM);
   pem.end_msg();
   return pem.read_all_as_string();
   }

/*
* Return the algorithm used to sign this object
*/
AlgorithmIdentifier EAC_Signed_Object::signature_algorithm() const
   {
   return sig_algo;
   }

/*
* Try to decode the actual information
*/
void EAC_Signed_Object::do_decode()
   {
   try {
      force_decode();
   }
   catch(Decoding_Error& e)
      {
      const std::string what = e.what();
      throw Decoding_Error(PEM_label_pref + " decoding failed (" +
                           what.substr(23, std::string::npos) + ")");
      }
   catch(Invalid_Argument& e)
      {
      const std::string what = e.what();
      throw Decoding_Error(PEM_label_pref + " decoding failed (" +
                           what.substr(7, std::string::npos) + ")");
      }
   }

}