monotone

monotone Mtn Source Tree

Root/botan/buf_filt.cpp

1/*************************************************
2* Buffering Filter Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/buf_filt.h>
7
8namespace Botan {
9
10/*************************************************
11* Buffering_Filter Constructor *
12*************************************************/
13Buffering_Filter::Buffering_Filter(u32bit b, u32bit i) : INITIAL_BLOCK_SIZE(i),
14 BLOCK_SIZE(b)
15 {
16 initial_block_pos = block_pos = 0;
17 initial.create(INITIAL_BLOCK_SIZE);
18 block.create(BLOCK_SIZE);
19 }
20
21/*************************************************
22* Reset the Buffering Filter *
23*************************************************/
24void Buffering_Filter::end_msg()
25 {
26 if(initial_block_pos != INITIAL_BLOCK_SIZE)
27 throw Exception("Buffering_Filter: Not enough data for first block");
28 final_block(block, block_pos);
29 initial_block_pos = block_pos = 0;
30 initial.clear();
31 block.clear();
32 }
33
34/*************************************************
35* Buffer input into blocks *
36*************************************************/
37void Buffering_Filter::write(const byte input[], u32bit length)
38 {
39 if(initial_block_pos != INITIAL_BLOCK_SIZE)
40 {
41 u32bit copied = std::min(INITIAL_BLOCK_SIZE - initial_block_pos, length);
42 initial.copy(initial_block_pos, input, copied);
43 input += copied;
44 length -= copied;
45 initial_block_pos += copied;
46 if(initial_block_pos == INITIAL_BLOCK_SIZE)
47 initial_block(initial);
48 }
49 block.copy(block_pos, input, length);
50 if(block_pos + length >= BLOCK_SIZE)
51 {
52 main_block(block);
53 input += (BLOCK_SIZE - block_pos);
54 length -= (BLOCK_SIZE - block_pos);
55 while(length >= BLOCK_SIZE)
56 {
57 main_block(input);
58 input += BLOCK_SIZE;
59 length -= BLOCK_SIZE;
60 }
61 block.copy(input, length);
62 block_pos = 0;
63 }
64 block_pos += length;
65 }
66
67}

Archive Download this file

Branches

Tags

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