~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/pk_filts.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************
2
 
* PK Filters Source File                         *
3
 
* (C) 1999-2007 The Botan Project                *
4
 
*************************************************/
5
 
 
6
 
#include <botan/pk_filts.h>
7
 
 
8
 
namespace Botan {
9
 
 
10
 
/*************************************************
11
 
* Append to the buffer                           *
12
 
*************************************************/
13
 
void PK_Encryptor_Filter::write(const byte input[], u32bit length)
14
 
   {
15
 
   buffer.append(input, length);
16
 
   }
17
 
 
18
 
/*************************************************
19
 
* Encrypt the message                            *
20
 
*************************************************/
21
 
void PK_Encryptor_Filter::end_msg()
22
 
   {
23
 
   send(cipher->encrypt(buffer, buffer.size()));
24
 
   buffer.destroy();
25
 
   }
26
 
 
27
 
/*************************************************
28
 
* Append to the buffer                           *
29
 
*************************************************/
30
 
void PK_Decryptor_Filter::write(const byte input[], u32bit length)
31
 
   {
32
 
   buffer.append(input, length);
33
 
   }
34
 
 
35
 
/*************************************************
36
 
* Decrypt the message                            *
37
 
*************************************************/
38
 
void PK_Decryptor_Filter::end_msg()
39
 
   {
40
 
   send(cipher->decrypt(buffer, buffer.size()));
41
 
   buffer.destroy();
42
 
   }
43
 
 
44
 
/*************************************************
45
 
* Add more data                                  *
46
 
*************************************************/
47
 
void PK_Signer_Filter::write(const byte input[], u32bit length)
48
 
   {
49
 
   signer->update(input, length);
50
 
   }
51
 
 
52
 
/*************************************************
53
 
* Sign the message                               *
54
 
*************************************************/
55
 
void PK_Signer_Filter::end_msg()
56
 
   {
57
 
   send(signer->signature());
58
 
   }
59
 
 
60
 
/*************************************************
61
 
* Add more data                                  *
62
 
*************************************************/
63
 
void PK_Verifier_Filter::write(const byte input[], u32bit length)
64
 
   {
65
 
   verifier->update(input, length);
66
 
   }
67
 
 
68
 
/*************************************************
69
 
* Verify the message                             *
70
 
*************************************************/
71
 
void PK_Verifier_Filter::end_msg()
72
 
   {
73
 
   if(signature.is_empty())
74
 
      throw Exception("PK_Verifier_Filter: No signature to check against");
75
 
   bool is_valid = verifier->check_signature(signature, signature.size());
76
 
   send((is_valid ? 1 : 0));
77
 
   }
78
 
 
79
 
/*************************************************
80
 
* Set the signature to check                     *
81
 
*************************************************/
82
 
void PK_Verifier_Filter::set_signature(const byte sig[], u32bit length)
83
 
   {
84
 
   signature.set(sig, length);
85
 
   }
86
 
 
87
 
/*************************************************
88
 
* Set the signature to check                     *
89
 
*************************************************/
90
 
void PK_Verifier_Filter::set_signature(const MemoryRegion<byte>& sig)
91
 
   {
92
 
   signature = sig;
93
 
   }
94
 
 
95
 
/*************************************************
96
 
* PK_Verifier_Filter Constructor                 *
97
 
*************************************************/
98
 
PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v, const byte sig[],
99
 
                                       u32bit length) :
100
 
   verifier(v), signature(sig, length)
101
 
   {
102
 
   }
103
 
 
104
 
/*************************************************
105
 
* PK_Verifier_Filter Constructor                 *
106
 
*************************************************/
107
 
PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v,
108
 
                                       const MemoryRegion<byte>& sig) :
109
 
   verifier(v), signature(sig)
110
 
   {
111
 
   }
112
 
 
113
 
}