Botan 1.10.17
pk_filts.cpp
Go to the documentation of this file.
1/*
2* PK Filters
3* (C) 1999-2009 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#include <botan/pk_filts.h>
9
10namespace Botan {
11
12/*
13* Append to the buffer
14*/
15void PK_Encryptor_Filter::write(const byte input[], size_t length)
16 {
17 buffer += std::make_pair(input, length);
18 }
19
20/*
21* Encrypt the message
22*/
24 {
25 send(cipher->encrypt(buffer, rng));
26 buffer.clear();
27 }
28
29/*
30* Append to the buffer
31*/
32void PK_Decryptor_Filter::write(const byte input[], size_t length)
33 {
34 buffer += std::make_pair(input, length);
35 }
36
37/*
38* Decrypt the message
39*/
41 {
42 send(cipher->decrypt(buffer));
43 buffer.clear();
44 }
45
46/*
47* Add more data
48*/
49void PK_Signer_Filter::write(const byte input[], size_t length)
50 {
51 signer->update(input, length);
52 }
53
54/*
55* Sign the message
56*/
58 {
59 send(signer->signature(rng));
60 }
61
62/*
63* Add more data
64*/
65void PK_Verifier_Filter::write(const byte input[], size_t length)
66 {
67 verifier->update(input, length);
68 }
69
70/*
71* Verify the message
72*/
74 {
75 if(signature.empty())
76 throw Invalid_State("PK_Verifier_Filter: No signature to check against");
77 bool is_valid = verifier->check_signature(signature);
78 send((is_valid ? 1 : 0));
79 }
80
81/*
82* Set the signature to check
83*/
84void PK_Verifier_Filter::set_signature(const byte sig[], size_t length)
85 {
86 signature.resize(length);
87 copy_mem(&signature[0], sig, length);
88 }
89
90/*
91* Set the signature to check
92*/
94 {
95 signature = sig;
96 }
97
98/*
99* PK_Verifier_Filter Constructor
100*/
102 size_t length) :
103 verifier(v), signature(sig, length)
104 {
105 }
106
107/*
108* PK_Verifier_Filter Constructor
109*/
111 const MemoryRegion<byte>& sig) :
112 verifier(v), signature(sig)
113 {
114 }
115
116}
void send(const byte in[], size_t length)
Definition filter.cpp:28
void write(const byte[], size_t)
Definition pk_filts.cpp:32
void write(const byte[], size_t)
Definition pk_filts.cpp:15
void write(const byte[], size_t)
Definition pk_filts.cpp:49
void write(const byte[], size_t)
Definition pk_filts.cpp:65
void set_signature(const byte[], size_t)
Definition pk_filts.cpp:84
PK_Verifier_Filter(PK_Verifier *v)
Definition pk_filts.h:88
void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:22
Invalid_State(const std::string &err)
Definition exceptn.h:27