monotone

monotone Mtn Source Tree

Root/botan/pk_filts.cpp

1/*************************************************
2* PK Filters Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/pk_filts.h>
7
8namespace Botan {
9
10/*************************************************
11* Append to the buffer *
12*************************************************/
13void PK_Encryptor_Filter::write(const byte input[], u32bit length)
14 {
15 buffer.append(input, length);
16 }
17
18/*************************************************
19* Encrypt the message *
20*************************************************/
21void 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*************************************************/
30void PK_Decryptor_Filter::write(const byte input[], u32bit length)
31 {
32 buffer.append(input, length);
33 }
34
35/*************************************************
36* Decrypt the message *
37*************************************************/
38void PK_Decryptor_Filter::end_msg()
39 {
40 send(cipher->decrypt(buffer, buffer.size()));
41 buffer.destroy();
42 }
43
44/*************************************************
45* Add more data *
46*************************************************/
47void PK_Signer_Filter::write(const byte input[], u32bit length)
48 {
49 signer->update(input, length);
50 }
51
52/*************************************************
53* Sign the message *
54*************************************************/
55void PK_Signer_Filter::end_msg()
56 {
57 send(signer->signature());
58 }
59
60/*************************************************
61* Add more data *
62*************************************************/
63void PK_Verifier_Filter::write(const byte input[], u32bit length)
64 {
65 verifier->update(input, length);
66 }
67
68/*************************************************
69* Verify the message *
70*************************************************/
71void 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*************************************************/
82void 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*************************************************/
90void PK_Verifier_Filter::set_signature(const MemoryRegion<byte>& sig)
91 {
92 signature = sig;
93 }
94
95/*************************************************
96* PK_Verifier_Filter Constructor *
97*************************************************/
98PK_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*************************************************/
107PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v,
108 const MemoryRegion<byte>& sig) :
109 verifier(v), signature(sig)
110 {
111 }
112
113}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status