diff options
author | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
commit | a2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch) | |
tree | ad3d6c4fcc8dd0f403f8105598943616246fe172 /src/pk_filts.cpp |
Initial checkin1.5.6
Diffstat (limited to 'src/pk_filts.cpp')
-rw-r--r-- | src/pk_filts.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/pk_filts.cpp b/src/pk_filts.cpp new file mode 100644 index 000000000..038360e2f --- /dev/null +++ b/src/pk_filts.cpp @@ -0,0 +1,113 @@ +/************************************************* +* PK Filters Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/pk_filts.h> + +namespace Botan { + +/************************************************* +* Append to the buffer * +*************************************************/ +void PK_Encryptor_Filter::write(const byte input[], u32bit length) + { + buffer.append(input, length); + } + +/************************************************* +* Encrypt the message * +*************************************************/ +void PK_Encryptor_Filter::end_msg() + { + send(cipher->encrypt(buffer, buffer.size())); + buffer.destroy(); + } + +/************************************************* +* Append to the buffer * +*************************************************/ +void PK_Decryptor_Filter::write(const byte input[], u32bit length) + { + buffer.append(input, length); + } + +/************************************************* +* Decrypt the message * +*************************************************/ +void PK_Decryptor_Filter::end_msg() + { + send(cipher->decrypt(buffer, buffer.size())); + buffer.destroy(); + } + +/************************************************* +* Add more data * +*************************************************/ +void PK_Signer_Filter::write(const byte input[], u32bit length) + { + signer->update(input, length); + } + +/************************************************* +* Sign the message * +*************************************************/ +void PK_Signer_Filter::end_msg() + { + send(signer->signature()); + } + +/************************************************* +* Add more data * +*************************************************/ +void PK_Verifier_Filter::write(const byte input[], u32bit length) + { + verifier->update(input, length); + } + +/************************************************* +* Verify the message * +*************************************************/ +void PK_Verifier_Filter::end_msg() + { + if(signature.is_empty()) + throw Exception("PK_Verifier_Filter: No signature to check against"); + bool is_valid = verifier->check_signature(signature, signature.size()); + send((is_valid ? 1 : 0)); + } + +/************************************************* +* Set the signature to check * +*************************************************/ +void PK_Verifier_Filter::set_signature(const byte sig[], u32bit length) + { + signature.set(sig, length); + } + +/************************************************* +* Set the signature to check * +*************************************************/ +void PK_Verifier_Filter::set_signature(const MemoryRegion<byte>& sig) + { + signature = sig; + } + +/************************************************* +* PK_Verifier_Filter Constructor * +*************************************************/ +PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v, const byte sig[], + u32bit length) : + verifier(v), signature(sig, length) + { + } + +/************************************************* +* PK_Verifier_Filter Constructor * +*************************************************/ +PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v, + const MemoryRegion<byte>& sig) : + verifier(v), signature(sig) + { + } + +} |