8#include <botan/filters.h>
13#if defined(BOTAN_HAS_STREAM_CIPHER)
15StreamCipher_Filter::StreamCipher_Filter(StreamCipher* cipher) : m_cipher(cipher), m_buffer(m_cipher->buffer_size()) {}
17StreamCipher_Filter::StreamCipher_Filter(StreamCipher* cipher,
const SymmetricKey& key) : StreamCipher_Filter(cipher) {
18 m_cipher->set_key(key);
21StreamCipher_Filter::StreamCipher_Filter(std::string_view sc_name) :
22 m_cipher(StreamCipher::create_or_throw(sc_name)), m_buffer(m_cipher->buffer_size()) {}
24StreamCipher_Filter::StreamCipher_Filter(std::string_view sc_name,
const SymmetricKey& key) :
25 StreamCipher_Filter(sc_name) {
26 m_cipher->set_key(key);
29void StreamCipher_Filter::write(
const uint8_t input[],
size_t length) {
31 size_t copied = std::min<size_t>(length, m_buffer.size());
32 m_cipher->cipher(input, m_buffer.data(), copied);
33 send(m_buffer, copied);
41#if defined(BOTAN_HAS_HASH)
43Hash_Filter::Hash_Filter(std::string_view hash_name,
size_t len) :
44 m_hash(HashFunction::create_or_throw(hash_name)), m_out_len(len) {}
46void Hash_Filter::end_msg() {
47 secure_vector<uint8_t> output = m_hash->final();
49 send(output, std::min<size_t>(m_out_len, output.size()));
56#if defined(BOTAN_HAS_MAC)
58MAC_Filter::MAC_Filter(std::string_view mac_name,
size_t len) :
59 m_mac(MessageAuthenticationCode::create_or_throw(mac_name)), m_out_len(len) {}
61MAC_Filter::MAC_Filter(std::string_view mac_name,
const SymmetricKey& key,
size_t len) : MAC_Filter(mac_name, len) {
65void MAC_Filter::end_msg() {
66 secure_vector<uint8_t> output = m_mac->final();
68 send(output, std::min<size_t>(m_out_len, output.size()));